Hi,
Can you please tell me why my 2 last LED´s do not work? The circuit is right, i tested it with another code from the internet and it worked.
Thanks
const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 1;
int led = 2;
int interval = 1000;
void setup() {
Serial.begin(9600);
for(int i = 2; i<6; i++) {
pinMode(i, OUTPUT);
}
pinMode(switchPin, INPUT);
}
void loop() {
unsigned long currentTime = millis();
if(currentTime-previousTime>=interval){
previousTime = currentTime;
digitalWrite(led, HIGH);
led++;
if(led == 8){
led = 2;
previousTime = currentTime;
for(int i = 2; i<6; i++){
digitalWrite(i, LOW);
led = 7;
}
}
}
switchState = digitalRead(switchPin);
if(switchState != prevSwitchState) {
previousTime = currentTime;
for(int i = 2;i<8;i++){
digitalWrite(i, LOW);
}
}
Serial.print(" previousTime: ");
Serial.print(previousTime);
Serial.print(" currentTime: ");
Serial.print(currentTime);
Serial.print(" switchState: ");
Serial.print(switchState);
Serial.print(" led: ");
Serial.print(led);
Serial.print(" prevSwitchState: ");
Serial.println(prevSwitchState);
delay(5);
}