Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# BasedOnStyle: Chromium
---
Language: Cpp
AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: false
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: false
BeforeCatch: true
BeforeElse: false
ColumnLimit: 85
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ContinuationIndentWidth: 2 # Same as TabWidth
DerivePointerAlignment: true
IndentAccessModifiers: true
IndentCaseLabels: false
IndentPPDirectives: BeforeHash
IndentWidth: 2 # Same as TabWidth
MaxEmptyLinesToKeep: 2
PenaltyExcessCharacter: 2
PointerAlignment: Right
ReferenceAlignment: Left
ReflowComments: IndentOnly
SkipMacroDefinitionBody: true
SortIncludes: Never
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpacesBeforeTrailingComments: 2
TabWidth: 2
UseTab: Never
33 changes: 14 additions & 19 deletions examples/GettingStartedProject/GettingStartedProject.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,33 @@


// Variables
int PulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED = LED_BUILTIN; // The on-board Arduion LED
int PulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED = LED_BUILTIN; // The on-board Arduion LED


int Signal; // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 580; // Determine which Signal to "count as a beat", and which to ingore.
int Signal; // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 580; // Determine which Signal to "count as a beat", and which to ingore.


// The SetUp Function:
void setup() {
pinMode(LED,OUTPUT); // pin that will blink to your heartbeat!
Serial.begin(115200); // Set's up Serial Communication at certain speed.

pinMode(LED, OUTPUT); // pin that will blink to your heartbeat!
Serial.begin(115200); // Set's up Serial Communication at certain speed.
}

// The Main Loop Function
void loop() {

Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's value.
// Assign this value to the "Signal" variable.

Serial.println("Signal " + String(Signal)); // Send "reading " followed by the Signal value to Serial Plotter.


if(Signal > Threshold){ // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
digitalWrite(LED,HIGH);
} else {
digitalWrite(LED,LOW); // Else, the sigal must be below "550", so "turn-off" this LED.
}

// Assign this value to the "Signal" variable.

delay(20);
Serial.println("Signal " + String(Signal)); // Send "reading " followed by the Signal value to Serial Plotter.

if (Signal > Threshold) { // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW); // Else, the sigal must be below "550", so "turn-off" this LED.
}

delay(20);
}
53 changes: 24 additions & 29 deletions examples/Getting_BPM_to_Monitor/Getting_BPM_to_Monitor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,44 @@
4) Blinks the builtin LED with user's Heartbeat.
--------------------------------------------------------------------*/

#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.

// Variables
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED = LED_BUILTIN; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore.
// Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default "550" value.
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED = LED_BUILTIN; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore.
// Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default "550" value.

PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"


void setup() {
void setup() {

Serial.begin(115200); // For Serial Monitor
Serial.begin(115200); // For Serial Monitor

// Configure the PulseSensor object, by assigning our variables to it.
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED); //auto-magically blink Arduino's LED with heartbeat.
pulseSensor.setThreshold(Threshold);
// Configure the PulseSensor object, by assigning our variables to it.
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED); // auto-magically blink Arduino's LED with heartbeat.
pulseSensor.setThreshold(Threshold);

// Double-check the "pulseSensor" object was created and "began" seeing a signal.
if (pulseSensor.begin()) {
Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset.
// Double-check the "pulseSensor" object was created and "began" seeing a signal.
if (pulseSensor.begin()) {
Serial.println("We created a pulseSensor Object !"); // This prints one time at Arduino power-up, or on Arduino reset.
}
}



void loop() {



if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
// "myBPM" hold this BPM value now.
Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
Serial.print("BPM: "); // Print phrase "BPM: "
Serial.println(myBPM); // Print the value inside of myBPM.
}

delay(20); // considered best practice in a simple sketch.
if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
// "myBPM" hold this BPM value now.
Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
Serial.print("BPM: "); // Print phrase "BPM: "
Serial.println(myBPM); // Print the value inside of myBPM.
}

