mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.1 CountDown
This commit is contained in:
parent
16d1003e2e
commit
351754e6b2
@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.1] - 2023-03-14
|
||||
- fix #14 add **restart()** function.
|
||||
- add demo for restart **countdown_restart.ino**
|
||||
|
||||
|
||||
## [0.3.0] - 2023-01-10
|
||||
- fix #12 MINUTES bug
|
||||
- label enum resolution to be printable u, m, s, M.
|
||||
|
@ -1,11 +1,9 @@
|
||||
//
|
||||
// FILE: CountDown.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// PURPOSE: CountDown library for Arduino
|
||||
// URL: https://github.com/RobTillaart/CountDown
|
||||
//
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "CountDown.h"
|
||||
@ -100,6 +98,12 @@ void CountDown::cont()
|
||||
}
|
||||
|
||||
|
||||
void CountDown::restart()
|
||||
{
|
||||
start(_ticks);
|
||||
}
|
||||
|
||||
|
||||
uint32_t CountDown::remaining()
|
||||
{
|
||||
calcRemaining();
|
||||
|
@ -2,51 +2,52 @@
|
||||
//
|
||||
// FILE: CountDown.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.0
|
||||
// VERSION: 0.3.1
|
||||
// PURPOSE: CountDown library for Arduino
|
||||
// URL: https://github.com/RobTillaart/CountDown
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define COUNTDOWN_LIB_VERSION (F("0.3.0"))
|
||||
#define COUNTDOWN_LIB_VERSION (F("0.3.1"))
|
||||
|
||||
|
||||
class CountDown
|
||||
{
|
||||
public:
|
||||
enum Resolution { MICROS = 'u', MILLIS = 'm', SECONDS = 's', MINUTES = 'M' };
|
||||
enum Resolution { MICROS = 'u', MILLIS = 'm', SECONDS = 's', MINUTES = 'M' };
|
||||
|
||||
explicit CountDown(const enum Resolution res = MILLIS);
|
||||
explicit CountDown(const enum Resolution res = MILLIS);
|
||||
|
||||
void setResolution(const enum Resolution res = MILLIS);
|
||||
enum Resolution resolution() { return _res; };
|
||||
char getUnits();
|
||||
void setResolution(const enum Resolution res = MILLIS);
|
||||
enum Resolution resolution() { return _res; };
|
||||
char getUnits();
|
||||
|
||||
// one need to set the resolution before calling start(ticks).
|
||||
bool start(uint32_t ticks);
|
||||
// Implicit set resolution to SECONDS.
|
||||
bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds);
|
||||
// Implicit set resolution to MINUTES.
|
||||
bool start(uint8_t days, uint16_t hours, uint32_t minutes);
|
||||
// one need to set the resolution before calling start(ticks).
|
||||
bool start(uint32_t ticks);
|
||||
// Implicit set resolution to SECONDS.
|
||||
bool start(uint8_t days, uint16_t hours, uint32_t minutes, uint32_t seconds);
|
||||
// Implicit set resolution to MINUTES.
|
||||
bool start(uint8_t days, uint16_t hours, uint32_t minutes);
|
||||
|
||||
void stop();
|
||||
void cont();
|
||||
void stop();
|
||||
void cont();
|
||||
void restart();
|
||||
|
||||
uint32_t remaining();
|
||||
bool isRunning();
|
||||
bool isStopped();
|
||||
uint32_t remaining();
|
||||
bool isRunning();
|
||||
bool isStopped();
|
||||
|
||||
|
||||
private:
|
||||
enum State { RUNNING, STOPPED };
|
||||
enum State { RUNNING, STOPPED };
|
||||
|
||||
uint32_t _ticks;
|
||||
uint32_t _remaining;
|
||||
enum State _state;
|
||||
enum Resolution _res;
|
||||
uint32_t _startTime;
|
||||
void calcRemaining();
|
||||
uint32_t _ticks;
|
||||
uint32_t _remaining;
|
||||
enum State _state;
|
||||
enum Resolution _res;
|
||||
uint32_t _startTime;
|
||||
void calcRemaining();
|
||||
};
|
||||
|
||||
|
||||
|
@ -26,8 +26,18 @@ Note the countdown object is as accurate as the underlying **millis()** or **mic
|
||||
Interrupts etc might cause deviations.
|
||||
|
||||
|
||||
#### Links
|
||||
|
||||
Relates to - https://github.com/RobTillaart/StopWatch_RT
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "CountDown.h"
|
||||
```
|
||||
|
||||
|
||||
The main functions of the CountDown clock are:
|
||||
|
||||
- **CountDown(const enum Resolution res = MILLIS)** constructor, with default resolution of milliseconds.
|
||||
@ -46,6 +56,8 @@ Note that **remaining()** will report in MINUTES.
|
||||
- **void stop()** stop the count down.
|
||||
- **void cont()** resumes / continue the count down.
|
||||
*(note continue is a C-Keyword)*
|
||||
- **void restart()** restart the CountDown with the same resolution and ticks as before.
|
||||
resets the \_ticks and starts again.
|
||||
- **uint32_t remaining()** returns the remaining ticks in current resolution.
|
||||
- **bool isRunning()** idem.
|
||||
- **bool isStopped()** idem.
|
||||
@ -121,6 +133,11 @@ One can call **start(...)** at any time to reset the running clock to a new valu
|
||||
This allows to implement a sort of watchdog clock in which e.g.
|
||||
the user must press a button at least once per minute to show he is still awake.
|
||||
|
||||
Since version 0.3.1 the library supports **restart()** to start the countdown with
|
||||
the last used parameters of **start()**. The user does not need to remember the
|
||||
number of ticks or hours + minutes + seconds any more. Much easier tom implement
|
||||
a repeating (timed) function or a watchdog. See examples.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
@ -133,14 +150,13 @@ the user must press a button at least once per minute to show he is still awake.
|
||||
|
||||
#### could
|
||||
|
||||
- does **restart()** need to return some information? what?
|
||||
- add examples
|
||||
- visualisations - hexadecimal - alphabetical (radix 26)
|
||||
- depends on sensor
|
||||
- (semi)watchdog()
|
||||
- add resolution::HOURS + **start(days, hours)**
|
||||
- extend adaptive display example
|
||||
- add call-back function when **0** is reached
|
||||
- example
|
||||
- or default 00 minutes?
|
||||
|
||||
|
||||
#### wont (unless)
|
||||
@ -158,4 +174,6 @@ the user must press a button at least once per minute to show he is still awake.
|
||||
but drift / interrupts would make it fail in practice.
|
||||
- countdown with a big number e.g. billions/ second ==> national deficit counter.
|
||||
- not time triggered (is just a big variable)
|
||||
|
||||
- printable interface (stopwatch_rt)
|
||||
- add call-back function when **0** is reached
|
||||
- cannot be guaranteed as interface polls.
|
||||
|
@ -0,0 +1,41 @@
|
||||
//
|
||||
// FILE: countdown_restart.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo restart
|
||||
// URL: https://github.com/RobTillaart/CountDown
|
||||
|
||||
|
||||
#include "CountDown.h"
|
||||
|
||||
CountDown cdt; // default millis
|
||||
|
||||
uint8_t lines = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("COUNTDOWN_LIB_VERSION: ");
|
||||
Serial.println(COUNTDOWN_LIB_VERSION);
|
||||
|
||||
cdt.start(10000UL);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// time for a new sample
|
||||
if (cdt.remaining() == 0)
|
||||
{
|
||||
// restart countDownTimer same values
|
||||
cdt.restart();
|
||||
// make a sample and print it.
|
||||
Serial.print(millis());
|
||||
Serial.print("\t");
|
||||
Serial.println(analogRead(A0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -12,6 +12,7 @@ getUnits KEYWORD2
|
||||
start KEYWORD2
|
||||
stop KEYWORD2
|
||||
cont KEYWORD2
|
||||
restart KEYWORD2
|
||||
|
||||
remaining KEYWORD2
|
||||
isRunning KEYWORD2
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/CountDown.git"
|
||||
},
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=CountDown
|
||||
version=0.3.0
|
||||
version=0.3.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to implement a CountDown clock in SW.
|
||||
|
Loading…
Reference in New Issue
Block a user