2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/timing/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
2021-12-29 05:16:45 -05:00
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/timing/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/timing/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/timing/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/timing/actions/workflows/jsoncheck.yml)
|
2021-01-29 06:31:58 -05:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/timing/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/timing.svg?maxAge=3600)](https://github.com/RobTillaart/timing/releases)
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
# Timing
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
Arduino library with wrappers for seconds millis micros.
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
A request often made on the Arduino forum and otherwise is an option to reset
|
|
|
|
the **millis()** function to 0 or another value.
|
|
|
|
This library provide wrapper classes around **millis()** and **micros()**
|
|
|
|
with the extra function to do this.
|
|
|
|
To implement this only a 4 byte offset is needed.
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
The classes are based upon **millis()** and **micros()**.
|
|
|
|
Therefore they have the same restrictions as these functions with respect to
|
|
|
|
overflow and accuracy. Depending on e.g. interrupts millis and micros can drift.
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
| class | overflow after | Notes |
|
|
|
|
|:-------------|:-------------------------|:--------------------|
|
|
|
|
| seconds | 49 days, 17:02:47 | based upon millis() |
|
|
|
|
| milliSeconds | 49 days, 17:02:47.297 |
|
|
|
|
| microSeconds | 00 days 01:11:34.967296 |
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
## Applications
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
These classes make it easy to make a simple stopwatch.
|
|
|
|
Or sync the time with an external source.
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
## Interface
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
The interface of all three are very similar:
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
- **microSeconds()** constructor, sets the offset so it starts at 0.
|
|
|
|
- **milliSeconds()** constructor, sets the offset so it starts at 0.
|
|
|
|
- **seconds()** constructor, sets the offset so it starts at 0.
|
|
|
|
- **uint32_t now()** returns the time elapsed since its 'zero moment'.
|
|
|
|
Ether set during construction or by a call to **set(0)**.
|
|
|
|
- **void set(uint32_t value = 0UL)** sets the offset of the object.
|
|
|
|
As it is possible to set it to a non zero value it is easy to adjust the time.
|
|
|
|
This allows one e.g. to compensate for overhead. Default = zero.
|
|
|
|
- **uint32_t getOffset()** returns current offset.
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Operation
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
See examples.
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
|
2021-12-29 05:16:45 -05:00
|
|
|
## Future
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
- test on ESP32
|
2021-12-29 05:16:45 -05:00
|
|
|
- nanos() on ESP32 ?
|
|
|
|
- implement printable interface (add unit)
|
|
|
|
- ?
|
|
|
|
- implement toClock()
|
|
|
|
- idea to give it a clock print layout
|
|
|
|
- seconds.toClock() -> DD 12:34:56
|
|
|
|
- milliSeconds.toClock(3) -> 12:23:45.123 (3) == 3 decimals..
|
|
|
|
- milliSeconds.toClock(1) -> 12:23:45.1
|
|
|
|
- microSeconds.toCLock() -> 12:23:45.123456 ???
|
|
|
|
- implement toSeconds()
|
|
|
|
- double milliSeconds.toSeconds() -> 45.123
|
|
|
|
- double microSeconds.toSeconds() -> 45.123456
|
|
|
|
- update documentation
|
|
|
|
- rounding effect, describe
|
2021-01-29 06:31:58 -05:00
|
|
|
|