2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/HeartBeat/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
2021-11-02 17:26:51 +01:00
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/HeartBeat/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/HeartBeat/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/HeartBeat/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/HeartBeat/actions/workflows/jsoncheck.yml)
|
2021-01-29 12:31:58 +01:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/HeartBeat/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/HeartBeat.svg?maxAge=3600)](https://github.com/RobTillaart/HeartBeat/releases)
|
|
|
|
|
|
|
|
|
|
|
|
# HeartBeat
|
|
|
|
|
2021-11-02 17:26:51 +01:00
|
|
|
Arduino library for a HeartBeat with frequency and duty cycle.
|
2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2021-11-02 17:26:51 +01:00
|
|
|
The heartbeat library offers a simple HeartBeat by sending pulses to
|
|
|
|
a digital pin. Typical usage is to blink a (built in) LED as indicator
|
2021-01-29 12:31:58 +01:00
|
|
|
a program is still alive.
|
|
|
|
|
|
|
|
The library uses no hardware timer and is based upon micros() so the user
|
|
|
|
is responsible to call the **beat()** function as often as needed or
|
|
|
|
better even more.
|
|
|
|
|
|
|
|
The library allows to set the frequency runtime, so the HeartBeat
|
|
|
|
can be used as a first level debugging tool. Different frequencies can indicate
|
|
|
|
a different state of the program or a different level of some sensor.
|
|
|
|
No heart beat indicates the program is stuck or blocked.
|
|
|
|
|
|
|
|
For more complex patterns, please check my pulsePattern library.
|
|
|
|
|
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
2021-11-02 17:26:51 +01:00
|
|
|
The interface consists of the following functions:
|
2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
- **HeartBeat()** constructor
|
2021-11-02 17:26:51 +01:00
|
|
|
- **void begin(uint8_t pin, float frequency)** to configure the HeartBeat.
|
2021-01-29 12:31:58 +01:00
|
|
|
The default frequency is 1.0
|
2021-11-02 17:26:51 +01:00
|
|
|
- **void setFrequency(float frequency)** change the frequency of the pulsing.
|
|
|
|
Will not enable or disable the HeartBeat.
|
|
|
|
Must be > 0.001 otherwise it will be constrained to 0.001.
|
|
|
|
On the upper side values beyond 10 Hz are hard for humans but are allowed.
|
|
|
|
- **void setDutyCycle(float dutyCycle = 50)** duty cycle in percentage time HIGH.
|
|
|
|
Must be between 0.00 and 100.0. A value of 0 will put the heartbeat effectively off.
|
|
|
|
- **float getFrequency()** returns set frequency (or constrained value).
|
|
|
|
- **float getDutyCycle()** returns set duty cycle (or constrained value).
|
|
|
|
- **void enable()** enable the pulsing.
|
|
|
|
- **void disable()** disable the pulsing; will switch of the LED.
|
|
|
|
- **void beat()** the worker; this function checks if the HeartBeat is enabled
|
2021-01-29 12:31:58 +01:00
|
|
|
and the LED must be toggled.
|
|
|
|
It must be called as often as possible to keep a steady pace,
|
|
|
|
at least 4 times the given frequency.
|
2021-11-02 17:26:51 +01:00
|
|
|
Not calling **beat()** effectively stops the heartbeat.
|
|
|
|
- **uint8_t getState()** returns the state of the heartbeat.
|
|
|
|
Useful for debugging.
|
2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
#### Obsolete
|
|
|
|
|
2021-11-02 17:26:51 +01:00
|
|
|
- **set(float freq)** is replaced by **setFrequency()**.
|
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
## Applications
|
|
|
|
|
|
|
|
Applications include but are not limited to
|
|
|
|
- show an alive sign, typical freq of 1 Hz is sufficient.
|
|
|
|
- show error code by means of different frequencies.
|
|
|
|
- 1 Hz = OK
|
|
|
|
- 2 Hz = Warning
|
|
|
|
- 5 Hz = Error
|
2021-11-02 17:26:51 +01:00
|
|
|
- no signal would indicate also an error.
|
|
|
|
- indicate power e.g. round(amps) - you might need to map the range!
|
|
|
|
- indicate the volume by increasing heartBeat
|
|
|
|
- indicate a changing distant - increasing or decreasing.
|
|
|
|
- Geiger counter style.
|
2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Operation
|
|
|
|
|
|
|
|
See examples
|
|
|
|
|
2021-11-02 17:26:51 +01:00
|
|
|
|
|
|
|
## Future
|
|
|
|
|
|
|
|
- differentiate between ON / OFF time
|
|
|
|
- improve documentation
|
|
|
|
- add examples
|
|
|
|
-
|
|
|
|
|