Autor: Rafael CD | Publicado: 2012-04-13T18:30:00-07:00

#include &lt;Servo.h&gt;

Servo myservo; &nbsp;// 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; &nbsp; &nbsp;// variable to store the servo position

void setup()
{
&nbsp; myservo.attach(9); &nbsp; &nbsp;// attaches the servo on pin 9 to the servo object
&nbsp; myservo2.attach(6); &nbsp; // pin 6
&nbsp; myservo3.attach(5); &nbsp;// pin 5
&nbsp; myservo4.attach(3); &nbsp;// pin 3
}


void loop()
{
&nbsp; for(pos = 0; pos &lt; 180; pos += 1) &nbsp;// goes from 0 degrees to 180 degrees &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // servo 1
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// in steps of 1 degree
&nbsp; &nbsp; myservo.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // waits 15ms for the servo to reach the position
&nbsp; }
&nbsp; for(pos = 180; pos&gt;=1; pos-=1) &nbsp; &nbsp; // goes from 180 degrees to 0 degrees
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; myservo.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // waits 15ms for the servo to reach the position
&nbsp; 
&nbsp; 


&nbsp; for(pos = 0; pos &lt; 180; pos += 1) &nbsp;// goes from 0 degrees to 180 degrees &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // servo 2
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// in steps of 1 degree
&nbsp; &nbsp; myservo2.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // waits 15ms for the servo to reach the position
&nbsp; }
&nbsp; for(pos = 180; pos&gt;=1; pos-=1) &nbsp; &nbsp; // goes from 180 degrees to 0 degrees
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; myservo2.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // waits 15ms for the servo to reach the position
&nbsp; 



&nbsp; &nbsp; &nbsp; for(pos = 0; pos &lt; 180; pos += 1) &nbsp;// goes from 0 degrees to 180 degrees &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // servo 3
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// in steps of 1 degree
&nbsp; &nbsp; myservo3.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // waits 15ms for the servo to reach the position
&nbsp; }
&nbsp; for(pos = 180; pos&gt;=1; pos-=1) &nbsp; &nbsp; // goes from 180 degrees to 0 degrees
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; myservo3.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp;} &nbsp; &nbsp;// waits 15ms for the servo to reach the position
&nbsp; 
&nbsp; 
&nbsp; 
&nbsp; &nbsp; &nbsp; for(pos = 0; pos &lt; 180; pos += 1) &nbsp;// goes from 0 degrees to 180 degrees &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // servo 4
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// in steps of 1 degree
&nbsp; &nbsp; myservo4.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // waits 15ms for the servo to reach the position
&nbsp; }
&nbsp; for(pos = 180; pos&gt;=1; pos-=1) &nbsp; &nbsp; // goes from 180 degrees to 0 degrees
&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; myservo4.write(pos); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// tell servo to go to position in variable 'pos'
&nbsp; &nbsp; delay(15); &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // waits 15ms for the servo to reach the position
}