Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino 退出状态1应为“if”之前的主表达式_Arduino - Fatal编程技术网

Arduino 退出状态1应为“if”之前的主表达式

Arduino 退出状态1应为“if”之前的主表达式,arduino,Arduino,我一直在做一个Arduino项目,在验证中遇到了这个问题:退出状态1 “if”之前应为主表达式 我已经在网络上搜索了解决方案,但唯一的解决方案是确保正确定义事物,但据我所知,它们很好 我的代码是: //Code for Machine int sensorPin1 = A0; //select pin input for LDR1// int sensorValue1 = 0; //variable to store value from LDR1// int sensorPin2 = A1;

我一直在做一个Arduino项目,在验证中遇到了这个问题:退出状态1 “if”之前应为主表达式

我已经在网络上搜索了解决方案,但唯一的解决方案是确保正确定义事物,但据我所知,它们很好

我的代码是:

//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);
}

帮助?

您的if语句编写不正确:您应该使用if sensorValue1<820&&sensorValue2>820{…}。我删除了你的第二个“如果”和“否”;在牙套之前。非常感谢您的回复,我刚刚解决了这个问题,但非常感谢!很抱歉,我什么都没说——老实说,我已经忘记了:/if语句写得不正确:应该使用if-sensorValue1<820&&sensorValue2>820{…}。我删除了你的第二个“如果”和“否”;在牙套之前。非常感谢您的回复,我刚刚解决了这个问题,但非常感谢!很抱歉,我什么也没说——老实说,我忘了:/