having trouble with the loop (Digital Hour Glass project)

const int switchPin = 8;
unsigned long previousTime=0;

int SwitchState=0;
int prevSwitchState=0;
int led=2;

long interval=1000;
int timei;
void setup() {
  // put your setup code here, to run once:
  for (int x=2;x<8;x++)
  {
    pinMode(x,OUTPUT);
  }
  pinMode(switchPin,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentTime = millis();
  if (currentTime - previousTime>interval)
  {
    previousTime=currentTime;
    digitalWrite(led,HIGH);
    if(led>=3);
    {
      digitalWrite(led-1,LOW); // turn off the previous light
    }
    led++;
  
  
  if (led==8)
  {   delay(1000);
      
      digitalWrite(7,LOW);//turn off the last light before flashing
      
      while(currentTime<10000)
      {
      for(int a=2;a<8;a++) //make loop for all the lights to turn on
      {
        digitalWrite(a,HIGH);
      }
      delay(100);
      for(int b=2;b<8;b++)//loop for all the lights to turn off 
      {
        digitalWrite(b,LOW);
      }
      delay(100);
      }
  }
  }
  SwitchState=digitalRead(switchPin);
  if (SwitchState != prevSwitchState)
  {
    for (int x=2;x<8;x++)
    {
      digitalWrite(x,LOW);
    }
    led=2;
    previousTime=currentTime;
  }
  prevSwitchState=SwitchState;
 }

So I'm trying to do the project Digital Glass Hour. I did everything the book told me to and it worked perfectly fine. But until I want to go a little further, I encountered some troubles. After having all the lights turned on (after 6s, 1s each) I want all six of it to flash (as an alarm). I got that part done, the problem is that I can't get out of the loop. Even if I shake the board (it has a tilt switch), it still doesn't do anything except keeping flashing. So can anyone tell me what I did wrong and how to fix it?
Thank you

      while(currentTime<10000)
      {
      for(int a=2;a<8;a++) //make loop for all the lights to turn on
      {
        digitalWrite(a,HIGH);
      }
      delay(100);
      for(int b=2;b<8;b++)//loop for all the lights to turn off
      {
        digitalWrite(b,LOW);
      }
      delay(100);
      }

Where do you ever update currentTime in that while loop?

What do you mean by "can't get out of the loop"? What do you really want to accomplish?

aarg:

      while(currentTime<10000)

{
      for(int a=2;a<8;a++) //make loop for all the lights to turn on
      {
        digitalWrite(a,HIGH);
      }
      delay(100);
      for(int b=2;b<8;b++)//loop for all the lights to turn off
      {
        digitalWrite(b,LOW);
      }
      delay(100);
      }




Where do you ever update currentTime in that while loop?

I thought the currentTime is auto updated since I used millis() function.

vaj4088:
What do you mean by "can't get out of the loop"? What do you really want to accomplish?

What I was trying to do is:

  • first get the lights to light up every second
  • when the last light shines, i will have all of them flash
    -and if I shake the breadboard, that will cause the SwitchState (from the tilt switch) to be different, and the whole thing restarts, back to the first step.

for some reason, the process doesn't restart when I shake the breadboard.

which did not happened until I put the "flashing code" in the program, that's why I think I did something wrong with that while-loop