int red=28; int green=27; int blue=26; bool lastButtonState = 1; int currentMode=0; void setup(){ Serial.begin(115200); pinMode(3, INPUT_PULLUP); pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); turnOffAllLEDs(); } void loop(){ int buttonState = digitalRead(3); if (buttonState == 0 && lastButtonState == 1) { // Button was pressed, change mode currentMode++; if (currentMode>3){ currentMode=0; } updateLEDs(currentMode); } lastButtonState = buttonState; delay(20); } void updateLEDs(int mode) { switch (mode) { case 0: turnOffAllLEDs(); break; // All LEDs off case 1: turnOnBlue(); break; // Blue on case 2: turnOnRed(); break; // Red on case 3: turnOnGreen(); break; // Green on } } void turnOffAllLEDs() { digitalWrite(red, HIGH); digitalWrite(green, HIGH); digitalWrite(blue, HIGH); } void turnOnBlue() { turnOffAllLEDs(); digitalWrite(blue, LOW); } void turnOnRed() { turnOffAllLEDs(); digitalWrite(red, LOW); } void turnOnGreen() { turnOffAllLEDs(); digitalWrite(green, LOW); }