|
4 | 4 | [](https://github.com/RobTillaart/CountDown/blob/master/LICENSE) |
5 | 5 | [](https://github.com/RobTillaart/CountDown/releases) |
6 | 6 |
|
| 7 | + |
7 | 8 | # CountDown |
8 | 9 |
|
9 | 10 | Arduino Library to implement a CountDown clock (in SW polling, no HW timer). |
10 | 11 |
|
| 12 | + |
11 | 13 | ## Description |
12 | 14 |
|
| 15 | +The countdown library is a clock that counts down from a given time to zero. |
| 16 | +It does not call a function or so as the user is responsible to check the time remaining. |
| 17 | +Typically one checks the remaining time in every loop. |
| 18 | + |
| 19 | +UNder the hood the function uses **micros()** or **millis()** which results in a maximum time |
| 20 | +of 4294 seconds in micros (1h10m) or something like 49+ days when using millis. |
| 21 | + |
| 22 | +For longer periods one could cascade countDown, so when one is finished the next starts. |
| 23 | + |
| 24 | + |
| 25 | +## Interface |
| 26 | + |
13 | 27 | The main functions of the CountDown clock are: |
14 | 28 |
|
15 | | -- **void start(ticks);** |
16 | | -- **void start(days, hours, minutes, seconds);** |
17 | | -- **void start(days, hours, minutes);** |
18 | | -- **void stop();** |
19 | | -- **void cont();** *(continue is a C-Keyword)* |
20 | | -- **uint32_t remaining();** |
21 | | -- **bool isRunning();** |
| 29 | +- **bool start(ticks)** |
| 30 | +- **bool start(days, hours, minutes, seconds)** |
| 31 | +- **bool start(days, hours, minutes)** |
| 32 | +- **void stop()** |
| 33 | +- **void cont()** *(continue is a C-Keyword)* |
| 34 | +- **uint32_t remaining()** |
| 35 | +- **bool isRunning()** |
22 | 36 |
|
23 | 37 | These functions work straightforward. |
24 | 38 |
|
| 39 | + |
| 40 | +## Operation |
| 41 | + |
25 | 42 | The function **start(days, hours, minutes, seconds)** has changed its |
26 | 43 | parameters type to minimize them, given that the total time may not exceed 2^32 milliseconds. |
27 | 44 | This allows the user to call **start()** with e.g. four hundred minutes **start(0, 0, 400, 0)** |
28 | 45 | or a million seconds **start(0, 0, 0, 1000000)** as parameter. |
29 | | -The resolution is implicitly set to *SECONDS*. |
30 | | - |
31 | | -Note: the function **start()** does not check if the parameters cause an overflow |
32 | | -in the underlying math. That is responsibility of the user. |
| 46 | +The resolution is implicitly set to **SECONDS**. |
33 | 47 |
|
34 | | -The function **start(days, hours, minutes)** is new since 0.2.2. |
35 | | -It also uses **millis()** under the hood. The resolution is implicitly set to *MINUTES*. |
| 48 | +Since 0.2.4 the function **start()** will check if the parameters cause an overflow |
| 49 | +in the underlying math. If there is no overflow call to **start()** returns true. |
| 50 | +If there is an overflow it returns false |
36 | 51 |
|
37 | 52 | Total amount of time to countdown for **MICROS** may not exceed 2\^32 micros ~ 1hr 10 minutes. |
38 | 53 | Total amount of time to countdown for **MILLIS**, **SECONDS** and **MINUTES** |
39 | 54 | may not exceed 2\^32 millis ~49 days |
40 | 55 |
|
41 | | -## Operation |
| 56 | + |
| 57 | +The function **start(days, hours, minutes)** is new since 0.2.2. |
| 58 | +It also uses **millis()** under the hood. The resolution is implicitly set to **MINUTES**. |
| 59 | + |
| 60 | + |
| 61 | +| Call to start() | resolution | max time | comments | |
| 62 | +|:--------------------------------------|:-----------------|:---------:|:---------| |
| 63 | +| start(days, hours, minutes, seconds) | SECONDS = millis | 49+ days | |
| 64 | +| start(days, hours, minutes) | MINUTES = millis | 49+ days | |
| 65 | +| start(ticks) | MILLIS = millis | 49+ days | default | |
| 66 | +| start(ticks) | MICROS = micros | ~70 min | use setResolution(MICROS) | |
| 67 | +| start(ticks) | SECONDS = millis | 49+ days | use setResolution(SECONDS) | |
| 68 | +| start(ticks) | MINUTES = millis | 49+ days | use setResolution(MINUTES) | |
| 69 | + |
42 | 70 |
|
43 | 71 | The Countdown clock uses by default **millis()** to do the time keeping, |
44 | 72 | although this can be changed runtime by **setResolution(res)**. The parameter |
45 | 73 | **res** can be: |
46 | 74 | - **MICROS** |
47 | | -- **MILLIS** |
| 75 | +- **MILLIS** // default |
48 | 76 | - **SECONDS** // based upon millis() |
49 | 77 | - **MINUTES** // based upon millis() |
50 | 78 |
|
|
0 commit comments