#define BUTTON_PIN 7
#define LED_GREEN 13
#define LED_BLUE 12
#define LED_RED 11
int buttonState = LOW;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
int ledState = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
pinMode(LED_RED, OUTPUT);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, LOW);
digitalWrite(LED_RED, LOW);
}
void loop() {
int reading = digitalRead(BUTTON_PIN);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
ledState++;
if (ledState > 3) {
ledState = 0;
}
}
}
}
lastButtonState = reading;
if (ledState == 1) {
digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, LOW);
digitalWrite(LED_RED, LOW);
} else if (ledState == 2) {
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, HIGH);
digitalWrite(LED_RED, LOW);
} else if (ledState == 3) {
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, LOW);
digitalWrite(LED_RED, HIGH);
} else {
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, LOW);
digitalWrite(LED_RED, LOW);
}
}