-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.h
More file actions
39 lines (32 loc) · 817 Bytes
/
Timer.h
File metadata and controls
39 lines (32 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <Arduino.h>
class Timer
{
private:
bool isPeriodical = false;
bool isAlreadyTriggered = false;
unsigned long int trigTime = 0;
unsigned int period = 0;
public:
Timer(bool isPeriodical, unsigned int period) {
this->isPeriodical = isPeriodical;
this->period = period;
}
Timer() {
}
~Timer() {
}
void setTimer(long int newTime) {
this->trigTime = newTime;
isAlreadyTriggered = false;
}
bool checkTimer() {
if(millis() >= trigTime && !isAlreadyTriggered) {
isAlreadyTriggered = true;
if(isPeriodical) {
setTimer(millis() + period);
}
return true;
}
else return false;
}
};