-
Notifications
You must be signed in to change notification settings - Fork 2
/
timer.h
103 lines (90 loc) · 1.7 KB
/
timer.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef _timer_h_
#define _timer_h_
/**
* Simple and easy to use timer library
*
* ### Description
*
* ### Example
*
* Hallo World example (blinking LED)
*
* ```cpp
* #include <Timer.h>
*
* Timer timer(1000);
*
* void setup() {
* pinMode(LED, OUTPUT);
* }
*
* void loop() {
* if (timer.elapsed()) {
* digitalWrite(LED, ! digitalRead(LED)); // toggle LED
* }
* }
* ```
*
*/
class Timer
{
public:
/**
* ## Type definition
*/
/**
* Type of time in miliseconds
*/
typedef unsigned long time_ms;
/**
* ## Constructors
**/
/**
* Create new timer instance with defined interval
*
* # Parameters
*
* - `interval` - interval time (in miliseconds)
* - `autostop` - indicate if timer should stop after each elapsed
*
* # Example
* ```cpp
* Timer mytimer(5000); // New timer for 5 sec.
* ```
*/
Timer(time_ms interval, bool autostop = false);
/**
* ## Methods
**/
/**
* Check if set interval elapsed
*
* # Return
*
* Return `true` if interval epalsed othervise `false`
*
*/
bool elapsed();
/**
* Restart timer form begining
*/
void restart();
/**
* Restart timer form begining and change interval
*
* # Parametry:
*
* - `interval` - interval time (in miliseconds)
*/
void restart(time_ms interval);
/**
* ## Attributes
*/
/**
* Timers interval (in miliseconds)
*/
time_ms interval;
private:
unsigned long last;
};
#endif