Been messing around with servos. I needed to make two of them turn in opposite directions at the same time.
I got it to work with the following code (see below), I don't understand how my "for" structure is influencing the rotation and is there a better way to code this??
//Two servos moving opposite direction at the same time.
#include <Servo.h>
Servo servo01;
Servo servo02;
int angle01 = 0;
int angle02 = 180;
void setup()
{
servo01.attach(5);
servo02.attach(6);
}
void loop()
{
for(int c = 0; c < 180; c +=1)
// c is for clockwise
{
servo01.write(angle01);
servo02.write(angle02);
delay(5);
}
for(int cc = 180; cc > 0; cc -=1)
//cc is for counter-clockwise
{
servo01.write(angle02);
servo02.write(angle01);
delay(5);
}
}