#include <Servo.h>
Servo Left; // create servo object to control a servo
Servo Right; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
Right.attach(9); // attaches the servo on pin 9 to the servo object
Left.attach(11); // attaches the servo on pin 9 to the servo object
}
void Forward(){
Left.write(-180); // tell servo to go to position in variable 'pos'
Right.write(180); // tell servo to go to position in variable 'pos'
}
void Backwards(){
Left.write(0); // tell servo to go to position in variable 'pos'
Right.write(0); // tell servo to go to position in variable 'pos'
}
void LeftTurn(){
Left.write(0); // tell servo to go to position in variable 'pos'
Right.write(-180); // tell servo to go to position in variable 'pos'
delay(1000); // waits 15ms for the servo to reach the position
}
void RightTurn(){
Left.write(180); // tell servo to go to position in variable 'pos'
Right.write(0); // tell servo to go to position in variable 'pos'
delay(1000); // waits 15ms for the servo to reach the position
}
void Stop(){
Left.write(90); // tell servo to go to position in variable 'pos'
Right.write(90); // tell servo to go to position in variable 'pos'
}
void loop() {
Forward();
delay(2000);
LeftTurn();
delay(800);
Forward();
delay(3000);
RightTurn();
delay(800);
}