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.
PulseSensor.h
00001 #ifndef PULSE_SENSOR_H 00002 #define PULSE_SENSOR_H 00003 00004 #include "mbed.h" 00005 00006 00007 /** 00008 * Class for interfacing with a http://pulsesensor.myshopify.com/ 'Pulse Sensor Amped'. 00009 * The contents of this class are based on the "Pulse Sensor Amped 1.1" Arduino Sketch. 00010 * 00011 * When using this class for the first time, it is recommended that you use the Processing 00012 * GUI app available http://pulsesensor.myshopify.com/pages/code-and-guide. Using this, you 00013 * will easily be able to verify the operating of your sensor, and the integration of this 00014 * class into your mbed project. 00015 */ 00016 00017 class PulseSensor 00018 { 00019 private: 00020 volatile int rate[10]; // used to hold last ten IBI values 00021 volatile unsigned long sampleCounter; // used to determine pulse timing 00022 volatile unsigned long lastBeatTime; // used to find the inter beat interval 00023 volatile int P; // used to find peak in pulse wave 00024 volatile int T; // used to find trough in pulse wave 00025 volatile int thresh; // used to find instant moment of heart beat 00026 volatile int amp; // used to hold amplitude of pulse waveform 00027 volatile bool firstBeat; // used to seed rate array so we startup with reasonable BPM 00028 volatile bool secondBeat; // used to seed rate array so we startup with reasonable BPM 00029 00030 // these variables are volatile because they are used during the interrupt service routine! 00031 volatile uint8_t BPM; // used to hold the pulse rate 00032 volatile int Signal; // holds the incoming raw data 00033 volatile int IBI; // holds the time between beats, the Inter-Beat Interval 00034 volatile bool Pulse; // true when pulse wave is high, false when it's low 00035 volatile bool QS; // becomes true when a beat is found 00036 00037 00038 void (*_printDataCallback)(int); 00039 static const int _sensorTickRateMs = 2; 00040 int _callbackRateMs; 00041 bool _started; 00042 00043 AnalogIn *_pAin; 00044 Ticker _pulseSensorTicker; 00045 Ticker _processDataTicker; 00046 00047 void sensor_ticker_callback(void); 00048 void process_data_ticker_callback(void); 00049 00050 public: 00051 /** PulseSensor Constructor - Note this does not start the reading of the sensor. 00052 * @param analogPin Name of the analog pin that the sensor is connected to. 00053 * @param printDataCallback Pointer to function which will be called to print the latest data. Output format available here: http://pulsesensor.myshopify.com/pages/code-and-guide 00054 * @param callbackRateMs Rate at which the printDataCallback is to be called, recommended is 20ms for graphing of pulse signal. 00055 */ 00056 //volatile uint8_t BPM; 00057 00058 PulseSensor(PinName analogPin, void (*printDataCallback)(int), int callbackRateMs=20); 00059 00060 /** Destructor */ 00061 ~PulseSensor(); 00062 00063 /** Start reading the Pulse Sensor, and sending current readings to the print data callback. 00064 * @returns true if reading of the sensor is started, false if reading was aleady in progress. 00065 */ 00066 bool start(); 00067 00068 /** Stops the current reading of the Pulse Senson. 00069 * @return true if reading is stopped, false if reading was already stopped. 00070 */ 00071 bool stop(); 00072 00073 uint8_t get_bpm(); 00074 }; 00075 00076 #endif
Generated on Mon Sep 26 2022 15:47:46 by
1.7.2