PeterH:
By the way, your implementation of timer() does not handler millis() overflow correctly. To handle overflow, you can code it like this:if(millis() - lastTime > interval)
{
// interval has expired
....
Mine should do the same thing. My code is:
//keep track of time and handle millis() rollover
boolean timer(unsigned long timeout)
{
return (long)(millis() - timeout) >= 0;
}
and then when I need to time something I do something like this:
last_valid_data = millis() + 2000;
and then I can just call timer like this:
if(timer(last_valid_data))
which I believe mathematically is equivalent to your code. I could be wrong though. I took calculus twice in college and still only squeaked out a "C" grade so my math may not be up to snuff.