退出状态1预期的主要表达式之前'如果'

时间:2016-10-31 20:11:46

标签: arduino

我一直在研究Arduino项目,并且在验证中遇到了这个问题:退出状态1 在'

之前预期的初级表达

我在网上搜索过解决方案,但唯一的解决方案是确保正确定义,但据我所知,它们很好......

我的代码是:

//Code for Machine

int sensorPin1 = A0; //select pin input for LDR1//
int sensorValue1 = 0; //variable to store value from LDR1//
int sensorPin2 = A1; //pin for LDR2//
int sensorValue2 = 0; //variable to store value from LDR2//
int pistonNum = 0; //variable to determin which piston to activate//

#define piston1Out 1 // is defined as pin #1//
#define piston1In 2 // is defined as pin #2//
#define piston2Out 3 // is defined as pin #3//
#define piston2In 4 // is defined as pin #4//
#define relay1 5 //is defined as pin #5//
#define relay2 6 //is defined as pin #6//

void setup() { //Setup runs once//

pinMode(piston1Out, OUTPUT); //Set  as an output//
pinMode(piston1In, OUTPUT); //Set  as an output//
pinMode(piston2Out, OUTPUT); //Set  as an output//
pinMode(piston2In, OUTPUT); //Set  as an output//
pinMode(relay1, OUTPUT); //set as an output//
pinMode(relay2, OUTPUT); //set as an output//
}

void loop() {

  //read value from sensor:
  sensorValue1 = analogRead(sensorPin1);  
  sensorValue2 = analogRead(sensorPin2); 

if((sensorValue1 < 820) && if(sensorValue2 > 820)); { //If first sensor is below threshold and second is above then activate first piston//
    digitalWrite(piston1In,HIGH);
digitalWrite(piston1Out,LOW); //Pistons Out
digitalWrite(relay1,HIGH); //turns the relay for the first piston on//

delay(100);

digitalWrite(relay1,LOW); //turns the relay for the first piston off//
digitalWrite(piston1Out,HIGH);
digitalWrite(piston1In,LOW); //piston IN//
digitalWrite(relay1,HIGH); //relay on - activate piston//

delay(100);

digitalWrite(relay1, LOW); //piston off//
   }
  else if((sensorValue1 < 820) && if(sensorValue2 < 820)) { //If both sensors are below threshold then activate the second piston//
   digitalWrite(piston1In,HIGH);
digitalWrite(piston1Out,LOW); //Pistons Out
digitalWrite(relay1,HIGH); //turns the relay for the first piston on//

delay(100);

digitalWrite(relay1,LOW); //turns the relay for the first piston off//
digitalWrite(piston1Out,HIGH);
digitalWrite(piston1In,LOW); //piston IN//
digitalWrite(relay1,HIGH); //relay on - activate piston//

delay(100);

digitalWrite(relay1On, LOW); //piston off//
  }  
  else if((sensorValue1 > 820) && if(sensorValue2 > 820)) { //If both are above threshold then activate no pistons//
    pistonNum = 1
   }
else {
  pistonNum = 0
}


delay(50);
}

帮助?

0 个答案:

没有答案