Thanks for your reply, here's the code
// Every ten seconds, a light goes on.
//After all the lights have been turned on, it starts again.
//if the switch is tilted, it starts again.
const int switchPin = 8;
unsigned long previousTime=0; // variable to hold the time
int switchState =0; // define time for comparison.
int prevSwitchState =0;
int led = 2; // variable created to know which pin to start from
long interval = 1000; // interval between each LED turning on
void setup (){
pinMode (switchPin, INPUT);
for (int x=2; x<8; x++){
pinMode(x,OUTPUT);
}
}
void loop () {
unsigned long currentTime = millis();
if(currentTime - previousTime > interval) {
previousTime = currentTime;
digitalWrite(led,HIGH);
led++;
// When the LED on pin 7 is turned on, the whole process starts with all lEDs turned off
if(led == 9) {
for(int x = 2; x < 8; x++){
digitalWrite(x, LOW);
}
led = 2;
previousTime = currentTime;
}
}
switchState = digitalRead(switchPin);
if(switchState != prevSwitchState){
for(int x =2; x<8; x++){
digitalWrite(x, LOW);
}
led = 2;
previousTime = currentTime;
}
prevSwitchState = switchState;
}