I’m trying to rotate a hobbico cs-60 servo from 0 to 90 degrees only once and I was wondering if there was any way to stop my code from looping. I’ve tried removing void loop but that didn’t work. I’ve checked the wiring and it’s all been put in correctly, so I’m guessing it’s a problem with the code. But I’m not getting any error messages.
Here’s my code:
void setup()
{
myservo.attach(9); //attaches servo on pin 9 to servo object
}
void loop()
{
delay(30);
{
}
for(angle = 90; angle < 180; angle += 1)
{
myservo.write(angle);
myservo.write (180-angle);
delay(50);
}
for(angle = 180; angle >=90; angle -= 1) // goes from 180 to 90 degrees
{
myservo.write(angle);
myservo.write(180-angle);
while(1) {}
}
}
The first time I run it it works fine, but it keeps jerking back when I run the code again. Is it supposed to do that? And is there any way to stop that from happening?
Any help is appreciated!