Skip to content

Instantly share code, notes, and snippets.

@teos0009
Created April 22, 2016 14:07
Show Gist options
  • Save teos0009/ef37b0bdf278d51376578d15c2d7d586 to your computer and use it in GitHub Desktop.
Save teos0009/ef37b0bdf278d51376578d15c2d7d586 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2; // twelve servo objects can be created on most boards
Servo myservo3;
int pos = 0; // variable to store the servo position
void setup()
{
myservo1.attach(10); // attaches the servo on pin 9 to the servo object
myservo2.attach(9);
myservo3.attach(8);
}
void loop()
{
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo1.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>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo1.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
{ // 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>=0; 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
{ // 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>=0; 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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment