const int topLEDs[] = {18, 05, 32, 33, 25};   // Top LEDs
const int bottomLEDs[] = {15, 13, 12, 14, 27}; // Bottom LEDs (reverse order)
const int alwaysOnLED = 26; // This one stays ON
const int buttonPin = 16;

unsigned long lastUpdateTime = 0;
int step = 0;
int running = 0;

const unsigned long stepDelay = 6000; // 12 seconds / 5 steps = 2400ms per step

void setup() {
  for (int i = 0; i < 5; i++) {
    pinMode(topLEDs[i], OUTPUT);
    pinMode(bottomLEDs[i], OUTPUT);
    digitalWrite(topLEDs[i], HIGH);    // Turn ON top LEDs initially
    digitalWrite(bottomLEDs[i], LOW);  // Turn OFF bottom LEDs initially
  }
  pinMode(alwaysOnLED, OUTPUT);
  digitalWrite(alwaysOnLED, HIGH);  // Always ON LED
  pinMode(buttonPin, INPUT_PULLUP); // Button with internal pull-up
}

void loop() {
  // Check for button press (active LOW)
  if (digitalRead(buttonPin) == LOW) {
    delay(50); // Debounce
    if (digitalRead(buttonPin) == LOW) {
      resetTimer();
      while (digitalRead(buttonPin) == LOW); // Wait until released
    }
  }

  if ( millis()-lastUpdateTime >= stepDelay ){
    if (step < 5) {
      digitalWrite(topLEDs[step], LOW);           // Turn OFF next top LED
      digitalWrite(bottomLEDs[step], HIGH);       // Turn ON corresponding bottom LED
      step++;
      lastUpdateTime = millis();
    } else {
      running= millis(); // Timer completed
    }
  }
}

void resetTimer() {
  // Reset LEDs
  for (int i = 0; i < 5; i++) {
    digitalWrite(topLEDs[i], HIGH);
    digitalWrite(bottomLEDs[i], LOW);
  }
  step = 0;
  lastUpdateTime = millis();
  running = 0;
}


// const int topLEDs[] = {18, 05, 32, 33, 25};   // Top LEDs
// const int bottomLEDs[] = {15, 13, 12, 14, 27}; // Bottom LEDs (reverse order)
// const int alwaysOnLED = 26; // This one stays ON
// const int buttonPin = 16;
// const unsigned long stepDelay = 12000; // 12 seconds / 5 steps = 2400ms per step

// void setup() {
//   for (int i = 0; i < 5; i++) {
//     pinMode(topLEDs[i], OUTPUT);
//     pinMode(bottomLEDs[i], OUTPUT);
//     digitalWrite(topLEDs[i], HIGH);    // Turn ON top LEDs initially
//     digitalWrite(bottomLEDs[i], LOW);  // Turn OFF bottom LEDs initially
//   }
//   pinMode(alwaysOnLED, OUTPUT);
//   digitalWrite(alwaysOnLED, HIGH);  // Always ON LED
//   pinMode(buttonPin, INPUT_PULLUP); // Button with internal pull-up
// }