Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EFM32_SegmentLCD Si114x mbed
Revision 1:b2b2924c3c48, committed 2015-08-25
- Comitter:
- Sissors
- Date:
- Tue Aug 25 19:30:13 2015 +0000
- Parent:
- 0:f3705ec14cf0
- Commit message:
- Improved heartbeat algorithmes.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Aug 23 17:00:09 2015 +0000
+++ b/main.cpp Tue Aug 25 19:30:13 2015 +0000
@@ -46,6 +46,8 @@
int sum;
int prevtime = 0;
int timesincelast;
+ float abssum;
+ float abssum_iir = 0.0f;
Timer timey;
timey.start();
@@ -58,8 +60,14 @@
mvingavg[0] = curval - prevval;
sum = mvingavg[2] + mvingavg[1] + mvingavg[0];
- //Magic number for minimum threshold before it sees something as a heartbeat, adjust if my fingers are special :)
- if (sum < -50) {
+ //Float val for abs(sum) to calculate threshold dynamically
+ abssum = (float)abs(sum);
+ abssum_iir = abssum_iir * 0.99f + abssum * 0.01f;
+
+ //Now we know the 'average' absolute 'noise' ( plus some part of the heartbeat)
+ //We multiply this by four (yes randomly chosen) and use it as threshold for heartbeat
+ //Possibly this is too much if you are really excited, but haven't been excited enough to check this
+ if (sum < (int)(-4.0f * abssum_iir)) {
segmentDisplay.Battery(4);
timesincelast = timey.read_ms() - prevtime;
if (timesincelast > 250) {