delay(20); // considered best practice in a simple sketch.
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@
getPulseAmplitude()
getLastBeatTime()
All other functionality is implicitly tested by successfully running the program.


Check out the PulseSensor Playground Tools for explaination
of all user functions and directives.
https://github.com/WorldFamousElectronics/PulseSensorPlayground/blob/master/resources/PulseSensor%20Playground%20Tools.md

Check out the PulseSensor Playground Tools for explaination
of all user functions and directives.
https://github.com/WorldFamousElectronics/PulseSensorPlayground/blob/master/resources/PulseSensor%20Playground%20Tools.md
Copyright World Famous Electronics LLC - see LICENSE
Contributors:
Joel Murphy, https://pulsesensor.com
Yury Gitman, https://pulsesensor.com
Bradford Needham, @bneedhamia, https://bluepapertech.com

Copyright World Famous Electronics LLC - see LICENSE
Contributors:
Joel Murphy, https://pulsesensor.com
Yury Gitman, https://pulsesensor.com
Bradford Needham, @bneedhamia, https://bluepapertech.com
Licensed under the MIT License, a copy of which
should have been included with this software.

Licensed under the MIT License, a copy of which
should have been included with this software.

This software is not intended for medical use.
*/

/*
Test notes here
This software is not intended for medical use.
*/

#include <PulseSensorPlayground.h>
Expand All @@ -41,8 +35,8 @@
unsigned long thisTime;
bool testing = false;
bool normal = false;
uint8_t errorCode = 0x00; // maybe used for anything automatic?
int testBPM, testIBI, testAmp, testLastBeatTime; // test variables
uint8_t errorCode = 0x00; // maybe used for anything automatic?
int testBPM, testIBI, testAmp, testLastBeatTime; // test variables
int beatCounter;
int firstBeatTime, lastBeatTime, firstToLastBeatTime;

Expand All @@ -51,7 +45,7 @@ const int OUTPUT_TYPE = SERIAL_PLOTTER;
const int PULSE_INPUT = A0;
const int PULSE_BLINK = LED_BUILTIN;
const int PULSE_FADE = 5;
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle

PulseSensorPlayground pulseSensor;

