puzzle-box/pulse.cpp

27 lines
447 B
C++
Raw Normal View History

2020-12-06 18:36:12 -07:00
#include "pulse.h"
#include <Arduino.h>
Pulse::Pulse(unsigned long period) {
this->period = period;
this->nextEventMillis = 0;
}
bool Pulse::Tick() {
unsigned long now = millis();
2020-12-13 21:07:20 -07:00
2020-12-06 18:36:12 -07:00
if (now >= nextEventMillis) {
2020-12-13 21:07:20 -07:00
Until(period, now);
2020-12-06 18:36:12 -07:00
return true;
}
return false;
}
2020-12-13 21:07:20 -07:00
void Pulse::Until(unsigned long next, unsigned long now) {
nextEventMillis = now + next;
}
void Pulse::Until(unsigned long next) {
Until(next, millis());
}