int button = 2; int buttonVal1; int buttonVal2; int buttonState; int i = 0; // button variables // set the number of states int numStates = 4; // variable that holds the current state int currentState = 0; void setup() { pinMode(button, INPUT); buttonState = digitalRead(button); Serial.begin(9600); } void checkButton() { buttonVal1 = digitalRead(button); delay(10); buttonVal2 = digitalRead(button); if (buttonVal1 == buttonVal2) { if (buttonVal1 != buttonState) { if (buttonVal1 == LOW) { // do stuff currentState = (currentState + 1) % numStates; //Serial.println(currentState); } buttonState = buttonVal1; } } } void loop() { int previousButtonState = currentState; // read button checkButton(); //Serial.println(currentState); if (currentState == 1) { Serial.println("Please don't press the button"); } else if (currentState == 2) { Serial.println("I said stop pressing the button"); } else if (currentState == 3) { Serial.println("YOU MUST NOT PRESS THE BUTTON"); } else { Serial.println(""); } }