Chrono: an example that runs
Yes. You can use the Chrono library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (LED). The example below, "Two LEDs on two chronos, and a stopwatch that pauses", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Chrono.h> and it builds, with nothing to install. Free, and no account needed.
What Chrono does
A stopwatch checked in loop(): hasPassed(1000, true), elapsed(), stop(), resume() and add(), in milliseconds, microseconds or seconds. That is what Chrono, by Thomas O Fredericks, covers. The sketch below uses it on the Arduino Uno: “Two LEDs on two chronos, and a stopwatch that pauses”.
Thomas O Fredericks' Chrono library (1.2.0), a stopwatch on millis(), micros() or seconds that a sketch checks rather than waits on.
stop() freezes elapsed() and resume() carries on from it; add() moves it on; hasPassed(t, true) restarts the chrono as it answers, counted from when it passed so the beat does not drift. Like upstream it is safe across the wrap of millis().
The calls follow release 1.2.1 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 | Chrono |
|---|---|
| Author | Thomas O Fredericks |
| Include | #include <Chrono.h>#include <LightChrono.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 <Chrono.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Chrono" by Thomas O Fredericks from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Chrono to lib_deps in PlatformIO. Mokxi follows the calls of release 1.2.1, 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.
Chrono ledChrono
Makes ledChrono, the Chrono object the calls below are made on.
stopwatch.stop()
Stops it and returns true or false.
stopwatch.resume()
Resumes it.
ledChrono.hasPassed(250, true)
Returns true or false for "has passed". Arguments: timeout, restart if passed.
stopwatch.isRunning()
Returns true or false for "is running".
Example: Two LEDs on two chronos, and a stopwatch that pauses
On the Arduino Uno R3. It runs in the browser exactly as printed.
// After the library's Blink example.
#include <Chrono.h>
Chrono ledChrono;
Chrono stopwatch;
int ledState = LOW;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
delay(300);
stopwatch.stop();
Serial.print("stopped at ");
Serial.println(stopwatch.elapsed() / 100 * 100);
delay(500);
Serial.print("still ");
Serial.println(stopwatch.elapsed() / 100 * 100);
stopwatch.resume();
}
void loop() {
if (ledChrono.hasPassed(250, true)) {
ledState = !ledState;
digitalWrite(13, ledState);
}
if (stopwatch.hasPassed(1000) && stopwatch.isRunning()) {
stopwatch.stop();
Serial.println("a second of running time");
}
}Wiring
- Arduino Uno R3 13 to LED A
- Arduino Uno R3 GND to LED C
Try Chrono without installing anything
Open the example, change the sketch, and keep your version in a free account.