Hi, I just got an Arduino card, and I have got a servo too.
I'm trying to do a little sketch to control the position of the servo, through the library, just by sending a % into the Serial port, and the servo mooves consequently.
Here is my sketch : What do you think about it ?
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
}
void loop()
{
byte pos;
if(Serial.available())
{
pos = Serial.read();
pos = pos/179*100;
Serial.println(pos, DEC);
myservo.write(pos);
delay(15);
}
}
With this one, when I send for the first time a value through Serial, the servo goes to the opposite side, and stay there (if i enter a 2 or a 98, it's the same !). Then, when I shut the Serial window, the servo goes to the previous value he was at start, and thats's all
I can't fix that problem. What can I do ? :
Thanks, and I hope you will be able to fix my beginner problem...
PS : Sorry for my bad english, it's hard to read me