Expand All @@ -69,56 +63,58 @@ void setup() {
// Now that everything is ready, start reading the PulseSensor signal.
if (!pulseSensor.begin()) {
/*
PulseSensor initialization failed,
likely because our particular Arduino platform interrupts
aren't supported yet.
PulseSensor initialization failed,
likely because our particular Arduino platform interrupts
aren't supported yet.

If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
which doesn't use interrupts.
If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
which doesn't use interrupts.
*/
for(;;) {
for (;;) {
// Flash the led to show things didn't work.
digitalWrite(PULSE_BLINK, LOW);
delay(50); Serial.println('!');
delay(50);
Serial.println('!');
digitalWrite(PULSE_BLINK, HIGH);
delay(50);
}
}
pulseSensor.pause();
delay(100);
printInstructions();

}

void loop() {
if(testing){
if (testing) {
runTest(millis());
}
if(normal){
if (normal) {
runNormal();
}
checkSerial();
} // loop
} // loop


/*
Receives millis() and runs a test for TEST_DURATION
Receives millis() and runs a test for TEST_DURATION
*/
void runTest(unsigned long startTime){
void runTest(unsigned long startTime) {
beatCounter = 0; // reset the beat counter
testIBI = 0;
testBPM = 0;
testAmp = 0;
firstBeatTime = -1;
lastBeatTime = -1;
Serial.println("\n\tSTART TEST");
pulseSensor.resume(); // start the sensing!
while((millis() - startTime) < TEST_DURATION){
Serial.println(pulseSensor.getLatestSample()); // print raw data for plotter or monitor review
if(pulseSensor.sawStartOfBeat()){
pulseSensor.resume(); // start the sensing!
while ((millis() - startTime) < TEST_DURATION) {
Serial.println(pulseSensor.getLatestSample()); // print raw data for plotter or monitor review
if (pulseSensor.sawStartOfBeat()) {
beatCounter++;
if(firstBeatTime < 0){ firstBeatTime = pulseSensor.getLastBeatTime(); }
testBPM += pulseSensor.getBeatsPerMinute();
if (firstBeatTime < 0) {
firstBeatTime = pulseSensor.getLastBeatTime();
}
testBPM += pulseSensor.getBeatsPerMinute();
testIBI += pulseSensor.getInterBeatIntervalMs();
testAmp += pulseSensor.getPulseAmplitude();
}
Expand All @@ -135,11 +131,11 @@ void runTest(unsigned long startTime){
printInstructions();
testing = false;
}


void runNormal(){
if(pulseSensor.UsingHardwareTimer){
delay(20);

void runNormal() {
if (pulseSensor.UsingHardwareTimer) {
delay(20);
pulseSensor.outputSample();
} else {
if (pulseSensor.sawNewSample()) {
Expand All @@ -152,4 +148,4 @@ void runNormal(){
if (pulseSensor.sawStartOfBeat()) {
pulseSensor.outputBeat();
}
}
}
32 changes: 17 additions & 15 deletions examples/PulseSensorLIbrary_V2_System_Test/serialStuff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

*/

void checkSerial(){
if(Serial.available()){
void checkSerial() {
if (Serial.available()) {
char inChar = Serial.read();
switch(inChar){
switch (inChar) {
case 't':
testing = true;
break;
Expand All @@ -19,29 +19,31 @@ void checkSerial(){
printInstructions();
break;
default:
Serial.print("i got "); Serial.println(inChar);
Serial.print("I got ");
Serial.println(inChar);
}
} // Serial.available
} // checkSerial
} // Serial.available
} // checkSerial


void printResults(){
float durationOfBeats = float(firstToLastBeatTime/1000.0);
Serial.println("\tTEST COMPLETE");
void printResults() {
float durationOfBeats = float(firstToLastBeatTime / 1000.0);
Serial.println("\tTEST COMPLETE");
Serial.print("\tAverage BPM: "); Serial.println(testBPM);
Serial.print("\tAverage IBI: "); Serial.println(testIBI);
Serial.print("\tAverage Pulse Amplitude: "); Serial.println(testAmp);
Serial.print("\tFirst to last heartbeat time: "); Serial.print(durationOfBeats,3); Serial.println(" Seconds");
Serial.print("\tFirst to last heartbeat time: "); Serial.print(durationOfBeats, 3); Serial.println(" Seconds");
Serial.print("\tPlayground Library is using a ");
if(pulseSensor.UsingHardwareTimer){
if (pulseSensor.UsingHardwareTimer) {
Serial.println("hardware timer");
} else {
Serial.println("software timer");
}
}

void printInstructions(){
Serial.print("\nPulseSensor Playground "); Serial.println(PULSESENSOR_PLAYGROUND_VERSION_STRING);
void printInstructions() {
Serial.print("\nPulseSensor Playground ");
Serial.println(PULSESENSOR_PLAYGROUND_VERSION_STRING);
Serial.println("Full System Test Instructions:");
Serial.println("\n\t1) Connect PulseSensor wires to the board under test");
Serial.println("\t2) Use a known good signal source to connect PulseSensor to");
Expand All @@ -52,11 +54,11 @@ void printInstructions(){
Serial.println("\nSend 'r' to run the pulseSensor with normal output");
Serial.println("Send 'p' to pause normal output, and print this message");
Serial.print("PulseSensor is currently ");
if(pulseSensor.isPaused()){
if (pulseSensor.isPaused()) {
Serial.println("paused");
} else {
Serial.println("running!");
}
// Serial.println("");
// Serial.println("");
}
}
Loading