Bradley Kohler / Mbed OS PulseRate

Dependencies:   PulseRate

Dependents:   PulseRate

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MAX30100.h"
00003 
00004 DigitalOut led(LED1);
00005 
00006 MAX30100 max;
00007 uint32_t tsLastPollUs = 0;
00008 
00009 // Tweakable parameters
00010 // Sampling and polling frequency must be set consistently
00011 #define POLL_PERIOD_US                      1E06 / 100
00012 #define SAMPLING_RATE                       MAX30100_SAMPRATE_100HZ
00013 
00014 // The LEDs currents must be set to a level that avoids clipping and maximises the
00015 // dynamic range
00016 #define IR_LED_CURRENT                      MAX30100_LED_CURR_50MA
00017 #define RED_LED_CURRENT                     MAX30100_LED_CURR_27_1MA
00018 
00019 // The pulse width of the LEDs driving determines the resolution of
00020 // the ADC (which is a Sigma-Delta).
00021 // set HIGHRES_MODE to true only when setting PULSE_WIDTH to MAX30100_SPC_PW_1600US_16BITS
00022 #define PULSE_WIDTH                         MAX30100_SPC_PW_1600US_16BITS
00023 #define HIGHRES_MODE                        true
00024 
00025 int main() {
00026 /*
00027 pc.printf("POR State:\n\r");
00028 max.printRegisters();
00029 pc.printf("\n\r");
00030 
00031 max.begin();
00032 pc.printf("Begin State:\n\r");
00033 max.printRegisters();
00034 wait(1);
00035 pc.printf("\n\r");
00036 
00037 max.setMode(MAX30100_MODE_SPO2_HR);
00038 pc.printf("\n\rSPO2 and HR Mode:\n\r");
00039 max.printRegisters();
00040 wait(1);
00041 
00042 pc.printf("\n\rSetting LEDs to 50mA:\n\r");
00043 max.setLedsCurrent(MAX30100_LED_CURR_50MA, MAX30100_LED_CURR_50MA);
00044 max.printRegisters();
00045 wait(10);
00046 
00047 pc.printf("\n\rSetting LEDs to 7.6mA\n\r");
00048 max.setLedsCurrent(MAX30100_LED_CURR_7_6MA, MAX30100_LED_CURR_7_6MA);
00049 max.printRegisters();
00050 pc.printf("\n\r");
00051 return 1;
00052 */
00053 max.begin();
00054 max.setMode(MAX30100_MODE_SPO2_HR);
00055 max.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT);
00056 max.setLedsPulseWidth(PULSE_WIDTH);
00057 max.setSamplingRate(SAMPLING_RATE);
00058 max.setHighresModeEnabled(HIGHRES_MODE);
00059 
00060 while(1){
00061 if(us_ticker_read() < tsLastPollUs || us_ticker_read() - tsLastPollUs > POLL_PERIOD_US){
00062     max.update();
00063     tsLastPollUs = us_ticker_read();
00064     pc.printf("$%d %d;", max.rawIRValue/10, max.rawRedValue/10);
00065 }
00066 }
00067 }