Hey, I want to operate two servos facing each other and their directions are opposite as both goes 0 to 180 degrees. I want to synchronize both like when one goes 0 to 180 degree while the other goes 180 to 0 degree.
here is my code, but It didnt work. could you please help me.
#include <Servo.h>
Servo servo9;
Servo servo10;
int pos9 = 0; // variable to store the servo position
int pos10 = 180;
void setup()
{
servo9.attach(9); // attaches the servo on pin 9 to the servo object
servo10.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop()
{
for(pos9 = 0; pos9 < 180; pos9 += 1) //servo 9 goes from 0 degrees to 180 degrees
for(pos10 = 180; pos10 < 0; pos10 += 1) //servo 10 goes from 180 degrees to 0 degrees
{ // in steps of 1 degree
servo9.write(pos9); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
servo10.write(pos10);
delay(15);
}
for(pos9 = 180; pos9>=1; pos9-=1) // goes from 180 degrees to 0 degrees
for(pos10 = 0; pos10>=1; pos10-=1) // goes from 0 degrees to 180 degrees
{
servo9.write(pos9); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
servo10.write(pos10);
delay(15);
}
}
thanks