#include<Servo.h>
Servo myServo;
int pos;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myServo.attach(9);
myServo.write(0);
}
void loop() {
Serial.println("enter position: ");
while (Serial.available()==0){}
pos = Serial.parseInt();
if(pos>=0&&pos<=180){
myServo.write(pos);
Serial.print("Turned to ");
Serial.println(pos);
Serial.flush();
}
else Serial.println("invalid position");
}