初始化提交
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
|
||||
/* PulseSensor Starter Project and Signal Tester
|
||||
* The Best Way to Get Started With, or See the Raw Signal of, your PulseSensor.com™ & Arduino.
|
||||
*
|
||||
* Here is a link to the tutorial
|
||||
* https://pulsesensor.com/pages/code-and-guide
|
||||
*
|
||||
* WATCH ME (Tutorial Video):
|
||||
* https://www.youtube.com/watch?v=RbB8NSRa5X4
|
||||
*
|
||||
*
|
||||
-------------------------------------------------------------
|
||||
1) This shows a live human Heartbeat Pulse.
|
||||
2) Live visualization in Arduino's Cool "Serial Plotter".
|
||||
3) Blink an LED on each Heartbeat.
|
||||
4) This is the direct Pulse Sensor's Signal.
|
||||
5) A great first-step in troubleshooting your circuit and connections.
|
||||
6) "Human-readable" code that is newbie friendly."
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// Variables
|
||||
int PulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
|
||||
int LED13 = 13; // The on-board Arduion LED
|
||||
|
||||
|
||||
int Signal; // holds the incoming raw data. Signal value can range from 0-1024
|
||||
int Threshold = 550; // Determine which Signal to "count as a beat", and which to ingore.
|
||||
|
||||
|
||||
// The SetUp Function:
|
||||
void setup() {
|
||||
pinMode(LED13,OUTPUT); // pin that will blink to your heartbeat!
|
||||
Serial.begin(9600); // 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); // Send the Signal value to Serial Plotter.
|
||||
|
||||
|
||||
if(Signal > Threshold){ // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
|
||||
digitalWrite(LED13,HIGH);
|
||||
} else {
|
||||
digitalWrite(LED13,LOW); // Else, the sigal must be below "550", so "turn-off" this LED.
|
||||
}
|
||||
|
||||
|
||||
delay(10);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
/* Getting_BPM_to_Monitor prints the BPM to the Serial Monitor, using the least lines of code and PulseSensor Library.
|
||||
* Tutorial Webpage: https://pulsesensor.com/pages/getting-advanced
|
||||
*
|
||||
--------Use This Sketch To------------------------------------------
|
||||
1) Displays user's live and changing BPM, Beats Per Minute, in Arduino's native Serial Monitor.
|
||||
2) Print: "♥ A HeartBeat Happened !" when a beat is detected, live.
|
||||
2) Learn about using a PulseSensor Library "Object".
|
||||
4) Blinks LED on PIN 13 with user's Heartbeat.
|
||||
--------------------------------------------------------------------*/
|
||||
|
||||
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
|
||||
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
|
||||
|
||||
// Variables
|
||||
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
|
||||
const int LED13 = 13; // 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() {
|
||||
|
||||
Serial.begin(9600); // For Serial Monitor
|
||||
|
||||
// Configure the PulseSensor object, by assigning our variables to it.
|
||||
pulseSensor.analogInput(PulseWire);
|
||||
pulseSensor.blinkOnPulse(LED13); //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.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
|
||||
// "myBPM" hold this BPM value now.
|
||||
|
||||
if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
|
||||
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.
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
Code to detect pulses from the PulseSensor,
|
||||
using an interrupt service routine.
|
||||
|
||||
Here is a link to the tutorial\
|
||||
https://pulsesensor.com/pages/ATtiny
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
|
||||
interrupts to automatically read and process PulseSensor data.
|
||||
|
||||
See ProcessEverySample.ino for an example of not using interrupts.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
#include <PulseSensorPlayground.h>
|
||||
#include <SoftwareSerial.h>
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = PROCESSING_VISUALIZER;
|
||||
|
||||
/*
|
||||
Pinout:
|
||||
PULSE_INPUT = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
|
||||
that will flash on each detected pulse.
|
||||
PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
|
||||
that will smoothly fade with each pulse.
|
||||
NOTE: PULSE_FADE must be a pin that supports PWM. Do not use
|
||||
pin 9 or 10, because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT = A1;
|
||||
const int PULSE_BLINK = 1; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 0;
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
const int TX_PIN = 3; // Using software serial
|
||||
const int RX_PIN = 4;
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor;
|
||||
SoftwareSerial pulseUART(TX_PIN,RX_PIN);
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 115200 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 11 bytes per millisecond.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
pulseUART.begin(115200);
|
||||
|
||||
// Configure the PulseSensor manager.
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
|
||||
pulseSensor.setSerial(pulseUART);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// 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.
|
||||
|
||||
If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
|
||||
which doesn't use interrupts.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/*
|
||||
Wait a bit.
|
||||
We don't output every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
delay(20);
|
||||
|
||||
// write the latest sample to Serial.
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
If a beat has happened since we last checked,
|
||||
write the per-beat information to Serial.
|
||||
*/
|
||||
if (pulseSensor.sawStartOfBeat()) {
|
||||
pulseSensor.outputBeat();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Code to detect pulses from the PulseSensor,
|
||||
using an interrupt service routine.
|
||||
|
||||
Here is a link to the tutorial\
|
||||
https://pulsesensor.com/pages/ATtiny
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
|
||||
interrupts to automatically read and process PulseSensor data.
|
||||
|
||||
See ProcessEverySample.ino for an example of not using interrupts.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
/*
|
||||
Pinout:
|
||||
PULSE_INPUT = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
|
||||
that will flash on each detected pulse.
|
||||
PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
|
||||
that will smoothly fade with each pulse.
|
||||
NOTE: PULSE_FADE must be a pin that supports PWM. Do not use
|
||||
pin 9 or 10, because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT = A1;
|
||||
const int PULSE_BLINK = 1; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 0;
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor;
|
||||
|
||||
void setup() {
|
||||
// Configure the PulseSensor manager.
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// 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.
|
||||
|
||||
If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
|
||||
which doesn't use interrupts.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/*
|
||||
When we're not outputting serial messages
|
||||
there's not much to do here.
|
||||
In case you want to add more behavior to the sketch
|
||||
you can use sawStartOfBeat() or isInsideBeat()
|
||||
to have the sketch do stuff when there's a beat.
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Code to detect pulses from the PulseSensor,
|
||||
using an interrupt service routine.
|
||||
|
||||
Here is a link to the tutorial\
|
||||
https://pulsesensor.com/pages/getting-advanced
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
|
||||
interrupts to automatically read and process PulseSensor data.
|
||||
|
||||
See ProcessEverySample.ino for an example of not using interrupts.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
Pinout:
|
||||
PULSE_INPUT = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
|
||||
that will flash on each detected pulse.
|
||||
PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
|
||||
that will smoothly fade with each pulse.
|
||||
NOTE: PULSE_FADE must be a pin that supports PWM. Do not use
|
||||
pin 9 or 10, because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT = A0;
|
||||
const int PULSE_BLINK = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 5;
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor;
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 115200 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 11 bytes per millisecond.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial.begin(115200);
|
||||
|
||||
// Configure the PulseSensor manager.
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
|
||||
pulseSensor.setSerial(Serial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// 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.
|
||||
|
||||
If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
|
||||
which doesn't use interrupts.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/*
|
||||
Wait a bit.
|
||||
We don't output every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
delay(20);
|
||||
|
||||
// write the latest sample to Serial.
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
If a beat has happened since we last checked,
|
||||
write the per-beat information to Serial.
|
||||
*/
|
||||
if (pulseSensor.sawStartOfBeat()) {
|
||||
pulseSensor.outputBeat();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
Sketch to handle each sample read from a PulseSensor.
|
||||
Typically used when you don't want to use interrupts
|
||||
to read PulseSensor voltages.
|
||||
|
||||
Here is a link to the tutorial that discusses this code
|
||||
https://pulsesensor.com/pages/getting-advanced
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS false tells the library to
|
||||
not use interrupts to read data from the PulseSensor.
|
||||
|
||||
If you want to use interrupts, simply change the line below
|
||||
to read:
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
|
||||
Set US_PS_INTERRUPTS to false if either
|
||||
1) Your Arduino platform's interrupts aren't yet supported
|
||||
by PulseSensor Playground, or
|
||||
2) You don't wish to use interrupts because of the side effects.
|
||||
|
||||
NOTE: if US_PS_INTERRUPTS is false, your Sketch must
|
||||
call pulse.sawNewSample() at least once every 2 milliseconds
|
||||
to accurately read the PulseSensor signal.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS false
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
Pinout:
|
||||
PULSE_INPUT = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
|
||||
that will flash on each detected pulse.
|
||||
PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
|
||||
that will smoothly fade with each pulse.
|
||||
NOTE: PULSE_FADE must be a pin that supports PWM.
|
||||
If USE_INTERRUPTS is true, Do not use pin 9 or 10 for PULSE_FADE,
|
||||
because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT = A0;
|
||||
const int PULSE_BLINK = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 5;
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
samplesUntilReport = the number of samples remaining to read
|
||||
until we want to report a sample over the serial connection.
|
||||
|
||||
We want to report a sample value over the serial port
|
||||
only once every 20 milliseconds (10 samples) to avoid
|
||||
doing Serial output faster than the Arduino can send.
|
||||
*/
|
||||
byte samplesUntilReport;
|
||||
const byte SAMPLES_PER_SERIAL_SAMPLE = 10;
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor;
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 115200 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 11 bytes per millisecond.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial.begin(115200);
|
||||
|
||||
// Configure the PulseSensor manager.
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
|
||||
pulseSensor.setSerial(Serial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// Skip the first SAMPLES_PER_SERIAL_SAMPLE in the loop().
|
||||
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
|
||||
|
||||
// Now that everything is ready, start reading the PulseSensor signal.
|
||||
if (!pulseSensor.begin()) {
|
||||
/*
|
||||
PulseSensor initialization failed,
|
||||
likely because our Arduino platform interrupts
|
||||
aren't supported yet.
|
||||
|
||||
If your Sketch hangs here, try changing USE_PS_INTERRUPT to false.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
/*
|
||||
See if a sample is ready from the PulseSensor.
|
||||
|
||||
If USE_INTERRUPTS is true, the PulseSensor Playground
|
||||
will automatically read and process samples from
|
||||
the PulseSensor.
|
||||
|
||||
If USE_INTERRUPTS is false, this call to sawNewSample()
|
||||
will, if enough time has passed, read and process a
|
||||
sample (analog voltage) from the PulseSensor.
|
||||
*/
|
||||
if (pulseSensor.sawNewSample()) {
|
||||
/*
|
||||
Every so often, send the latest Sample.
|
||||
We don't print every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
if (--samplesUntilReport == (byte) 0) {
|
||||
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
|
||||
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
At about the beginning of every heartbeat,
|
||||
report the heart rate and inter-beat-interval.
|
||||
*/
|
||||
if (pulseSensor.sawStartOfBeat()) {
|
||||
pulseSensor.outputBeat();
|
||||
}
|
||||
}
|
||||
|
||||
/*******
|
||||
Here is a good place to add code that could take up
|
||||
to a millisecond or so to run.
|
||||
*******/
|
||||
}
|
||||
|
||||
/******
|
||||
Don't add code here, because it could slow the sampling
|
||||
from the PulseSensor.
|
||||
******/
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
Sketch to handle each sample read from a PulseSensor.
|
||||
Typically used when you don't want to use interrupts
|
||||
to read PulseSensor voltages.
|
||||
|
||||
Here is a link to the tutorial that discusses this code
|
||||
>> Comming Soon! <<
|
||||
|
||||
Use this code as a basic example when targeting STM32 boards.
|
||||
Open your Arduino > Preferences window, and add this to your Additional Boards Manager URLs:
|
||||
|
||||
https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json
|
||||
|
||||
Then, go to Tools > Board > Boards Manager to install the STM32 core.
|
||||
|
||||
This example targets the Nucleo 64 F401RE
|
||||
If you are using a different Nucleo board, you may have to change some of the
|
||||
board parameters. Here are the drop-down selections that I used.
|
||||
|
||||
Board: Nucleo-64
|
||||
Board Part Number: Nucleo F401RE
|
||||
Serial Interface: Enable first third (USART to 3 if available)
|
||||
USB Interace: None
|
||||
Upload Method: STlink
|
||||
Optimize: Smallest (-Os defalut)
|
||||
|
||||
This sketch uses Serial1 to communicate with your computer.
|
||||
Attach an FTDI or other USB > Serial breakout to the pins
|
||||
|
||||
tx: D8 (Arduino Pin)
|
||||
rx: D2 (Arduino Pin)
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS false tells the library to
|
||||
not use interrupts to read data from the PulseSensor.
|
||||
|
||||
If you want to use interrupts, simply change the line below
|
||||
to read:
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
|
||||
Set US_PS_INTERRUPTS to false if either
|
||||
1) Your Arduino platform's interrupts aren't yet supported
|
||||
by PulseSensor Playground, or
|
||||
2) You don't wish to use interrupts because of the side effects.
|
||||
|
||||
NOTE: if US_PS_INTERRUPTS is false, your Sketch must
|
||||
call pulse.sawNewSample() at least once every 2 milliseconds
|
||||
to accurately read the PulseSensor signal.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS false
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
Pinout:
|
||||
PULSE_INPUT = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
|
||||
that will flash on each detected pulse.
|
||||
PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
|
||||
that will smoothly fade with each pulse.
|
||||
NOTE: PULSE_FADE must be a pin that supports PWM.
|
||||
If USE_INTERRUPTS is true, Do not use pin 9 or 10 for PULSE_FADE,
|
||||
because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT = A0;
|
||||
const int PULSE_BLINK = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 5;
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
samplesUntilReport = the number of samples remaining to read
|
||||
until we want to report a sample over the serial connection.
|
||||
|
||||
We want to report a sample value over the serial port
|
||||
only once every 20 milliseconds (10 samples) to avoid
|
||||
doing Serial output faster than the Arduino can send.
|
||||
*/
|
||||
byte samplesUntilReport;
|
||||
const byte SAMPLES_PER_SERIAL_SAMPLE = 10;
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor;
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 115200 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 11 bytes per millisecond.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial1.begin(115200);
|
||||
|
||||
// Configure the PulseSensor manager.
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
|
||||
pulseSensor.setSerial(Serial1);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// Skip the first SAMPLES_PER_SERIAL_SAMPLE in the loop().
|
||||
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
|
||||
|
||||
// Now that everything is ready, start reading the PulseSensor signal.
|
||||
if (!pulseSensor.begin()) {
|
||||
/*
|
||||
PulseSensor initialization failed,
|
||||
likely because our Arduino platform interrupts
|
||||
aren't supported yet.
|
||||
|
||||
If your Sketch hangs here, try changing USE_PS_INTERRUPT to false.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
/*
|
||||
See if a sample is ready from the PulseSensor.
|
||||
|
||||
If USE_INTERRUPTS is true, the PulseSensor Playground
|
||||
will automatically read and process samples from
|
||||
the PulseSensor.
|
||||
|
||||
If USE_INTERRUPTS is false, this call to sawNewSample()
|
||||
will, if enough time has passed, read and process a
|
||||
sample (analog voltage) from the PulseSensor.
|
||||
*/
|
||||
if (pulseSensor.sawNewSample()) {
|
||||
/*
|
||||
Every so often, send the latest Sample.
|
||||
We don't print every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
if (--samplesUntilReport == (byte) 0) {
|
||||
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
|
||||
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
At about the beginning of every heartbeat,
|
||||
report the heart rate and inter-beat-interval.
|
||||
*/
|
||||
if (pulseSensor.sawStartOfBeat()) {
|
||||
pulseSensor.outputBeat();
|
||||
}
|
||||
}
|
||||
|
||||
/*******
|
||||
Here is a good place to add code that could take up
|
||||
to a millisecond or so to run.
|
||||
*******/
|
||||
}
|
||||
|
||||
/******
|
||||
Don't add code here, because it could slow the sampling
|
||||
from the PulseSensor.
|
||||
******/
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Arduino Sketch to detect pulses from two PulseSensors
|
||||
and measures the time between! This can be used to derive
|
||||
Pulse Transit Time (PTT)
|
||||
|
||||
Here is a link to the PTT tutorial
|
||||
https://pulsesensor.com/pages/pulse-transit-time
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS false tells the library to
|
||||
not use interrupts to read data from the PulseSensor.
|
||||
|
||||
If you want to use interrupts, simply change the line below
|
||||
to read:
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
|
||||
Set US_PS_INTERRUPTS to false if either
|
||||
1) Your Arduino platform's interrupts aren't yet supported
|
||||
by PulseSensor Playground, or
|
||||
2) You don't wish to use interrupts because of the side effects.
|
||||
|
||||
NOTE: if US_PS_INTERRUPTS is false, your Sketch must
|
||||
call pulse.sawNewSample() at least once every 2 milliseconds
|
||||
to accurately read the PulseSensor signal.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the multi-sensor Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensorAmped_2_Sensors
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = PROCESSING_VISUALIZER;
|
||||
|
||||
/*
|
||||
Number of PulseSensor devices we're reading from.
|
||||
*/
|
||||
const int PULSE_SENSOR_COUNT = 2;
|
||||
|
||||
/*
|
||||
PULSE_POWERx = the output pin that the red (power) pin of
|
||||
the first PulseSensor will be connected to. PulseSensor only
|
||||
draws about 4mA, so almost any micro can power it from a GPIO.
|
||||
If you don't want to use pins to power the PulseSensors, you can remove
|
||||
the code dealing with PULSE_POWER0 and PULSE_POWER1.
|
||||
PULSE_INPUTx = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINKx = digital Output. Connected to an LED (must have at least
|
||||
470 ohm resistor) that will flash on each detected pulse.
|
||||
PULSE_FADEx = digital Output. PWM pin onnected to an LED (must have
|
||||
at least 470 ohm resistor) that will smoothly fade with each pulse.
|
||||
|
||||
NOTE: PULSE_FADEx must be pins that support PWM.
|
||||
If USE_INTERRUPTS is true, Do not use pin 9 or 10 for PULSE_FADEx
|
||||
because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT0 = A0;
|
||||
const int PULSE_BLINK0 = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE0 = 5;
|
||||
|
||||
const int PULSE_INPUT1 = A1;
|
||||
const int PULSE_BLINK1 = 12;
|
||||
const int PULSE_FADE1 = 11;
|
||||
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
We tell it how many PulseSensors we're using.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor(PULSE_SENSOR_COUNT);
|
||||
|
||||
/*
|
||||
Variables used to determine PTT.
|
||||
NOTE: This code assumes the Pulse Sensor on analog pin 0 is closer to he heart.
|
||||
*/
|
||||
unsigned long lastBeatSampleNumber[PULSE_SENSOR_COUNT];
|
||||
int PTT;
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 250000 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 25 bytes per millisecond,
|
||||
or 50 characters per PulseSensor sample period of 2 milliseconds.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial.begin(250000);
|
||||
|
||||
/*
|
||||
Configure the PulseSensor manager,
|
||||
telling it which PulseSensor (0 or 1)
|
||||
we're configuring.
|
||||
*/
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT0, 0);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK0, 0);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE0, 0);
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT1, 1);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK1, 1);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE1, 1);
|
||||
|
||||
pulseSensor.setSerial(Serial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
|
||||
// Now that everything is ready, start reading the PulseSensor signal.
|
||||
if (!pulseSensor.begin()) {
|
||||
/*
|
||||
PulseSensor initialization failed,
|
||||
likely because our Arduino platform interrupts
|
||||
aren't supported yet.
|
||||
|
||||
If your Sketch hangs here, try changing USE_ARDUINO_INTERRUPTS to false.
|
||||
*/
|
||||
for (;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK0, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK0, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
/*
|
||||
Wait a bit.
|
||||
We don't output every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
delay(20);
|
||||
|
||||
// write the latest sample to Serial.
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
If a beat has happened on a given PulseSensor
|
||||
since we last checked, write the per-beat information
|
||||
about that PulseSensor to Serial.
|
||||
*/
|
||||
for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
|
||||
if (pulseSensor.sawStartOfBeat(i)) {
|
||||
pulseSensor.outputBeat(i);
|
||||
|
||||
lastBeatSampleNumber[i] = pulseSensor.getLastBeatTime(i);
|
||||
if(i == 1){
|
||||
PTT = lastBeatSampleNumber[1] - lastBeatSampleNumber[0];
|
||||
pulseSensor.outputToSerial('|',PTT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
Code to detect pulses from the PulseSensor
|
||||
and move a servo motor to the beat.
|
||||
uses an interrupt service routine.
|
||||
|
||||
Here is a link to the tutorial
|
||||
https://pulsesensor.com/pages/pulse-sensor-servo-tutorial
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Include Servo.h BEFORE you include PusleSensorPlayground.h
|
||||
*/
|
||||
#include <Servo.h>
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
|
||||
interrupts to automatically read and process PulseSensor data.
|
||||
|
||||
See ProcessEverySample.ino for an example of not using interrupts.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
Pinout:
|
||||
PULSE_INPUT = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
|
||||
that will flash on each detected pulse.
|
||||
PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
|
||||
that will smoothly fade with each pulse.
|
||||
NOTE: PULSE_FADE must be a pin that supports PWM. Do not use
|
||||
pin 9 or 10, because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT = A0;
|
||||
const int PULSE_BLINK = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 5;
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor;
|
||||
|
||||
/*
|
||||
Make a heart servo, the pin to control it with, and a servo position variable
|
||||
*/
|
||||
Servo heart;
|
||||
const int SERVO_PIN = 6;
|
||||
int pos = 90;
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 115200 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 11 bytes per millisecond.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial.begin(115200);
|
||||
// set up the heart servo on SERVO_PULSE
|
||||
// set servo position to pos (90 degrees, mid position)
|
||||
heart.attach(SERVO_PIN);
|
||||
heart.write(pos);
|
||||
|
||||
// Configure the PulseSensor manager.
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
|
||||
pulseSensor.setSerial(Serial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// 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.
|
||||
|
||||
If your Sketch hangs here, try changing USE_ARDUINO_INTERRUPTS to false.
|
||||
which doesn't use interrupts.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/*
|
||||
Wait a bit.
|
||||
We don't output every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
delay(20);
|
||||
|
||||
// write the latest sample to Serial.
|
||||
pulseSensor.outputSample();
|
||||
|
||||
// write the latest analog value to the heart servo
|
||||
moveServo(pulseSensor.getLatestSample());
|
||||
|
||||
/*
|
||||
If a beat has happened since we last checked,
|
||||
write the per-beat information to Serial.
|
||||
*/
|
||||
if (pulseSensor.sawStartOfBeat()) {
|
||||
pulseSensor.outputBeat();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Map the Pulse Sensor Signal to the Servo range
|
||||
Pulse Sensor = 0 <> 1023
|
||||
Servo = 0 <> 180
|
||||
Modify as you see fit!
|
||||
*/
|
||||
void moveServo(int value){
|
||||
pos = map(value,0,1023,0,180);
|
||||
heart.write(pos);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
Code to detect pulses from the PulseSensor,
|
||||
using an interrupt service routine.
|
||||
|
||||
>>>> THIS EXAMPLE OUTPUTS USES TONE COMMAND <<<<
|
||||
>>>> TO MAKE A SPEAKER BEEP WITH HEARTBEAT! <<<<
|
||||
|
||||
Here is a link to the tutorial
|
||||
https://pulsesensor.com/pages/pulse-sensor-speaker-tutorial
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
|
||||
interrupts to automatically read and process PulseSensor data.
|
||||
|
||||
See ProcessEverySample.ino for an example of not using interrupts.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
Pinout:
|
||||
PULSE_INPUT = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
|
||||
that will flash on each detected pulse.
|
||||
PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
|
||||
that will smoothly fade with each pulse.
|
||||
NOTE: PULSE_FADE must be a pin that supports PWM. Do not use
|
||||
pin 9 or 10, because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT = A0;
|
||||
const int PULSE_BLINK = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 5;
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor;
|
||||
|
||||
/*
|
||||
Setup the things we need for driving the Speaker
|
||||
NOTE: Speaker MUST be AC coupled! Connect PIN_SPEAKER to red speaker wire.
|
||||
Then connect black speaker wire to + side of electrolytic capacitor.
|
||||
Then connect - side of electrolytic capacitor to GND.
|
||||
Capacitor value should be 1uF or higher!
|
||||
Follow this tutorial:
|
||||
[link]
|
||||
*/
|
||||
const int PIN_SPEAKER = 2; // speaker on pin2 makes a beep with heartbeat
|
||||
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 115200 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 11 bytes per millisecond.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial.begin(115200);
|
||||
|
||||
// Configure the PulseSensor manager.
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
|
||||
pulseSensor.setSerial(Serial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// 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.
|
||||
|
||||
If your Sketch hangs here, try changing USE_ARDUINO_INTERRUPTS to false.
|
||||
which doesn't use interrupts.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/*
|
||||
Wait a bit.
|
||||
We don't output every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
delay(20);
|
||||
|
||||
// write the latest sample to Serial.
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
If a beat has happened since we last checked,
|
||||
write the per-beat information to Serial.
|
||||
write a frequency to the PIN_SPEAKER
|
||||
NOTE: Do not set the optional duration of tone! That is blocking!
|
||||
*/
|
||||
if (pulseSensor.sawStartOfBeat()) {
|
||||
pulseSensor.outputBeat();
|
||||
tone(PIN_SPEAKER,1047); // tone(pin,frequency)
|
||||
}
|
||||
|
||||
/*
|
||||
The Pulse variable is true only for a short time after the heartbeat is detected
|
||||
Use this to time the duration of the beep
|
||||
*/
|
||||
if(pulseSensor.isInsideBeat() == false){
|
||||
noTone(PIN_SPEAKER);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
Code to detect pulses from the PulseSensor,
|
||||
using an interrupt service routine and
|
||||
using SoftwareSerial for Serial output.
|
||||
|
||||
Here is a link to the tutorial that discusses this coe
|
||||
https://pulsesensor.com/pages/getting-advanced
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
#define USE_ARDUINO_INTERRUPTS true // we want the Playground to use interrupts
|
||||
#include <PulseSensorPlayground.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
PIN_RX = Serial Receive pin (input into Arduino)
|
||||
PIN_TX = Serial Transmit pin (output from Arduino)
|
||||
|
||||
In most cases, you'll want to wire the Arduino PIN_RX
|
||||
to the TRANSMIT pin of the external serial device,
|
||||
and the Arduino PIN_TX to the RECEIVE pin of the
|
||||
external device.
|
||||
*/
|
||||
const int PIN_RX = 7;
|
||||
const int PIN_TX = 8;
|
||||
|
||||
const int PULSE_INPUT = A0;
|
||||
const int PULSE_BLINK = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE = 5; // Must be a PWM pin other than 9 or 10.
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
Our software serial controller.
|
||||
*/
|
||||
SoftwareSerial ourSerial(PIN_RX, PIN_TX);
|
||||
|
||||
PulseSensorPlayground pulseSensor;
|
||||
|
||||
void setup() {
|
||||
|
||||
ourSerial.begin(115200);
|
||||
|
||||
// Configure the PulseSensor manager.
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE);
|
||||
|
||||
pulseSensor.setSerial(ourSerial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
if (!pulseSensor.begin()) {
|
||||
/*
|
||||
* PulseSensor initialization failed,
|
||||
* likely because our particular Arduino platform interrupts
|
||||
* aren't supported yet.
|
||||
*
|
||||
* If your Sketch hangs here, try changing USE_ARDUINO_INTERRUPTS to false.
|
||||
*/
|
||||
for(;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(20);
|
||||
|
||||
pulseSensor.outputSample();
|
||||
|
||||
if (pulseSensor.sawStartOfBeat()) {
|
||||
pulseSensor.outputBeat();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
Arduino Sketch to detect pulses from two PulseSensors.
|
||||
|
||||
Here is a link to the tutorial
|
||||
https://pulsesensor.com/pages/two-or-more-pulse-sensors
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS false tells the library to
|
||||
not use interrupts to read data from the PulseSensor.
|
||||
|
||||
If you want to use interrupts, simply change the line below
|
||||
to read:
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
|
||||
Set US_PS_INTERRUPTS to false if either
|
||||
1) Your Arduino platform's interrupts aren't yet supported
|
||||
by PulseSensor Playground, or
|
||||
2) You don't wish to use interrupts because of the side effects.
|
||||
|
||||
NOTE: if US_PS_INTERRUPTS is false, your Sketch must
|
||||
call pulse.sawNewSample() at least once every 2 milliseconds
|
||||
to accurately read the PulseSensor signal.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the multi-sensor Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensorAmped_2_Sensors
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
Number of PulseSensor devices we're reading from.
|
||||
*/
|
||||
const int PULSE_SENSOR_COUNT = 2;
|
||||
|
||||
/*
|
||||
PULSE_POWERx = the output pin that the red (power) pin of
|
||||
the first PulseSensor will be connected to. PulseSensor only
|
||||
draws about 4mA, so almost any micro can power it from a GPIO.
|
||||
If you don't want to use pins to power the PulseSensors, you can remove
|
||||
the code dealing with PULSE_POWER0 and PULSE_POWER1.
|
||||
PULSE_INPUTx = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINKx = digital Output. Connected to an LED (must have at least
|
||||
470 ohm resistor) that will flash on each detected pulse.
|
||||
PULSE_FADEx = digital Output. PWM pin onnected to an LED (must have
|
||||
at least 470 ohm resistor) that will smoothly fade with each pulse.
|
||||
|
||||
NOTE: PULSE_FADEx must be pins that support PWM.
|
||||
If USE_INTERRUPTS is true, Do not use pin 9 or 10 for PULSE_FADEx
|
||||
because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT0 = A0;
|
||||
const int PULSE_BLINK0 = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE0 = 5;
|
||||
|
||||
const int PULSE_INPUT1 = A1;
|
||||
const int PULSE_BLINK1 = 12;
|
||||
const int PULSE_FADE1 = 11;
|
||||
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
We tell it how many PulseSensors we're using.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor(PULSE_SENSOR_COUNT);
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 250000 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 25 bytes per millisecond,
|
||||
or 50 characters per PulseSensor sample period of 2 milliseconds.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial.begin(250000);
|
||||
|
||||
/*
|
||||
Configure the PulseSensor manager,
|
||||
telling it which PulseSensor (0 or 1)
|
||||
we're configuring.
|
||||
*/
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT0, 0);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK0, 0);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE0, 0);
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT1, 1);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK1, 1);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE1, 1);
|
||||
|
||||
pulseSensor.setSerial(Serial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
|
||||
// Now that everything is ready, start reading the PulseSensor signal.
|
||||
if (!pulseSensor.begin()) {
|
||||
/*
|
||||
PulseSensor initialization failed,
|
||||
likely because our Arduino platform interrupts
|
||||
aren't supported yet.
|
||||
|
||||
If your Sketch hangs here, try changing USE_ARDUINO_INTERRUPTS to false.
|
||||
*/
|
||||
for (;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK0, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK0, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
/*
|
||||
Wait a bit.
|
||||
We don't output every sample, because our baud rate
|
||||
won't support that much I/O.
|
||||
*/
|
||||
delay(20);
|
||||
|
||||
// write the latest sample to Serial.
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
If a beat has happened on a given PulseSensor
|
||||
since we last checked, write the per-beat information
|
||||
about that PulseSensor to Serial.
|
||||
*/
|
||||
for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
|
||||
if (pulseSensor.sawStartOfBeat(i)) {
|
||||
pulseSensor.outputBeat(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
Arduino Sketch to detect pulses from two PulseSensors.
|
||||
|
||||
Here is a link to the tutorial
|
||||
https://pulsesensor.com/pages/two-or-more-pulse-sensors
|
||||
|
||||
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.
|
||||
|
||||
This software is not intended for medical use.
|
||||
*/
|
||||
|
||||
/*
|
||||
Every Sketch that uses the PulseSensor Playground must
|
||||
define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
|
||||
Here, #define USE_ARDUINO_INTERRUPTS false tells the library to
|
||||
not use interrupts to read data from the PulseSensor.
|
||||
|
||||
If you want to use interrupts, simply change the line below
|
||||
to read:
|
||||
#define USE_ARDUINO_INTERRUPTS true
|
||||
|
||||
Set US_PS_INTERRUPTS to false if either
|
||||
1) Your Arduino platform's interrupts aren't yet supported
|
||||
by PulseSensor Playground, or
|
||||
2) You don't wish to use interrupts because of the side effects.
|
||||
|
||||
NOTE: if US_PS_INTERRUPTS is false, your Sketch must
|
||||
call pulse.sawNewSample() at least once every 2 milliseconds
|
||||
to accurately read the PulseSensor signal.
|
||||
*/
|
||||
#define USE_ARDUINO_INTERRUPTS false
|
||||
#include <PulseSensorPlayground.h>
|
||||
|
||||
|
||||
/*
|
||||
The format of our output.
|
||||
|
||||
Set this to PROCESSING_VISUALIZER if you're going to run
|
||||
the multi-sensor Processing Visualizer Sketch.
|
||||
See https://github.com/WorldFamousElectronics/PulseSensorAmped_2_Sensors
|
||||
|
||||
Set this to SERIAL_PLOTTER if you're going to run
|
||||
the Arduino IDE's Serial Plotter.
|
||||
*/
|
||||
const int OUTPUT_TYPE = SERIAL_PLOTTER;
|
||||
|
||||
/*
|
||||
Number of PulseSensor devices we're reading from.
|
||||
*/
|
||||
const int PULSE_SENSOR_COUNT = 2;
|
||||
|
||||
/*
|
||||
PULSE_POWERx = the output pin that the red (power) pin of
|
||||
the first PulseSensor will be connected to. PulseSensor only
|
||||
draws about 4mA, so almost any micro can power it from a GPIO.
|
||||
If you don't want to use pins to power the PulseSensors, you can remove
|
||||
the code dealing with PULSE_POWER0 and PULSE_POWER1.
|
||||
PULSE_INPUTx = Analog Input. Connected to the pulse sensor
|
||||
purple (signal) wire.
|
||||
PULSE_BLINKx = digital Output. Connected to an LED (must have at least
|
||||
470 ohm resistor) that will flash on each detected pulse.
|
||||
PULSE_FADEx = digital Output. PWM pin onnected to an LED (must have
|
||||
at least 470 ohm resistor) that will smoothly fade with each pulse.
|
||||
|
||||
NOTE: PULSE_FADEx must be pins that support PWM.
|
||||
If USE_INTERRUPTS is true, Do not use pin 9 or 10 for PULSE_FADEx
|
||||
because those pins' PWM interferes with the sample timer.
|
||||
*/
|
||||
const int PULSE_INPUT0 = A0;
|
||||
const int PULSE_BLINK0 = 13; // Pin 13 is the on-board LED
|
||||
const int PULSE_FADE0 = 5;
|
||||
|
||||
const int PULSE_INPUT1 = A1;
|
||||
const int PULSE_BLINK1 = 12;
|
||||
const int PULSE_FADE1 = 11;
|
||||
|
||||
const int THRESHOLD = 550; // Adjust this number to avoid noise when idle
|
||||
|
||||
/*
|
||||
samplesUntilReport = the number of samples remaining to read
|
||||
until we want to report a sample over the serial connection.
|
||||
|
||||
We want to report a sample value over the serial port
|
||||
only once every 20 milliseconds (10 samples) to avoid
|
||||
doing Serial output faster than the Arduino can send.
|
||||
*/
|
||||
byte samplesUntilReport;
|
||||
const byte SAMPLES_PER_SERIAL_SAMPLE = 10;
|
||||
|
||||
/*
|
||||
All the PulseSensor Playground functions.
|
||||
We tell it how many PulseSensors we're using.
|
||||
*/
|
||||
PulseSensorPlayground pulseSensor(PULSE_SENSOR_COUNT);
|
||||
|
||||
void setup() {
|
||||
/*
|
||||
Use 250000 baud because that's what the Processing Sketch expects to read,
|
||||
and because that speed provides about 25 bytes per millisecond,
|
||||
or 50 characters per PulseSensor sample period of 2 milliseconds.
|
||||
|
||||
If we used a slower baud rate, we'd likely write bytes faster than
|
||||
they can be transmitted, which would mess up the timing
|
||||
of readSensor() calls, which would make the pulse measurement
|
||||
not work properly.
|
||||
*/
|
||||
Serial.begin(250000);
|
||||
|
||||
/*
|
||||
Configure the PulseSensor manager,
|
||||
telling it which PulseSensor (0 or 1)
|
||||
we're configuring.
|
||||
*/
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT0, 0);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK0, 0);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE0, 0);
|
||||
|
||||
pulseSensor.analogInput(PULSE_INPUT1, 1);
|
||||
pulseSensor.blinkOnPulse(PULSE_BLINK1, 1);
|
||||
pulseSensor.fadeOnPulse(PULSE_FADE1, 1);
|
||||
|
||||
pulseSensor.setSerial(Serial);
|
||||
pulseSensor.setOutputType(OUTPUT_TYPE);
|
||||
pulseSensor.setThreshold(THRESHOLD);
|
||||
|
||||
// Skip the first SAMPLES_PER_SERIAL_SAMPLE in the loop().
|
||||
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
|
||||
|
||||
// Now that everything is ready, start reading the PulseSensor signal.
|
||||
if (!pulseSensor.begin()) {
|
||||
/*
|
||||
PulseSensor initialization failed,
|
||||
likely because our Arduino platform interrupts
|
||||
aren't supported yet.
|
||||
|
||||
If your Sketch hangs here, try changing USE_ARDUINO_INTERRUPTS to false.
|
||||
*/
|
||||
for (;;) {
|
||||
// Flash the led to show things didn't work.
|
||||
digitalWrite(PULSE_BLINK0, LOW);
|
||||
delay(50);
|
||||
digitalWrite(PULSE_BLINK0, HIGH);
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if (pulseSensor.sawNewSample()) {
|
||||
|
||||
if (--samplesUntilReport == (byte) 0) {
|
||||
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
|
||||
|
||||
pulseSensor.outputSample();
|
||||
|
||||
/*
|
||||
If a beat has happened on a given PulseSensor
|
||||
since we last checked, write the per-beat information
|
||||
about that PulseSensor to Serial.
|
||||
*/
|
||||
|
||||
for (int i = 0; i < PULSE_SENSOR_COUNT; ++i) {
|
||||
if (pulseSensor.sawStartOfBeat(i)) {
|
||||
pulseSensor.outputBeat(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******
|
||||
Here is a good place to add code that could take up
|
||||
to a millisecond or so to run.
|
||||
*******/
|
||||
}
|
||||
|
||||
/******
|
||||
Don't add code here, because it could slow the sampling
|
||||
from the PulseSensor.
|
||||
******/
|
||||
}
|
||||
Reference in New Issue
Block a user