#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 10; // variable to store the servo position
int pushButton = 2;
int ledPin = 13;
int clicks = 0;
void setup()
{
Serial.begin(9600);
myservo.attach(10); // attaches the servo on pin 9 to the servo object
pinMode(pushButton, INPUT_PULLUP);
digitalWrite(ledPin, LOW);
}
void loop() {
int buttonState = digitalRead(pushButton);
if (buttonState == 0 && pos <= 180) {
clicks = clicks + 1;
Serial.print("Clicks: ");
Serial.println(clicks);
pos = map(clicks, 0, 11, 0, 180);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(100);
}
else if (buttonState == 0) {
digitalWrite(ledPin, HIGH); // LED goes on when the button has been pressed too many times
}
}