#include <Servo.h>
Servo mysevo; // 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() {
mysevo.attach(9); //attaches the servo on pin 9 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
mysevo.write(pos);
delay(15);
}
for (pos=180;pos >= 0;pos -= 1){//goes from 180 degrees to 0 degrees
mysevo.write(pos);
delay(15);
}
}