GY-63_MS5611/libraries/Stopwatch_RT
2023-01-11 20:05:21 +01:00
..
.github 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
examples sync repos (mostly keeping build happy) 2022-10-01 13:17:26 +02:00
test 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
.arduino-ci.yml 0.3.3 Stopwatch_RT 2022-11-25 20:09:48 +01:00
CHANGELOG.md 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
keywords.txt 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
library.json 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
library.properties 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
LICENSE 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
README.md 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
StopWatch.cpp 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00
StopWatch.h 0.3.4 StopWatch_RT 2023-01-11 20:05:21 +01:00

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

Stopwatch_RT

Arduino Library implementing a stopwatch including seconds, milliseconds microseconds.

Description

The stopwatch class allows one to create a stopwatch with 4 levels of resolution:

  • MICROS - microseconds
  • MILLIS - milliseconds (default)
  • SECONDS - seconds
  • MINUTES - minutes (added 0.2.0)

Note that the resolution chosen implies the finest granularity of units measured. E.g. if chosen minutes then one cannot measure half (30 sec) or other part of a minute.

The resolution is typically set in the constructor, however since 0.2.0 one can call setResolution() to change the 'tick unit' of the clock runtime. This way one can reuse the stopwatch object without creating a new one and thereby save some memory.

Warning: Changing the resolution will reset the stopwatch as start time and stop time will become meaningless. The stopwatch will reset even when the resolution is the current resolution.

This library is based upon millis() and micros() and therefore has the same restrictions and limitations as these functions with respect to overflow and precision. This means minutes and seconds will overflow also after about 49 days.

Relates to - https://github.com/RobTillaart/CountDown

Interface

Core

  • StopWatch(Resolution resolution = MILLIS) constructor, with default resolution.
  • void start() start counting
  • void stop() stop counting
  • uint32_t elapsed() returns the time in chosen units since last start()
  • void reset() resets the counting to 0.
  • char getUnits() returns u, s, m , M.

Status

  • bool isRunning() returns true if clock is counting.
  • bool isStopped() returns true if clock is stopped.
  • bool isReset() returns true if clock is reset.
  • enum state() returns RESET, RUNNING or STOPPED.
  • void setResolution(Resolution resolution) changes the resolution of the stopwatch and resets it. Even when called with the current resolution a reset will take place.
  • enum resolution() returns MICROS, MILLIS, SECONDS or MINUTES.

Printable

As the stopwatch implements the printable interface since version 0.3.1 one can call

Serial.println(stopwatch);

To get output like "115 ms" or "159753 us" including the units.

Calibration

If processors internal clock are not accurately enough, one can adjust the two constants in the StopWatch.h file. Use at your own risk.

  • STOPWATCH_SECONDS_DIVIDER default 1000
  • STOPWATCH_MINUTES_DIVIDER default 60000

Obsolete

The use of value() is obsolete, use elapsed() instead.

Operation

See examples

Future

must

should

  • create getters and setters for the calibration constants so they can changed runtime under program control. Must it be float + round() or uint32_t ?

could

  • with rising of faster processors in Arduino ecosystem, NANOS might added. Be aware that these short time frames are better measured e.g. by a hardware timer.
  • resolution() ==> getResolution()