#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
int writeValues[5] = {1000, 1250,1500,1750,2000};
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0;
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT_PULLUP);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == LOW) {
// if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
Serial.println(buttonPushCounter);
Serial.print("buttonPushCounter % 5 = ");
Serial.println(buttonPushCounter % 5);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
lastButtonState = buttonState;
{
m1.writeMicroseconds(writeValues[buttonPushCounter % 5]);
}
}