nass

This is great, and means you don't have to wait an hour too see the thing working. But a curious thing happens, it all works as expected... but after a certain length of time the whole hourglass starts all over again!

So I got curious and added some debug code, namely printing out the value of led. And when led gets to 76 things go weird. Can anyone explain this to me?

unsigned long previousTime = 0; // store the last time an LED was updatedint switchState = 0; // the current switch stateint prevSwitchState = 0; // the previous switch stateint led = 2; // a variable to refer to the LEDs

// 600000 = 10 minutes in millisecondslong interval = 200; // interval at which to light the next LED

void loop(){ // store the time since the Arduino started running in a variable unsigned long currentTime = millis();

// compare the current time to the previous time an LED turned on // if it is greater than your interval, run the if statement if(currentTime - previousTime > interval) { // save the current time as the last time you changed an LED previousTime = currentTime; // Turn the LED on digitalWrite(led, HIGH); // increment the led variable // in 10 minutes the next LED will light up led++;

//reset the timer previousTime = currentTime; } // set the previous switch state to the current state prevSwitchState = switchState;}

typical readout:

Quote

led is more than 7!!!!!!!!!!!! led: 70led is more than 7!!!!!!!!!!!! led: 71led is more than 7!!!!!!!!!!!! led: 72led is more than 7!!!!!!!!!!!! led: 73led is more than 7!!!!!!!!!!!! led: 74led is more than 7!!!!!!!!!!!! led: 75led is more than 7!!!!!!!!!!!! led: 76led is more than 7!!!!!!!!!!!! led: 4429led is more than 7!!!!!!!!!!!! led: 4430led is more than 7!!!!!!!!!!!! led: 4431led is more than 7!!!!!!!!!!!! led: 3led: 4led: 5led: 6led: 7led is more than 7!!!!!!!!!!!! led: 8led is more than 7!!!!!!!!!!!! led: 9led is more than 7!!!!!!!!!!!! led: 10led is more than 7!!!!!!!!!!!! led: 11led is more than 7!!!!!!!!!!!! led: 12

etc

Seems it's maybe some sort of memory thing? Because when I make the fabulously informative write " Serial.print("led is more than 7!!!!!!!!!!!! ");" have a few more exclamation marks in it it starts to behave differently