Created
January 22, 2012 00:12
-
-
Save ah01/1654676 to your computer and use it in GitHub Desktop.
IsTime function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean IsTime(unsigned long *timeMark, unsigned long timeInterval) { | |
if (millis() - *timeMark >= timeInterval) { | |
*timeMark = millis(); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.