So I have a problem. I need to write a program to control the continuous rotation servo from serial input. I need to use the Servo library to control the servo. I ran into a problem, that first of all, my if statements don´t work, so like if the first if statement is true, it just doesn't read the second if statement, but I need to have them because I don't want the user input to be more than 1700 and less than 1300. Another problem is, that If I input 1700 as my input, then it rotates for a second in another direction and then stops, I need it to rotate in the direction constantly and change it when I type 1300.
Here´s my code:
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(9);
Serial.begin(9600);
Serial.println("Please enter a number and press ENTER.");
}
int x;
void loop() {
x=Serial.parseInt();
if(x>1700){
Serial.println("Too high of a number");
}
else{
myservo.writeMicroseconds(x);
}
if(x<1300){
Serial.println("Too low of a number");
}
else{
myservo.writeMicroseconds(x);
}
}