#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2;// a maximum of eight servo objects can be created
Servo myservo3;
Servo myservo4;
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(6); // pin 6
myservo3.attach(5); // pin 5
myservo4.attach(3); // pin 3
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees // servo 1
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); } // waits 15ms for the servo to reach the position
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees // servo 2
{ // in steps of 1 degree
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); } // waits 15ms for the servo to reach the position
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees // servo 3
{ // in steps of 1 degree
myservo3.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo3.write(pos); // tell servo to go to position in variable 'pos'
delay(15); } // waits 15ms for the servo to reach the position
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees // servo 4
{ // in steps of 1 degree
myservo4.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo4.write(pos); // tell servo to go to position in variable 'pos'
delay(15); } // waits 15ms for the servo to reach the position
}