I am trying to control a servo directly from a serial connection this is my code right now.
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
Serial.begin(9600);
myservo.attach(9);
}
void loop()
{
if ( Serial.available()) {
pos = Serial.read();
myservo.write(pos);
}
}
The values of pos range from 0 to 255 but it only works the first time you send a value then it won’t work anymore. Could you guys revise my code to make it better? I am revlatively new to arduino so any help would be greatly appreciated! I have gotten the sweep code to work so its not the arduino its the code errrr…