forked from nettigo/Timers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimers.cpp
61 lines (49 loc) · 784 Bytes
/
Timers.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
52
53
54
55
56
57
58
59
60
61
#include "Timers.h"
void Timer::restart()
{
_lastTime = millis();
_running = true;
}
void Timer::begin(const uint32_t interval)
{
time(interval);
restart();
}
bool Timer::available()
{
if (_time == 0)
{
return false;
}
uint32_t actualTime = millis();
uint32_t deltaTime = actualTime - _lastTime;
if (deltaTime >= _time)
{
return true;
}
return false;
}
uint32_t Timer::time()
{
if (_time == 0)
{
return 0;
}
uint32_t actualTime = millis();
uint32_t deltaTime = actualTime - _lastTime;
return _time - deltaTime;
}
void Timer::time(const uint32_t interval)
{
_time = interval;
}
void Timer::pause()
{
_time = milis() - _lastTime;
_running = false;
}
void Timer::resume()
{
_lastTime = millis();
_running = true;
}