#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int buttonPin = 12; // declare button pin
int servoPin = 13; // declare the servo pin
int ledPin = 11; // declare led pin
void setup() {
myservo.attach(13); // attaches the servo on pin 13 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // servo from 0 degrees to 180 degrees 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
digitalWrite(ledPin, HIGH); // turn LED ON
}
delay(5000); // pause for some time at 180 degrees
for (pos = 180; pos >= 0; pos -= 1) { // returns 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
digitalWrite(ledPin, LOW); // turn LED OFF
}
}