I am trying to control a servo using keyboard.
void loop() {
if (Serial.available() > 0) {
x = Serial.parseInt();
while(pos < 180){
pos = x + pos;
Serial.println(pos);
myservo.write(pos);
delay(100);
}
}
else if(Serial.available() > 0){
if(pos>=180){
pos = 0;
delay(500);
myservo.write(0);
}
}
}
Right now the servo takes the input correctly. The only thing is that it wont change positions immediately. It will wait until it hits 180 resets to 0 and then use the input I put in. This isnt the behaviour I want. I want it to change immediately. How Do I set this up?