Hey Forum, i am working on a project where i require multiple servos to move at different paces but also to move at different times. I am able to have all the servos move simultaneously but not one after the other.
here is my code so far:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservoa;
Servo myservob;// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(8);
myservoa.attach(9);
myservob.attach(10); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos <= 15; pos += 15) // goes from 0 degrees to 15 degrees
{ // in steps of 15 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50);
myservoa.write(pos);
myservob.write(pos);
delay(50); // waits 15ms for the servo to reach the position
}
for(pos = 15; pos>=0; pos-=15) // goes from 15 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50);
myservoa.write(pos);
myservob.write(pos);
delay(50); // waits 50ms for the servo to reach the position
}
}