Arduino代码:“ + =”令牌之前的预期主表达式

时间:2019-02-24 05:50:07

标签: c++ arduino

我正在编写代码,代码的最后一部分是唯一看起来有麻烦的部分。该错误表明必须有一个

  

“ + =”令牌之前的预期主要表达式

但是我不确定如何解决此问题。这是代码,问题出在代码底部。

void loop(){

 if(digitalRead(pirPin) == HIGH){
   digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
   if(lockLow){  
     //makes sure we wait for a transition to LOW before any further output is made:
     lockLow = false;            
     Serial.println("---");
     Serial.print("motion detected at ");
     Serial.print(millis()/1000);
     Serial.println(" sec"); 
     delay(50);
     }         
     takeLowTime = true;
   }

 if(digitalRead(pirPin) == LOW){       
   digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

   if(takeLowTime){
    lowIn = millis();          //save the time of the transition from high to LOW
    takeLowTime = false;       //make sure this is only done at the start of a LOW phase
    }
   //if the sensor is low for more than the given pause, 
   //we assume that no more motion is going to happen
   if(!lockLow && millis() - lowIn > pause){  
       //makes sure this block of code is only executed again after 
       //a new motion sequence has been detected
       lockLow = true;   

       for (int pos = 0; pos <= 180; +=1) //**Here is the issue**
          myservo.write(pos);
          delay(15);
      }
       for (int pos = 180; pos >= 0; -= 1) //**Here is the issue**
          myservo.write(pos);
          delay(15);
      }                     
       Serial.print("motion ended at ");      //output
       Serial.print((millis() - pause)/1000);
       Serial.println(" sec");
       delay(50);
       }
   }
}

1 个答案:

答案 0 :(得分:0)

replace +=1 ===> pos +=1
 AND
replace -=1 ======> pos-=1