mirror of
https://github.com/AlexGyver/GyverLamp2.git
synced 2025-08-08 01:00:37 +03:00
add
This commit is contained in:
36
firmware/GyverLamp2_v0.7b/timerMillis.h
Normal file
36
firmware/GyverLamp2_v0.7b/timerMillis.h
Normal file
@@ -0,0 +1,36 @@
|
||||
class timerMillis {
|
||||
public:
|
||||
timerMillis() {}
|
||||
timerMillis(uint32_t interval, bool active = false) {
|
||||
_interval = interval;
|
||||
reset();
|
||||
if (active) restart();
|
||||
else stop();
|
||||
}
|
||||
void setInterval(uint32_t interval) {
|
||||
_interval = (interval == 0) ? 1 : interval;
|
||||
}
|
||||
boolean isReady() {
|
||||
if (_active && millis() - _tmr >= _interval) {
|
||||
//_tmr += _interval;
|
||||
reset();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void reset() {
|
||||
_tmr = millis();
|
||||
}
|
||||
void restart() {
|
||||
reset();
|
||||
_active = true;
|
||||
}
|
||||
void stop() {
|
||||
_active = false;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t _tmr = 0;
|
||||
uint32_t _interval = 0;
|
||||
boolean _active = false;
|
||||
};
|
Reference in New Issue
Block a user