#define BUTTON_PIN 27 #define LED_1 0 #define LED_2 1 #define LED_3 26 int buttonPressCount = 0; // Global variable to keep track of the number of button presses void setup() { pinMode(LED_1, OUTPUT); pinMode(LED_2, OUTPUT); pinMode(LED_3, OUTPUT); pinMode(BUTTON_PIN, INPUT_PULLUP); Serial.begin(9600); delay(2000); Serial.println("This is LED button example for FAB ACADEMY 2024"); } void loop() { int buttonState = digitalRead(BUTTON_PIN); if (buttonState == HIGH) { buttonPressCount++; // Increment the button press count toggleLED(); // Call the function to toggle the LEDs // Wait for the button to be released while(digitalRead(BUTTON_PIN) == HIGH); delay(50); } } void toggleLED() { if (buttonPressCount == 1) { digitalWrite(LED_1, HIGH); digitalWrite(LED_2, LOW); digitalWrite(LED_3, LOW); Serial.println("LED 1 ON"); } else if (buttonPressCount == 2) { digitalWrite(LED_1, LOW); digitalWrite(LED_2, HIGH); digitalWrite(LED_3, LOW); Serial.println("LED 2 ON"); } else if (buttonPressCount == 3) { digitalWrite(LED_1, LOW); digitalWrite(LED_2, LOW); digitalWrite(LED_3, HIGH); Serial.println("LED 3 ON"); } if (buttonPressCount >= 3) { // Reset to 1 to start from the first LED again after the third press buttonPressCount = 0; } }