#include <ezButton.h>
const byte btn1Pin = 2;
const byte redPin = 13;
const byte greenPin = 12;
const byte bluePin = 14;
const byte yellowPin = 27;
ezButton button(btn1Pin);
unsigned long btnCount = 0;
byte redState = LOW;
byte greenState = LOW;
byte blueState = LOW;
byte yellowState = LOW;
void ledStates();
void display();
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(yellowPin, OUTPUT);
button.setDebounceTime(50);
Serial.begin(115200);
}
void loop() {
delay(10); // this speeds up the simulation
button.loop();
if (button.isPressed()) {
btnCount++;
if (btnCount > 4) {
btnCount = 0;
}
ledStates();
Serial.print("Count = ");
Serial.println(btnCount);
}
}
void ledStates() {
switch (btnCount) {
case 1:
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
digitalWrite(yellowPin, LOW);
break;
case 2:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
digitalWrite(yellowPin, LOW);
break;
case 3:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
digitalWrite(yellowPin, LOW);
break;
case 4:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
digitalWrite(yellowPin, HIGH);
break;
default:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
digitalWrite(yellowPin, LOW);
break;
}
}