bool hasIntervalPassed(unsigned long lastTime, unsigned long interval) {
unsigned long currentTime = getTime();
return (currentTime - lastTime >= interval);
and is tested with something like
if (sClock::hasIntervalPassed(lastLoopTime, ACTUATOR_BLINKEN_MS)) {
and set with
lastLoopTime = sClock::getTime();
I think this would be better if we flipped this, so we stored the next time we wanted to run, and checked if getTime() had passed it.
Two rationals for this.
a: the math is simpler in the hasIntervalPassed which is executed much more frequently than the setting.
b: when we get to do power management, we can do something like storing a global earliestAction time and sleeping till then.
The clock uses a pattern like
and is tested with something like
and set with
I think this would be better if we flipped this, so we stored the next time we wanted to run, and checked if getTime() had passed it.
Two rationals for this. a: the math is simpler in the
hasIntervalPassed
which is executed much more frequently than the setting. b: when we get to do power management, we can do something like storing a global earliestAction time and sleeping till then.