I have the following snippet of code:
const unsigned long fiveMinutes = 5 * 60 * 1000UL;
unsigned long lastCheck = 0 - fiveMinutes;
unsigned long now = 0;
void loop() {
now = millis();
if ( now - lastCheck >= fiveMinutes ) {
doStuff();
lastCheck = now;
}
}
The doStuff() routine is getting called on every loop() iteration, because the value of lastCheck isn't getting updated. I thought Icould update global variables inside subroutines, but the behavior I'm seeing says otherwise. What am I doing wrong? (doStuff() is defined and works correctly, I'm not posting it here for brevity.)
unsigned long lastCheck = 0 - fiveMinutes;" Are you sure you meant that?lastCheck = now;insideloop(). That line doesn't update thelastCheckvariable correctly.loop().I have the following snippet of code:- Unfortunately snippets don't cut it as I try to explain at Snippets R Us! - you need to post a Minimal, Complete, and Verifiable example. That is, code that actually demonstrates your point.