Skip to content

Commit 792ea0d

Browse files
committed
0.3.5 HeartBeat
1 parent ba788bd commit 792ea0d

File tree

9 files changed

+108
-27
lines changed

9 files changed

+108
-27
lines changed

libraries/HeartBeat/.arduino-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ compile:
2727
- rpipico
2828
libraries:
2929
- "SRF05"
30+
- "ACS712"

libraries/HeartBeat/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.5] - 2025-01-31
10+
- extended HeartBeatSL code length to 15.
11+
- add example **HeartBeat_ACS712_demo.ino**
12+
- minor edits readme.md
13+
914
## [0.3.4] - 2024-09-09
1015
- Fix #12, add **bool codeCompleted()** to HeartBeatDiag and HeartBeatSL
1116
- update readme.md

libraries/HeartBeat/HeartBeat.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: HeartBeat.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.4
4+
// VERSION: 0.3.5
55
// PURPOSE: Arduino library for HeartBeat with frequency and dutyCycle
66
// DATE: 2019-06-12
77
// URL: https://github.com/RobTillaart/HeartBeat
@@ -103,7 +103,7 @@ uint8_t HeartBeat::getState()
103103
//
104104
void HeartBeat::_setFreqDuty()
105105
{
106-
float time = 10000.0/_frequency;
106+
float time = 10000.0 / _frequency;
107107
_dutyCycleHigh = round(_dutyCycle * time);
108108
_dutyCycleLow = round((100 - _dutyCycle) * time);
109109
}
@@ -216,7 +216,7 @@ void HeartBeatSL::beat()
216216
HeartBeat::beat();
217217
return;
218218
}
219-
// _code mode
219+
// _code mode
220220
if (_codeStart == 0)
221221
{
222222
// force a LOW first.
@@ -259,7 +259,7 @@ bool HeartBeatSL::code(const char * str)
259259
if (_codeMask > 0) return false;
260260
// pattern too long
261261
uint8_t len = strlen(str);
262-
if (len > 7) return false;
262+
if (len > 15) return false;
263263

264264
_code = 0;
265265
_codeMask = 1 << len;

libraries/HeartBeat/HeartBeat.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
//
33
// FILE: HeartBeat.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.4
5+
// VERSION: 0.3.5
66
// PURPOSE: Arduino library for HeartBeat with frequency and dutyCycle
77
// DATE: 2019-06-12
88
// URL: https://github.com/RobTillaart/HeartBeat
99

1010

1111
#include "Arduino.h"
1212

13-
#define HEARTBEAT_LIB_VERSION (F("0.3.4"))
13+
#define HEARTBEAT_LIB_VERSION (F("0.3.5"))
1414

1515

1616
class HeartBeat
@@ -104,8 +104,8 @@ class HeartBeatSL : public HeartBeat
104104
bool codeCompleted(); // pattern has been executed.
105105

106106
protected:
107-
uint8_t _code = 0; // up to 7 bits
108-
uint8_t _codeMask = 0; // to extract the bit value from code
107+
uint16_t _code = 0; // up to 15 bits
108+
uint16_t _codeMask = 0; // to extract the bit value from code
109109
uint8_t _codeStart = 0; // force starting with LOW
110110
uint8_t _pulseLength = 0; // to track length of current pulse
111111
};

libraries/HeartBeat/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2024 Rob Tillaart
3+
Copyright (c) 2019-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/HeartBeat/README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ No heart beat indicates the program is stuck or blocked.
3939

4040
Since version 0.3.0 a derived class **HeartBeatSL** is added which can
4141
send specific diagnostic or error patterns.
42-
A pattern exists of 1 to 7 HIGH pulses separated by a fixed length LOW pulse.
42+
A pattern exists of 1 to 15 HIGH pulses separated by a fixed length LOW pulse.
4343
The length of the HIGH pulses can be coded with characters S and L (short and long).
44-
An example of an SOS pattern is "SLS".
44+
An example of an SOS alike pattern is "SSSLLLSSS".
4545
The unit length of the base pulse is determined by the frequency.
4646

4747
If a pattern is started it cannot be overwritten until it is either ready
@@ -65,7 +65,8 @@ If one wants to repeat a pattern the application has to repeat the call.
6565

6666
To keep patterns recognizable one can exaggerate the difference in length.
6767
121 is harder to differentiate than 131, a rule of thumb is to use multiples
68-
of 3 (1, 3, 6 and 9) as length as it allows 4 length levels.
68+
of 3 (1, 3, 6 and 9) as length as it allows 4 length levels. Or use three
69+
levels (1 5 9) to keep it recognizeable.
6970

7071
Many applications only need 2 lengths, short and long (BIOS alike),
7172
but the interface allows more.
@@ -89,7 +90,6 @@ For more complex patterns, please check my pulsePattern library.
8990
#include "HeartBeat.h"
9091
```
9192

92-
9393
### HeartBeat
9494

9595
The interface of the base **HeartBeat** consists of the following functions:
@@ -98,25 +98,33 @@ The interface of the base **HeartBeat** consists of the following functions:
9898
- **void begin(uint8_t pin, float frequency = 1.0)** to configure the HeartBeat.
9999
The output pin should be unique.
100100
The default frequency is 1.0.
101+
- **void beat()** the worker; this function checks if the HeartBeat is enabled
102+
and the OUTPUT (LED) must be toggled.
103+
It must be called as often as possible to keep a steady pace,
104+
preferably at least 4 times the given frequency.
105+
Not calling **beat()** effectively stops the heartbeat.
106+
107+
108+
### Frequency and duty cycle
109+
101110
- **void setFrequency(float frequency = 1.0)** change the frequency of the pulsing.
102111
The default frequency is 1.0.
103112
Setting the frequency will not enable or disable the HeartBeat.
104113
The frequency must be > 0.001 otherwise it will be constrained to 0.001.
105114
On the upper side values beyond 10 Hz are hard for humans but are allowed.
115+
- **float getFrequency()** returns set frequency (or constrained value).
106116
- **void setDutyCycle(float dutyCycle = 50)** duty cycle in percentage time HIGH.
107117
The default duty cycle = 50 %.
108118
The duty cycle must be between 0.0 and 100.0 %.
109119
A value of 0 will put the heartbeat effectively off.
110-
- **float getFrequency()** returns set frequency (or constrained value).
111120
- **float getDutyCycle()** returns set duty cycle (or constrained value).
121+
122+
123+
### Status
124+
112125
- **void enable()** enables the heart beat.
113126
- **void disable()** disable the heart beat. Will switch the pin to LOW.
114127
- **bool isEnabled()** returns true if the heart beat is enabled (running).
115-
- **void beat()** the worker; this function checks if the HeartBeat is enabled
116-
and the OUTPUT (LED) must be toggled.
117-
It must be called as often as possible to keep a steady pace,
118-
preferably at least 4 times the given frequency.
119-
Not calling **beat()** effectively stops the heartbeat.
120128
- **uint8_t getState()** returns the state of the heartbeat.
121129
Useful for debugging.
122130

@@ -128,7 +136,7 @@ The interface of **HeartBeatSL** adds of the following functions to **HeartBeat*
128136
- **HeartBeatSL()** constructor.
129137
- **bool code(const char \* str)** executes the pattern ONE time.
130138
Repeating the pattern means repeating the call.
131-
The max supported string length is **7** as pattern is stored in a byte.
139+
The max supported string length is **15** as pattern is stored in a byte.
132140
- **void codeOff()** explicitly stops the pattern. Forced stop.
133141
- **bool codeCompleted()** returns true if pattern is executed completely.
134142

@@ -150,7 +158,10 @@ void setup()
150158
void loop()
151159
{
152160
HB.beat();
153-
if (some_error) HB.code("LSSLSL"); // ==> L HHHHHH L H L H L HHH
161+
if (some_error)
162+
{
163+
HB.code("LSSLSL"); // ==> L HHHHHH L H L H L HHHHHH L H L HHH
164+
}
154165

155166
// other code here
156167
}
@@ -167,7 +178,6 @@ void someOtherfunction()
167178
Note: a code will be executed, even if the HB is disabled.
168179

169180

170-
171181
### HeartBeatDiag
172182

173183
The interface of **HeartBeatDiag** adds of the following functions:
@@ -242,18 +252,18 @@ See examples
242252
#### Should
243253

244254
- add examples
245-
- ACS712 current sensor
246255
- buffer % filled (e.g. stream)
247256

248257
#### Could
249258

259+
- HBSL: add R at the end for repeat?
250260
- investigate a pattern recognizer (fun)
251261
- e.g. with an LDR or lux sensor.
252-
- HeartBeatSL
253-
- extend code length to 16 (bit)?
262+
- send Morse characters?
254263

255264
#### Wont
256265

266+
- add **setColor(r, g, b)** for 8 colour RGBheartbeat (no PWM)
257267

258268
## Support
259269

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// FILE: HeartBeat_ACS712_demo.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: demo distance sensor
5+
// URL: https://github.com/RobTillaart/HeartBeat
6+
// https://github.com/RobTillaart/ACS712
7+
8+
9+
// HEARTBEAT
10+
#include "HeartBeat.h"
11+
const int buzzer = 13; // also build in LED UNO
12+
HeartBeat HB;
13+
14+
15+
// CURRENT SENSOR
16+
// Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
17+
// ACS712 5A uses 185 mV per A
18+
// ACS712 20A uses 100 mV per A
19+
// ACS712 30A uses 66 mV per A
20+
#include "ACS712.h"
21+
ACS712 ACS(A0, 5.0, 1023, 100); // analog pin, maxV, maxADC, mV/A
22+
23+
24+
uint32_t lastTime = 0;
25+
26+
27+
void setup()
28+
{
29+
while (!Serial);
30+
Serial.begin(115200);
31+
Serial.println(__FILE__);
32+
Serial.print("HEARTBEAT_LIB_VERSION: ");
33+
Serial.println(HEARTBEAT_LIB_VERSION);
34+
Serial.print(" ACS712_LIB_VERSION: ");
35+
Serial.println(ACS712_LIB_VERSION);
36+
Serial.println();
37+
38+
HB.begin(buzzer, 0.1); // very low frequency
39+
HB.setDutyCycle(10); // short pulses
40+
41+
ACS.autoMidPoint();
42+
}
43+
44+
45+
void loop()
46+
{
47+
HB.beat();
48+
49+
int mA = ACS.mA_DC(); // Direct Current
50+
// int mA = ACS.mA_AC(); // Alternating Current
51+
Serial.println(mA); // print e.g. for plotter.
52+
53+
if (millis() - lastTime > 250) // update 4 times per second
54+
{
55+
lastTime = millis();
56+
// map 0..20000 mA ==> 0..20 Hz
57+
float freq = mA * 0.001;
58+
HB.setFrequency(freq);
59+
}
60+
61+
delay(10);
62+
}
63+
64+
65+
// -- END OF FILE --

libraries/HeartBeat/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/HeartBeat.git"
1717
},
18-
"version": "0.3.4",
18+
"version": "0.3.5",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/HeartBeat/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=HeartBeat
2-
version=0.3.4
2+
version=0.3.5
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for HeartBeat with frequency and duty cycle.

0 commit comments

Comments
 (0)