1010 *
1111 */
1212
13- #include < arduino-timer-cpp17.h >
13+ #include < arduino-timer-cpp17.hpp >
1414
1515auto timerset = Timers::create_default(); // create a TimerSet with default settings
1616Timers::TimerSet<> default_timerset; // same as above
@@ -22,66 +22,66 @@ Timers::TimerSet<1, Timers::Clock::micros> microtimerset;
2222Timers::TimerSet<16 , Timers::Clock::millis> t_timerset;
2323
2424Timers::HandlerResult toggle_led () {
25- digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)); // toggle the LED
26- return Timers::TimerStatus::repeat;
25+ digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)); // toggle the LED
26+ return Timers::TimerStatus::repeat;
2727}
2828
2929Timers::HandlerResult print_message (const char *message) {
30- Serial.print (" print_message: " );
31- Serial.println (message);
32- return Timers::TimerStatus::repeat;
30+ Serial.print (" print_message: " );
31+ Serial.println (message);
32+ return Timers::TimerStatus::repeat;
3333}
3434
3535size_t repeat_count = 1 ;
3636Timers::HandlerResult repeat_x_times (size_t limit) {
37- Serial.print (" repeat_x_times: " );
38- Serial.print (repeat_count);
39- Serial.print (" /" );
40- Serial.println (limit);
37+ Serial.print (" repeat_x_times: " );
38+ Serial.print (repeat_count);
39+ Serial.print (" /" );
40+ Serial.println (limit);
4141
42- // remove this task after limit reached
43- return ++repeat_count <= limit ? Timers::TimerStatus::repeat : Timers::TimerStatus::completed;
42+ // remove this task after limit reached
43+ return ++repeat_count <= limit ? Timers::TimerStatus::repeat : Timers::TimerStatus::completed;
4444}
4545
4646void setup () {
47- Serial.begin (9600 );
48- pinMode (LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
47+ Serial.begin (9600 );
48+ pinMode (LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
4949
50- // call the toggle_led function every 500 millis (half second)
51- timerset.every (500 , toggle_led);
50+ // call the toggle_led function every 500 millis (half second)
51+ timerset.every (500 , toggle_led);
5252
53- // call the repeat_x_times function every 1000 millis (1 second)
54- timerset.every (1000 , [](){ return repeat_x_times (10 ); });
53+ // call the repeat_x_times function every 1000 millis (1 second)
54+ timerset.every (1000 , [](){ return repeat_x_times (10 ); });
5555
56- // call the print_message function every 1000 millis (1 second),
57- // passing it an argument string
58- t_timerset.every (1000 , [](){ return print_message (" called every second" ); });
56+ // call the print_message function every 1000 millis (1 second),
57+ // passing it an argument string
58+ t_timerset.every (1000 , [](){ return print_message (" called every second" ); });
5959
60- // call the print_message function in five seconds
61- t_timerset.in (5000 , [](){ return print_message (" delayed five seconds" ); });
60+ // call the print_message function in five seconds
61+ t_timerset.in (5000 , [](){ return print_message (" delayed five seconds" ); });
6262
63- // call the print_message function in fifteen seconds by scheduling and then rescheduling
64- auto resched_timer = t_timerset.in (5000 , [](){ return print_message (" delayed fifteen seconds" ); });
65- t_timerset.reschedule_in (resched_timer, 15000 );
63+ // call the print_message function in fifteen seconds by scheduling and then rescheduling
64+ auto resched_timer = t_timerset.in (5000 , [](){ return print_message (" delayed fifteen seconds" ); });
65+ t_timerset.reschedule_in (resched_timer, 15000 );
6666
67- // call the print_message function at time + 10 seconds
68- t_timerset.at (millis () + 10000 , [](){ return print_message (" call at millis() + 10 seconds" ); });
67+ // call the print_message function at time + 10 seconds
68+ t_timerset.at (millis () + 10000 , [](){ return print_message (" call at millis() + 10 seconds" ); });
6969
70- // call the toggle_led function every 500 millis (half-second)
71- auto timer = timerset.every (500 , toggle_led);
72- timerset.cancel (timer); // this task is now cancelled, and will not run
70+ // call the toggle_led function every 500 millis (half-second)
71+ auto timer = timerset.every (500 , toggle_led);
72+ timerset.cancel (timer); // this task is now cancelled, and will not run
7373
74- // call print_message in 2 seconds, but with microsecond clock
75- microtimerset.in (2000000 , [](){ return print_message (" delayed two seconds using microseconds" ); });
74+ // call print_message in 2 seconds, but with microsecond clock
75+ microtimerset.in (2000000 , [](){ return print_message (" delayed two seconds using microseconds" ); });
7676
77- if (!microtimerset.in (5000 , [](){ return print_message (" never printed" ); })) {
78- /* this fails because we created microtimerset with only 1 concurrent timer slot */
79- Serial.println (" Failed to add microsecond event - timer full" );
80- }
77+ if (!microtimerset.in (5000 , [](){ return print_message (" never printed" ); })) {
78+ /* this fails because we created microtimerset with only 1 concurrent timer slot */
79+ Serial.println (" Failed to add microsecond event - timer full" );
80+ }
8181}
8282
8383void loop () {
84- timerset.tick ();
85- t_timerset.tick ();
86- microtimerset.tick ();
84+ timerset.tick ();
85+ t_timerset.tick ();
86+ microtimerset.tick ();
8787}
0 commit comments