I am trying to modify the code of this project so that the led connected to pin 7 blinks after all the leds are on but I can't figure out how to do that. I would greatly appreciate any help with this and the code i am using now is:
const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 0;
int led = 2;
long interval = 1000;
void setup() {
for(int x = 2;x<8;x++){
pinMode(x, OUTPUT);
}
pinMode(switchPin, INPUT);
}
void loop(){
unsigned long currentTime = millis();
if(currentTime - previousTime > interval) {
previousTime = currentTime;
digitalWrite(led, HIGH);
led++;
if(led == 7);
}
switchState = digitalRead(switchPin);
if(switchState != prevSwitchState){
for(int x = 2;x<8;x++){
digitalWrite(x, LOW);
previousTime = currentTime;
}
}
prevSwitchState = switchState;
}
That part of the code accomplishes nothing. You need to post the original code, or a link to it.
The code you posted turns another LED on, if the interval between now and the last time an LED changed state is greater than the threshold. It looks like it tries to do something when the last LED has been turned on. But, that code appears to be missing, so we can't tell what it is supposed to do.
Clearly, led will have the value 7 when the last LED is turned on, so that would be where you would make the 7th LED change state instead of just turning on.
Sorry for the confusion ! That is the whole code that i got from the arduino starter kit I was just saying that one part of the code was already in it.