Skip to content

Instantly share code, notes, and snippets.

@ah01
Created January 22, 2012 00:12
Show Gist options
  • Save ah01/1654676 to your computer and use it in GitHub Desktop.
Save ah01/1654676 to your computer and use it in GitHub Desktop.
IsTime function
boolean IsTime(unsigned long *timeMark, unsigned long timeInterval) {
if (millis() - *timeMark >= timeInterval) {
*timeMark = millis();
return true;
}
return false;
}
@scargill
Copy link

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.

@q2dg
Copy link

q2dg commented Sep 26, 2015

@scargill So...any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment