const int buttonPin = 27; // the number of the pushbutton pin const int ledPins[] = {26, 0, 1}; // Pins for LEDs int buttonState = 0; // variable for reading the pushbutton status bool pressed; void setup() { Serial.begin(9600); // Initialize LEDs as outputs for (int i = 0; i < sizeof(ledPins) / sizeof(ledPins[0]); i++) { pinMode(ledPins[i], OUTPUT); } pinMode(buttonPin, INPUT); Serial.println("This is an LED example Board for FAB24"); } // Function to turn on LEDs one by one void lightUp(int index) { if (index < sizeof(ledPins) / sizeof(ledPins[0])) { digitalWrite(ledPins[index], HIGH); delay(500); // Adjust delay as needed lightUp(index + 1); } } // Function to turn off LEDs in reverse order void turnOff(int index) { if (index >= 0) { digitalWrite(ledPins[index], LOW); delay(500); // Adjust delay as needed turnOff(index - 1); } } void regressiveLED() { lightUp(0); // Turn on LEDs one by one turnOff(sizeof(ledPins) / sizeof(ledPins[0]) - 1); // Turn off LEDs in reverse order } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { if (pressed == false) { Serial.println("Button is pressed"); pressed = true; // Toggle the state of LED 1 if (digitalRead(ledPins[0]) == LOW) { Serial.println("LED is ON"); digitalWrite(ledPins[0], HIGH); regressiveLED(); // Call the function to control LEDs } else { Serial.println("LED is OFF"); digitalWrite(ledPins[0], LOW); // No need to call regressiveLED() when turning off the LED } } } else { pressed = false; delay(50); } }