Skip to content

Commit 61632e8

Browse files
authored
Merge pull request #191 from WorldFamousElectronics/Version-2.0-Beta
Version 2.0.0
2 parents 996839a + 6835f94 commit 61632e8

File tree

38 files changed

+1651
-2394
lines changed

38 files changed

+1651
-2394
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.cfg
22
*.json
33
*.svd
4+
*.zip
5+
*.DS_Store

LICENSE

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

3-
Copyright (c) 2015-2017 World Famous Electroncs LLC, Brooklyn, New York.
3+
Copyright (c) 2015-2024 World Famous Electroncs LLC, Brooklyn, New York.
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

README-archive-3-2018.md

Lines changed: 0 additions & 159 deletions
This file was deleted.

Version 2.0 Beta Read Me.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This branch is for development and testing of PulseSensor Playground Library v2.0
2+
3+
High-level goals for v2.0:
4+
5+
- Remove user requirement for defining USE ARDUINO INTERRUPTS
6+
7+
Files effected:
8+
9+
- All example sketches will need to accomodate changes
10+
- Interrupts.h will be superceded
11+
- PulseSensorPlayground.h and PulseSensorPlayground.cpp will need to accomodate changes
12+
- All comments in all files will be reviewed and editied to reflect paradigm shift
13+
14+
15+
Notes 12/6/23
16+
It works!
17+
The file SelectTimer.h contains the most up to date hardware architecture that
18+
has hardware timer interrupt support.
19+
20+
## TO DO:
21+
22+
- Make adjustments to example sketches to accomodate library decisions
23+
- Make a program PulseSensorFullSystem.ino to make hardware testing easy
24+
- Test ATtiny85 using Digispark board
25+
26+
27+
28+
29+
30+

examples/Getting_BPM_to_Monitor/Getting_BPM_to_Monitor.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
4) Blinks the builtin LED with user's Heartbeat.
1010
--------------------------------------------------------------------*/
1111

12-
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
1312
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
1413

1514
// Variables
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
This example will test functionality of PulseSensor user functions.
3+
Program any hardware with this sketch and open a serial port
4+
to view the test instructions, operation and results.
5+
Functionality that is explicity tested by the program:
6+
pause()
7+
resume()
8+
getInterBeatIntervalMs()
9+
getBeatsPerMinute()
10+
getLatestSample()
11+
getPulseAmplitude()
12+
getLastBeatTime()
13+
All other functionality is implicitly tested by successfully running the program.
14+
15+
16+
17+
Check out the PulseSensor Playground Tools for explaination
18+
of all user functions and directives.
19+
https://github.com/WorldFamousElectronics/PulseSensorPlayground/blob/master/resources/PulseSensor%20Playground%20Tools.md
20+
21+
Copyright World Famous Electronics LLC - see LICENSE
22+
Contributors:
23+
Joel Murphy, https://pulsesensor.com
24+
Yury Gitman, https://pulsesensor.com
25+
Bradford Needham, @bneedhamia, https://bluepapertech.com
26+
27+
Licensed under the MIT License, a copy of which
28+
should have been included with this software.
29+
30+
This software is not intended for medical use.
31+
*/
32+
33+
/*
34+
Test notes here
35+
*/
36+
37+
#include <PulseSensorPlayground.h>
38+
39+
// Test variables
40+
#define TEST_DURATION 10000 // run time in milliseconds
41+
unsigned long thisTime;
42+
bool testing = false;
43+
bool normal = false;
44+
uint8_t errorCode = 0x00; // maybe used for anything automatic?
45+
int testBPM, testIBI, testAmp, testLastBeatTime; // test variables
46+
int beatCounter;
47+
int firstBeatTime, lastBeatTime, firstToLastBeatTime;
48+
49+
// Standard PulseSensor Stuff
50+
const int OUTPUT_TYPE = SERIAL_PLOTTER;
51+
const int PULSE_INPUT = A0;
52+
const int PULSE_BLINK = LED_BUILTIN;
53+
const int PULSE_FADE = 5;
54+
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
55+
56+
PulseSensorPlayground pulseSensor;
57+
58+
void setup() {
59+
60+
Serial.begin(115200);
61+
pulseSensor.analogInput(PULSE_INPUT);
62+
pulseSensor.blinkOnPulse(PULSE_BLINK);
63+
pulseSensor.fadeOnPulse(PULSE_FADE);
64+
65+
pulseSensor.setSerial(Serial);
66+
pulseSensor.setOutputType(OUTPUT_TYPE);
67+
pulseSensor.setThreshold(THRESHOLD);
68+
69+
// Now that everything is ready, start reading the PulseSensor signal.
70+
if (!pulseSensor.begin()) {
71+
/*
72+
PulseSensor initialization failed,
73+
likely because our particular Arduino platform interrupts
74+
aren't supported yet.
75+
76+
If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
77+
which doesn't use interrupts.
78+
*/
79+
for(;;) {
80+
// Flash the led to show things didn't work.
81+
digitalWrite(PULSE_BLINK, LOW);
82+
delay(50); Serial.println('!');
83+
digitalWrite(PULSE_BLINK, HIGH);
84+
delay(50);
85+
}
86+
}
87+
pulseSensor.pause();
88+
delay(100);
89+
printInstructions();
90+
91+
}
92+
93+
void loop() {
94+
if(testing){
95+
runTest(millis());
96+
}
97+
if(normal){
98+
runNormal();
99+
}
100+
checkSerial();
101+
} // loop
102+
103+
104+
/*
105+
Receives millis() and runs a test for TEST_DURATION
106+
*/
107+
void runTest(unsigned long startTime){
108+
beatCounter = 0; // reset the beat counter
109+
testIBI = 0;
110+
testBPM = 0;
111+
testAmp = 0;
112+
firstBeatTime = -1;
113+
lastBeatTime = -1;
114+
Serial.println("\n\tSTART TEST");
115+
pulseSensor.resume(); // start the sensing!
116+
while((millis() - startTime) < TEST_DURATION){
117+
Serial.println(pulseSensor.getLatestSample()); // print raw data for plotter or monitor review
118+
if(pulseSensor.sawStartOfBeat()){
119+
beatCounter++;
120+
if(firstBeatTime < 0){ firstBeatTime = pulseSensor.getLastBeatTime(); }
121+
testBPM += pulseSensor.getBeatsPerMinute();
122+
testIBI += pulseSensor.getInterBeatIntervalMs();
123+
testAmp += pulseSensor.getPulseAmplitude();
124+
}
125+
delay(20);
126+
}
127+
lastBeatTime = pulseSensor.getLastBeatTime();
128+
pulseSensor.pause();
129+
testBPM /= beatCounter;
130+
testIBI /= beatCounter;
131+
testAmp /= beatCounter;
132+
firstToLastBeatTime = lastBeatTime - firstBeatTime;
133+
134+
printResults();
135+
printInstructions();
136+
testing = false;
137+
}
138+
139+
140+
void runNormal(){
141+
if(pulseSensor.UsingHardwareTimer){
142+
delay(20);
143+
pulseSensor.outputSample();
144+
} else {
145+
if (pulseSensor.sawNewSample()) {
146+
if (--pulseSensor.samplesUntilReport == (byte) 0) {
147+
pulseSensor.samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
148+
pulseSensor.outputSample();
149+
}
150+
}
151+
}
152+
if (pulseSensor.sawStartOfBeat()) {
153+
pulseSensor.outputBeat();
154+
}
155+
}

0 commit comments

Comments
 (0)