public
Created

IsTime function

  • Download Gist
gistfile1.c
C
1 2 3 4 5 6 7
boolean IsTime(unsigned long *timeMark, unsigned long timeInterval) {
if (millis() - *timeMark >= timeInterval) {
*timeMark = millis();
return true;
}
return false;
}

Problem with this... Lets say ISTIME is called LATE - it can't compensate for this so accurate timing is impossible... surely needs to compensate and ensure that timer overflow doesn't mess anything up. Perhaps some may not want that compensation, a flag could allow both versions..

In case that's not clear, lets say we need this to run every 50ms. We come in late at 52ms... and the timeMark is reset for another 50ms. It SHOULD be set to 48ms to compensate for us being late this time. Also technically we're potentially creeping a fraction of a millisecond each time we use this.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.