This is just two steps of a test run, eventually there will be more steps. When the button is pressed briefly, led 3 lights for 3 seconds, if the button is pressed for longer the led 4 comes on and the led 3 goes off after 3 seconds. What should then happen is the led 4 goes off after 3 seconds, but it just stays on. Can you see what I am doing wrong?
// Variables constant
const int buttonPin =2; // button on pin 2 with 10k res to ground
const int led3Pin = 3; // led on pin 3 via 220 res
const int led4Pin = 4; // led on pin 4 via 220 res
long interval = 3000L; // interval 3 seconds
// Variables will change:
int buttonState = 0;
int timeVariable = 0; // not used yet
long previousMillis = 0; // will store last time LED was updated
void setup() {
pinMode (buttonPin, INPUT);
pinMode(led3Pin, OUTPUT);
pinMode(led4Pin, OUTPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin); // first led
if (buttonState == HIGH) {
++timeVariable; // not used yet
digitalWrite(led3Pin, HIGH);
}
else {
}
{ unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
digitalWrite(led3Pin, LOW);
buttonState = digitalRead(buttonPin); // second led
if (buttonState == HIGH) {
++timeVariable; // not used yet
digitalWrite(led4Pin, HIGH);
}
else {
}
{ unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
digitalWrite(led4Pin, LOW);
}
}
}
}
}