GY-63_MS5611/libraries/Stopwatch_RT/README.md

109 lines
3.8 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/Stopwatch_RT/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-28 11:04:43 -05:00
[![Arduino-lint](https://github.com/RobTillaart/Stopwatch_RT/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Stopwatch_RT/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/Stopwatch_RT/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Stopwatch_RT/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/Stopwatch_RT/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Stopwatch_RT.svg?maxAge=3600)](https://github.com/RobTillaart/Stopwatch_RT/releases)
# Stopwatch_RT
2021-12-28 11:04:43 -05:00
Arduino Library implementing a stopwatch including seconds, milliseconds microseconds.
2021-01-29 06:31:58 -05:00
## Description
2021-12-28 11:04:43 -05:00
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)
2021-01-29 06:31:58 -05:00
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
2021-12-28 11:04:43 -05:00
restrictions and limitations as these functions with respect to overflow and precision.
2021-01-29 06:31:58 -05:00
This means minutes and seconds will overflow also after about 49 days.
2023-01-11 14:05:21 -05:00
#### Links
Relates to - https://github.com/RobTillaart/CountDown
2021-01-29 06:31:58 -05:00
## Interface
2021-12-28 11:04:43 -05:00
2021-01-29 06:31:58 -05:00
### Core
2021-12-28 11:04:43 -05:00
- **StopWatch(Resolution resolution = MILLIS)** constructor, with default resolution.
2021-01-29 06:31:58 -05:00
- **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.
2023-01-11 14:05:21 -05:00
- **char getUnits()** returns u, s, m , M.
2021-01-29 06:31:58 -05:00
2021-12-28 11:04:43 -05:00
2021-01-29 06:31:58 -05:00
### Status
- **bool isRunning()** returns true if clock is counting.
2023-01-11 14:05:21 -05:00
- **bool isStopped()** returns true if clock is stopped.
- **bool isReset()** returns true if clock is reset.
2021-01-29 06:31:58 -05:00
- **enum state()** returns RESET, RUNNING or STOPPED.
2021-12-28 11:04:43 -05:00
- **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.
2021-01-29 06:31:58 -05:00
### Printable
2021-12-28 11:04:43 -05:00
As the stopwatch implements the printable interface since version 0.3.1 one can call
2021-01-29 06:31:58 -05:00
```cpp
Serial.println(stopwatch);
```
To get output like "115 ms" or "159753 us" including the units.
### Calibration
2022-11-25 14:09:48 -05:00
If processors internal clock are not accurately enough, one can adjust
the two constants in the StopWatch.h file. Use at your own risk.
2021-01-29 06:31:58 -05:00
2021-12-28 11:04:43 -05:00
- **STOPWATCH_SECONDS_DIVIDER** default 1000
- **STOPWATCH_MINUTES_DIVIDER** default 60000
2021-01-29 06:31:58 -05:00
2022-11-25 14:09:48 -05:00
### Obsolete
The use of **value()** is obsolete, use **elapsed()** instead.
2021-01-29 06:31:58 -05:00
## Operation
See examples
2021-12-28 11:04:43 -05:00
## Future
2022-11-25 14:09:48 -05:00
#### must
#### should
2021-12-28 11:04:43 -05:00
- create getters and setters for the calibration constants so they can
changed runtime under program control. Must it be float + round() or uint32_t ?
2022-11-25 14:09:48 -05:00
#### 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()**