-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimerTask.cpp
53 lines (39 loc) · 905 Bytes
/
TimerTask.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
#include "Arduino.h"
#include "TimerTask.h"
/**
* Consturctor
**/
TimerTask::TimerTask(unsigned long delta, boolean timer_status) {
delta_time = delta;
active = timer_status;
}
// activate method
void TimerTask::activate() {
active = true;
}
// desactivate method
void TimerTask::desactivate() {
active = false;
}
// single line active method
void TimerTask::setActive(boolean timer_status) {
active = timer_status;
}
// main method, run soft timer
void TimerTask::tick(void (*callback)(int count), unsigned long delta) {
if(delta > 0 ) {
delta_time = delta;
}
//check if it's active
if(active) {
//start counting
current_millis = millis();
if(current_millis - previous_millis >= delta_time) {
//start new cycle
previous_millis = current_millis;
count ++;
//call callback
callback(count);
}
}
}