-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.c
More file actions
56 lines (53 loc) · 947 Bytes
/
Timer.c
File metadata and controls
56 lines (53 loc) · 947 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// --------------------------------------------------
// Timer Class
// v.1.0.1
// by Samet Baykul
// --------------------------------------------------
class Timer
{
public:
// Constructor
Timer(int StepInterval);
// Methods
void UPDATE(void (*CallBack)());
void START();
void STOP();
void RESUME();
void NEXT(void (*CallBack)());
private:
// Main
bool _active;
// Dynamics
int _step_interval;
unsigned long _last_update;
};
Timer::Timer(int StepInterval)
{
_step_interval = StepInterval;
_active = true;
}
void Timer::UPDATE(void (*CallBack)())
{
if (_active && millis() - _last_update > _step_interval)
{
(*CallBack)();
_last_update = millis();
}
}
void Timer::START()
{
_active = true;
}
void Timer::STOP()
{
_active = false;
}
void Timer::RESUME()
{
_active = !_active;
}
void Timer::NEXT(void (*CallBack)())
{
(*CallBack)();
_last_update = millis();
}