You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+72-36Lines changed: 72 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,65 +1,100 @@
1
-
# arduino-timer - library for delaying function calls
1
+
# arduino-timer-cpp17 - library for scheduling function calls
2
2
3
-
Simple *non-blocking* timer library for calling functions **in / at / every** specified units of time. Supports millis, micros, time rollover, and compile time configurable number of tasks.
3
+
Simple *non-blocking* timer library for calling functions **in / at / every** specified units of time. Supports millis, micros, time rollover, and compile-time configurable number of timers.
4
+
5
+
This library was inspired by [Michael Contreras' arduino-timer library](https://github.com/sponsors/contrem/arduino-timer), but has been rewritten to make use of 'modern C++' types and
6
+
functionality. As a result this library requires that the Arduino IDE toolchain be manually configured for "gnu++17" mode.
4
7
5
8
### Use It
6
9
7
-
Include the library and create a *Timer* instance.
10
+
Include the library and create a *TimerSet* instance.
8
11
```cpp
9
12
#include<arduino-timer.h>
10
13
11
-
autotimer = timer_create_default();
14
+
autotimerset = Timers::create_default();
12
15
```
13
16
14
-
Or using the *Timer* constructors for different task limits / time resolution
17
+
Or using the *TimerSet* constructors for different timer limits / time resolution.
15
18
```cpp
16
-
Timer<10> timer; // 10 concurrent tasks, using millis as resolution
17
-
Timer<10, micros> timer; // 10 concurrent tasks, using micros as resolution
18
-
Timer<10, micros, int> timer; // 10 concurrent tasks, using micros as resolution, with handler argument of type int
19
+
Timers::TimerSet<10> timerset; // 10 concurrent times, using millis as resolution
20
+
Timers::TimerSet<10, micros, delayMicroseconds> timerset; // 10 concurrent timers, using micros as resolution
19
21
```
20
22
21
-
Call *timer*.**tick()** in the loop function
23
+
Call *timerset*.**tick_and_delay()** in the ```loop``` function to execute handlers for any timers
24
+
which have expired and then delay until the next scheduled timer expiration.
22
25
```cpp
23
26
voidloop() {
24
-
timer.tick();
27
+
timerset.tick_and_delay();
25
28
}
26
29
```
27
30
28
-
Make a function to call when the *Timer* expires
31
+
Call *timerset*.**tick()** in the ```loop``` function to execute handlers for any timers
32
+
which have expired, and then return so additional processing can be handled in the loop function.
29
33
```cpp
30
-
boolfunction_to_call(void *argument /* optional argument given to in/at/every */) {
31
-
return true; // to repeat the action - false to stop
34
+
voidloop() {
35
+
timerset.tick;
36
+
}
37
+
```
38
+
39
+
Make a function to call (without arguments) when a *Timer* expires.
40
+
```cpp
41
+
Timers::HandlerResult function_to_call() {
42
+
return { Timers::TimerStatus::repeat, 0 }; // to repeat the action - 'completed' to stop
43
+
}
44
+
```
45
+
46
+
Make a function to call (with an argument) when a *Timer* expires.
Currently only a software timer. Any blocking code delaying *timer*.**tick()** will prevent the timer from moving forward and calling any functions.
179
+
Currently only a software timer. Any blocking code delaying *timerset*.**tick()** will prevent the TimerSet from moving forward and calling any functions.
145
180
146
181
The library does not do any dynamic memory allocation.
147
182
148
-
The number of concurrent tasks is a compile time constant, meaning there is a limit to the number of concurrent tasks. The **in / at / every** functions return **NULL** if the *Timer* is full.
183
+
The number of concurrent timers is a compile time constant, meaning there is a limit to the number of concurrent timers. The **in / at / every / now_and_every**
184
+
functions return a TimerHandle which evaluates to ```false``` if the TimerSet is full.
149
185
150
-
A *Task* value is valid only for the timer that created it, and only for the lifetime of that timer.
186
+
A *TimerHandle* value is valid only for the TimerSet that created it, and only for the lifetime of that timer.
151
187
152
-
Change the number of concurrent tasks using the *Timer* constructors. Save memory by reducing the number, increase memory use by having more. The default is **TIMER_MAX_TASKS** which is currently 16.
188
+
Change the number of concurrent timers using the *Timer* constructors. Save memory by reducing the number, increase memory use by having more. The default is **TIMERSET_DEFAULT_TIMERS** which is currently 16.
153
189
154
190
If you find this project useful, [consider becoming a sponsor.](https://github.com/sponsors/contrem)
sentence=Timer library for delaying function calls
7
-
paragraph=Simple non-blocking timer library for calling functions in / at / every specified units of time. Supports millis, micros, time rollover, and compiletime configurable number of tasks.
4
+
author=Kevin P. Fleming
5
+
maintainer=Kevin P. Fleming
6
+
sentence=Timer library for scheduling function calls
7
+
paragraph=Simple non-blocking timer library for calling functions in / at / every specified units of time. Supports millis, micros, time rollover, and compile-time configurable number of timers.
0 commit comments