Skip to content

Commit a9f08e6

Browse files
committed
add void resume()
1 parent c47ebc4 commit a9f08e6

File tree

18 files changed

+144
-102
lines changed

18 files changed

+144
-102
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.4] - 2025-03-20
10+
- add **void resume()** to replace cont()
11+
- update examples
12+
- update readme.md
13+
- minor edits
14+
15+
916
## [0.3.3] - 2024-04-11
1017
- update GitHub actions
1118
- minor edits

CountDown.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: CountDown.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.3
4+
// VERSION: 0.3.4
55
// PURPOSE: CountDown library for Arduino
66
// URL: https://github.com/RobTillaart/CountDown
77

@@ -89,7 +89,7 @@ void CountDown::stop()
8989
}
9090

9191

92-
void CountDown::cont()
92+
void CountDown::resume()
9393
{
9494
if (_state == CountDown::STOPPED)
9595
{

CountDown.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
//
33
// FILE: CountDown.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.3
5+
// VERSION: 0.3.4
66
// PURPOSE: CountDown library for Arduino
77
// URL: https://github.com/RobTillaart/CountDown
88

99

1010
#include "Arduino.h"
1111

12-
#define COUNTDOWN_LIB_VERSION (F("0.3.3"))
12+
#define COUNTDOWN_LIB_VERSION (F("0.3.4"))
1313

1414

1515
class CountDown
@@ -31,13 +31,15 @@ class CountDown
3131
bool start(uint8_t days, uint16_t hours, uint32_t minutes);
3232

3333
void stop();
34-
void cont();
34+
void resume();
3535
void restart();
3636

3737
uint32_t remaining();
3838
bool isRunning();
3939
bool isStopped();
4040

41+
// obsolete in future
42+
void cont() { resume(); }; // replaced by resume()
4143

4244
private:
4345
enum State { RUNNING, STOPPED };

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2015-2024 Rob Tillaart
3+
Copyright (c) 2015-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,31 @@ Arduino Library to implement a CountDown clock (in software polling, no hardware
1616

1717
## Description
1818

19-
The countdown library is a clock that counts down from a given time to zero.
20-
It does not call a function or so as the user is responsible to check the time remaining.
19+
The CountDown library is a clock that counts down from a given time to zero, like an hour glass.
20+
It does not call any function or so when reaching zero as the user is responsible to check the time remaining.
2121
Typically one checks the remaining time at least once in every **loop()**.
2222

23-
Under the hood the function uses **micros()** or **millis()** which results in a maximum time
24-
of 4294 seconds in micros (1h 10m) or about 49+ days when using milliseconds.
23+
A CountDown object can be used for
24+
- to detect a timeout
25+
- to show to a user how long to wait e.g. for a traffic light to become green.
26+
- to learn count backwards (educational)
27+
- etc.
2528

26-
For longer periods one could cascade countDown objects, so when one is finished the next one starts.
29+
Under the hood the CountDown object uses **micros()** or **millis()** which results in a maximum time
30+
of 4294 seconds in micros (about 1h 10m) or about 49+ days when using milliseconds.
2731

28-
Note the countdown object is as accurate as the underlying **millis()** or **micros()**.
32+
For longer periods one could cascade CountDown objects, so when one is finished the next one starts.
33+
34+
Note the CountDown object is as accurate as the underlying **millis()** or **micros()**.
2935
Interrupts etc. might cause deviations.
3036

3137

32-
#### Related
38+
### Related
3339

34-
- https://github.com/RobTillaart/StopWatch_RT
40+
- https://github.com/RobTillaart/printHelpers
41+
- https://github.com/RobTillaart/stopWatch_RT
42+
- https://github.com/RobTillaart/CountDown
43+
- https://github.com/RobTillaart/timing wrappers around millis() and microc()
3544

3645

3746
## Interface
@@ -40,14 +49,18 @@ Interrupts etc. might cause deviations.
4049
#include "CountDown.h"
4150
```
4251

52+
The main functions of the CountDown clock are straightforward:
4353

44-
The main functions of the CountDown clock are:
54+
### Constructor
4555

4656
- **CountDown(const enum Resolution res = MILLIS)** constructor, with default resolution of milliseconds.
4757
- **void setResolution(const enum Resolution res = MILLIS)** set the resolution,
48-
default to MILLIS.
58+
default to MILLIS. See table below.
4959
- **enum Resolution resolution()** return the current resolution (integer).
5060
- **char getUnits()** return the current resolution as printable char (u,m,s,M)
61+
62+
### Start / Stop functions
63+
5164
- **bool start(uint32_t ticks)** (re)start in current resolution.
5265
Typical used for MILLIS and MICROS which must be set manually.
5366
- **bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds)** Implicit set resolution to SECONDS.
@@ -57,21 +70,24 @@ Note that **remaining()** will report in SECONDS.
5770
Returns false if total exceeds 2^32 milliseconds ~49 days.
5871
Note that **remaining()** will report in MINUTES.
5972
- **void stop()** stop the count down.
60-
- **void cont()** resumes / continue the count down.
61-
*(note continue is a C-Keyword)*
73+
- **void resume()** resumes / continues the count down.
6274
- **void restart()** restart the CountDown with the same resolution and ticks as before.
6375
resets the \_ticks and starts again.
76+
77+
Obsolete in future (0.4.0).
78+
- **void cont()** resumes / continue the count down.
79+
*(note continue is a C-Keyword)*
80+
81+
### Status
82+
6483
- **uint32_t remaining()** returns the remaining ticks in current resolution.
6584
- **bool isRunning()** idem.
6685
- **bool isStopped()** idem.
6786

68-
These functions work straightforward.
69-
70-
7187
## Operation
7288

7389
The function **start(days, hours, minutes, seconds)** allows all combinations
74-
as long as the total time may not exceed 2^32 milliseconds.
90+
as long as the total time not exceeds 2^32 milliseconds.
7591
The function will return false if it exceeds this (rounded) maximum.
7692
Example calls are:
7793
- four hundred minutes **start(0, 0, 400, 0)**
@@ -130,7 +146,7 @@ the accuracy. E.g checking once a minute while doing milliseconds makes only sen
130146
if the number of milliseconds is still very large. Think of an adaptive strategy.
131147

132148

133-
#### Watchdog
149+
### Watchdog
134150

135151
One can call **start(...)** at any time to reset the running clock to a new value.
136152
This allows to implement a sort of watchdog clock in which e.g.
@@ -160,7 +176,7 @@ a repeating (timed) function or a watchdog. See examples.
160176
- add resolution::HOURS + **start(days, hours)**
161177
- extend adaptive display example
162178
- or default 00 minutes?
163-
179+
- add **void resume()** instead of **cont()**?
164180

165181
#### Wont (unless)
166182

examples/demo_DHMS/demo_DHMS.ino renamed to examples/countdown_DHMS/countdown_DHMS.ino

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// FILE: demo_DHMS.ino
2+
// FILE: countdown_DHMS.ino
33
// AUTHOR: Rob Tillaart
44
// PURPOSE: demo
55
// URL: http://forum.arduino.cc/index.php?topic=356253
@@ -13,20 +13,23 @@ CountDown CD;
1313

1414
void setup()
1515
{
16-
Serial.begin(115200);
17-
Serial.println(__FILE__);
18-
Serial.print("COUNTDOWN_LIB_VERSION: ");
19-
Serial.println(COUNTDOWN_LIB_VERSION);
20-
21-
// countdown 1 minute
22-
CD.start(0, 0, 1, 0);
16+
{
17+
// while(!Serial); // uncomment if needed
18+
Serial.begin(115200);
19+
Serial.println(__FILE__);
20+
Serial.print("COUNTDOWN_LIB_VERSION: ");
21+
Serial.println(COUNTDOWN_LIB_VERSION);
22+
Serial.println();
23+
24+
// countdown 1 minute
25+
CD.start(0, 0, 1, 0);
2326
}
2427

2528

2629
void loop()
2730
{
2831
static uint32_t last_remaining = 0;
29-
if (last_remaining != CD.remaining() || CD.remaining() == 0 )
32+
if ((last_remaining != CD.remaining()) || (CD.remaining() == 0) )
3033
{
3134
Serial.println();
3235
last_remaining = CD.remaining();

examples/countdown_adaptive_display/countdown_adaptive_display.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ int wait = 2000;
1515

1616
void setup()
1717
{
18+
{
19+
// while(!Serial); // uncomment if needed
1820
Serial.begin(115200);
1921
Serial.println(__FILE__);
2022
Serial.print("COUNTDOWN_LIB_VERSION: ");
2123
Serial.println(COUNTDOWN_LIB_VERSION);
2224
Serial.println();
2325

24-
2526
CD.start(0, 0, 2); // 2 minutes => unit is MINUTES
2627
}
2728

examples/countdown_demo1/countdown_demo1.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ uint32_t start, stop;
1616

1717
void setup()
1818
{
19+
// while(!Serial); // uncomment if needed
1920
Serial.begin(115200);
2021
Serial.println(__FILE__);
2122
Serial.print("COUNTDOWN_LIB_VERSION: ");
2223
Serial.println(COUNTDOWN_LIB_VERSION);
24+
Serial.println();
2325

2426
delay(random(2000));
2527
start = millis();
@@ -46,4 +48,3 @@ void loop()
4648

4749

4850
// -- END OF FILE --
49-

examples/countdown_demo2/countdown_demo2.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ uint8_t lines = 0;
1616

1717
void setup()
1818
{
19+
// while(!Serial); // uncomment if needed
1920
Serial.begin(115200);
2021
Serial.println(__FILE__);
2122
Serial.print("COUNTDOWN_LIB_VERSION: ");
2223
Serial.println(COUNTDOWN_LIB_VERSION);
24+
Serial.println();
2325

2426
for (int i = 0; i < 5; i++)
2527
{

examples/countdown_overflow_test/countdown_overflow_test.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ CountDown CD(CountDown::MICROS);
1313

1414
void setup()
1515
{
16+
// while(!Serial); // uncomment if needed
1617
Serial.begin(115200);
1718
Serial.println(__FILE__);
1819
Serial.print("COUNTDOWN_LIB_VERSION: ");
1920
Serial.println(COUNTDOWN_LIB_VERSION);
21+
Serial.println();
2022

2123
// wait for almost overflow ~70 minutes !!
2224
while (micros() < 4290000000UL)
@@ -25,7 +27,7 @@ void setup()
2527
delay(1000);
2628
}
2729
Serial.println("----------------------");
28-
30+
2931
CD.setResolution(CountDown::MICROS);
3032
CD.start(1 * 60 * 1000000UL); // 1 minute = 60 seconds
3133
}

0 commit comments

Comments
 (0)