Try:
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo2; // create servo object to control servo 2
Servo myservo3; // create servo object to control servo 3
Servo myservo4; // create servo object to control servo 4
Servo myservo5; // create servo object to control servo 5
int pos = 0; // variable to store the servo position
void setup()
{
myservo2.attach(2); // attaches the servo on pin 2 to the servo object
myservo3.attach(3); // attaches the servo on pin 3 to the servo object
myservo4.attach(4); // attaches the servo on pin 4 to the servo object
myservo5.attach(5); // attaches the servo on pin 5 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo(2).write(pos); // tell servo to go to position in variable 'pos'
myservo(3).write(pos);
myservo(4).write(pos);
myservo(5).write(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(2).write(pos); // tell servo to go to position in variable 'pos'
myservo(3).write(pos);
myservo(4).write(pos);
myservo(5).write(pos);
delay(15); // waits 15ms for the servo to reach the position
}
}