SINGLE PUSH BUTTON

single push button

const int buttonPin = 2;
const int ledPin1 = 6;
const int ledPin2 = 7;
const int ledPin3 = 8;

int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
Serial.begin(9600);
}
unsigned long last = millis();

void loop() {{
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
if (millis() – last > 150) {
buttonPushCounter++;
Serial.println(“on”);
Serial.print(“number of button pushes: “);
Serial.println(buttonPushCounter);
}
last = millis();
}
}
else {

}
}

lastButtonState = buttonState;

if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);

}
if (buttonPushCounter % 4 == 1) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
}
if (buttonPushCounter % 4 == 2) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
}
if (buttonPushCounter % 4 == 3) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
}

}

/*

for similar project with use IR remote as button, see on https://arduinoproyek.wordpress.com/single-button-ir-remote/

*/