const int buttonPin = 27; // Button pin const int ledPins[] = {26, 0, 1}; // LED pins const int numLeds = 3; // Number of LEDs int ledIndex = 0; // Current LED index bool previousButtonState = HIGH; // Previous button state, assuming pull-up void setup() { for (int i = 0; i < numLeds; i++) { pinMode(ledPins[i], OUTPUT); // Initialize LED pins as output } pinMode(buttonPin, INPUT_PULLUP); // Initialize button pin as input with pull-up resistor } void loop() { bool currentButtonState = digitalRead(buttonPin); if (currentButtonState == LOW && previousButtonState == HIGH) { // Button was pressed blinkLedsRecursively(0); // Start blinking sequence } previousButtonState = currentButtonState; // Update the previous button state } void blinkLedsRecursively(int index) //recursive function { if (index >= numLeds) return; // Base case: stop if past the last LED digitalWrite(ledPins[index], HIGH); // Turn on current LED delay(500); // Wait for half a second digitalWrite(ledPins[index], LOW); // Turn off current LED blinkLedsRecursively(index + 1); // Recursively call for the next LED }