CountDown: an example that runs
Yes. You can use the CountDown library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (LED). The example below, "A countdown that pauses, then lights an LED at zero", runs on the Arduino Uno R3.
Built in on Mokxi: #include <CountDown.h> and it builds, with nothing to install. Free, and no account needed.
What CountDown does
A timer counting down to zero in milliseconds, microseconds, seconds or minutes: start(), remaining(), stop(), cont(), isRunning(). That is what CountDown, by Rob Tillaart, covers. The sketch below uses it on the Arduino Uno: “A countdown that pauses, then lights an LED at zero”.
Rob Tillaart's CountDown library (0.3.5), a timer that counts down to zero in milliseconds, microseconds, seconds or minutes.
start(days, hours, minutes, seconds) counts in seconds and start(days, hours, minutes) in minutes. stop() holds the count, cont() carries on from it, restart() starts the last count again. isRunning() is false once it reaches zero.
The calls follow release 0.3.5 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.
| Library Manager name | CountDown |
|---|---|
| Author | Rob Tillaart |
| Include | #include <CountDown.h> |
| Boards | every board Mokxi compiles for |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | LED |
Install it
It builds on every board Mokxi compiles for.
In Mokxi it is built in: #include <CountDown.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "CountDown" by Rob Tillaart from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add CountDown to lib_deps in PlatformIO. Mokxi follows the calls of release 0.3.5, so a sketch written here builds there too.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- ATtiny85
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
CountDown CD(CountDown::MILLIS)
Makes CD, the CountDown object the calls below are made on.
CD.stop()
Stops it.
CD.remaining()
Returns the remaining as a whole number.
CD.isRunning()
Returns true or false for "is running".
Example: A countdown that pauses, then lights an LED at zero
On the Arduino Uno R3. It runs in the browser exactly as printed.
// After the library's countdown_demo example.
#include <CountDown.h>
CountDown CD(CountDown::MILLIS);
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
CD.start(1000);
delay(400);
CD.stop();
Serial.print("stopped with ");
Serial.println(CD.remaining() / 100 * 100);
delay(500);
Serial.print("still ");
Serial.println(CD.remaining() / 100 * 100);
CD.cont();
}
void loop() {
static bool told = false;
if (!told && !CD.isRunning()) {
told = true;
digitalWrite(13, HIGH);
Serial.print("zero at ");
Serial.println(millis() / 100 * 100);
}
}Wiring
- Arduino Uno R3 13 to LED A
- Arduino Uno R3 GND to LED C
Keep going
Try CountDown without installing anything
Open the example, change the sketch, and keep your version in a free account.