GY-63_MS5611/libraries/timing/README.md
2022-11-26 14:28:31 +01:00

3.0 KiB

Arduino CI Arduino-lint JSON check License: MIT GitHub release

Timing

Arduino library with wrappers for seconds millis micros.

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.

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.

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

Applications

These classes make it easy to make a simple stopwatch. Or sync the time with an external source.

Interface

The interface of all three are very similar:

  • 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.

Operation

See examples.

Future

must

  • test on ESP32

should

  • 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 ???
    • printHelpers class?
  • implement toSeconds()
    • double milliSeconds.toSeconds() -> 45.123
    • double microSeconds.toSeconds() -> 45.123456

could

  • nanos() on ESP32 ?
  • implement printable interface
    • add unit (s, ms, us)
    • what layout to use?
  • update documentation
  • rounding effect, describe