@@ -10,23 +10,23 @@ _This is a library I use in almost all of my projects. It is fully unit-tested a
1010
1111### Example 1: A simple timeout
1212
13- The LED will turn on after 2 seconds.
13+ The LED will turn off after 2 seconds.
1414
1515``` cpp
16- #include < timeout .h>
16+ #include < Timeout .h>
1717
1818const int LED_PIN = 13 ;
19- Timeout timeout ;
19+ Timeout timer ;
2020
2121void setup ()
2222{
23- pinMode (LED_PIN, OUTPUT);
24- timeout .start(2000);
23+ pinMode (LED_PIN, OUTPUT);
24+ timer .start(2000);
2525}
2626
2727void loop ()
2828{
29- digitalWrite (LED_PIN, timeout .time_over());
29+ digitalWrite (LED_PIN, !timer .time_over());
3030}
3131```
3232
@@ -37,7 +37,7 @@ Press the button to turn on the LED.
3737Failing to press the button for more than one second switches off the LED.
3838
3939``` cpp
40- #include < timeout .h>
40+ #include < Timeout .h>
4141
4242const int LED_PIN = 13 ;
4343const int BUTTON_PIN = 12 ;
@@ -46,20 +46,16 @@ Timeout heartbeat;
4646
4747void setup ()
4848{
49- pinMode (LED_PIN, OUTPUT);
50- pinMode(BUTTON_PIN, INPUT);
51-
52- heartbeat.prepare(1000);
49+ pinMode (LED_PIN, OUTPUT);
50+ pinMode (BUTTON_PIN, INPUT);
5351}
5452
5553void loop ()
5654{
57- if (digitalRead(BUTTON_PIN))
58- {
59- heartbeat.start();
60- }
61-
62- digitalWrite (LED_PIN, !heartbeat.time_over());
55+ if (digitalRead(BUTTON_PIN)) {
56+ heartbeat.start(1000);
57+ }
58+ digitalWrite (LED_PIN, !heartbeat.time_over());
6359}
6460```
6561
@@ -68,7 +64,7 @@ void loop()
6864Toggles the LED every 200 milliseconds.
6965
7066``` cpp
71- #include < timeout .h>
67+ #include < Timeout .h>
7268
7369const int LED_PIN = 13 ;
7470bool led_on = false ;
@@ -77,17 +73,15 @@ Timeout timer;
7773
7874void setup ()
7975{
80- pinMode (LED_PIN, OUTPUT);
81- timer.start(200);
76+ pinMode (LED_PIN, OUTPUT);
8277}
8378
8479void loop ()
8580{
86- if (timer.periodic())
87- {
88- led_on = !led_on;
89- digitalWrite (LED_PIN, led_on);
90- }
81+ if (timer.periodic(200)) {
82+ led_on = !led_on;
83+ digitalWrite(LED_PIN, led_on);
84+ }
9185}
9286```
9387
@@ -96,23 +90,25 @@ void loop()
9690` Timeout ` instances have the following methods:
9791
9892``` cpp
99- // setup duration but don't start (time_over() will return true)
100- // then call `start()` somewhere else in your code to start the timer.
101- void prepare (unsigned long duration);
93+ // set the timer to `time_ms` and start ticking
94+ void start (uint32_t time_ms);
95+
96+ // returns a single true when time runs out and then resets to ` time_ms ` .
97+ bool periodic(uint32_t time_ms);
10298
103- // setup duration and start the timer (time_over() is false
104- // for the next ` duration ` milliseconds)
105- void start(unsigned long duration );
99+ // pause and resume the timer
100+ void pause(void);
101+ void resume(void );
106102
107- // returns true if time ran out, false otherwise
108- bool time_over( );
103+ // runs out the timer so ` time_over() ` returns true
104+ void expire(void );
109105
110- // winds up the timer to last known duration
111- void start( );
106+ // returns whether the time ran out
107+ bool time_over(void );
112108
113- // runs out the timer so time_over() is true
114- void expire( );
109+ // returns whether the timer is paused
110+ bool is_paused(void );
115111
116- // returns a single true when time runs out then automatically resets itself
117- bool periodic( );
112+ // returns the milliseconds until the timer runs out
113+ uint32_t time_left_ms(void );
118114```
0 commit comments