This program displays heart rate and time between heart beats on LCD, prints it to a USB serial port, print it to a bluetooth serial port and store it on a USB mass storage device. The program has two interrupt routines: 1.Every 1ms a counter is increased with one, 2. On every heart beat the counter is value copied. In the main loop the beats per minute are calculated. Ext.Modules:- Polar RMCM-01 heart rate module connected to pin8. - 2x16 LCD - a RF-BT0417CB bluetooth serial device connected to p27 and p28 - an USB mass storage device

Dependencies:   TextLCD mbed

Committer:
jrsikken
Date:
Wed Nov 24 21:31:44 2010 +0000
Revision:
0:939617e180e8
Child:
1:8b001f936bb0
The first post

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jrsikken 0:939617e180e8 1 //This program measures heart rate and displays it on the LCD and sends the time between heart beats to the serial port.
jrsikken 0:939617e180e8 2 //The program has two interrupt routines: 1.Every 1ms a counter is increased with one, 2. On every heart beat the counter is value copied.
jrsikken 0:939617e180e8 3 //In the main loop the beats per minute are calculated.
jrsikken 0:939617e180e8 4 //Ext.Modules: -Polar RMCM-01 heart rate module connected to pin8.
jrsikken 0:939617e180e8 5 // -2x16 character.
jrsikken 0:939617e180e8 6
jrsikken 0:939617e180e8 7 #include "mbed.h"
jrsikken 0:939617e180e8 8 #include "TextLCD.h"
jrsikken 0:939617e180e8 9
jrsikken 0:939617e180e8 10 TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d0-d3
jrsikken 0:939617e180e8 11 InterruptIn beat(p8);
jrsikken 0:939617e180e8 12 DigitalOut led(LED1);
jrsikken 0:939617e180e8 13 Ticker mscnt;
jrsikken 0:939617e180e8 14
jrsikken 0:939617e180e8 15 //initialize
jrsikken 0:939617e180e8 16 int count, CNT,displayBPMFlag ;
jrsikken 0:939617e180e8 17
jrsikken 0:939617e180e8 18 void ms_counter() { //this interrupt routine starts every ms
jrsikken 0:939617e180e8 19 count++; //the counter is increased with 1
jrsikken 0:939617e180e8 20 if (count>1999) { //when no heart beat is detected for >2ms, then display "-" in the main loop
jrsikken 0:939617e180e8 21 CNT=count; // copy counter value to CNT
jrsikken 0:939617e180e8 22 displayBPMFlag = 1; // set flag that the BPM can be put to LCD in the main loop
jrsikken 0:939617e180e8 23 count=0; // reset counter value
jrsikken 0:939617e180e8 24 }
jrsikken 0:939617e180e8 25 }
jrsikken 0:939617e180e8 26
jrsikken 0:939617e180e8 27 void flip() { //this interrupt routine starts on every heart beat
jrsikken 0:939617e180e8 28 CNT = count; // copy counter value to CNT
jrsikken 0:939617e180e8 29 count = 0 ; // reset counter value
jrsikken 0:939617e180e8 30 displayBPMFlag = 1; // set flag that the BPM can be put to LCD in the main loop
jrsikken 0:939617e180e8 31 led = !led; // toggle the led on/off
jrsikken 0:939617e180e8 32 }
jrsikken 0:939617e180e8 33
jrsikken 0:939617e180e8 34 int main() {
jrsikken 0:939617e180e8 35 int BPM; //initialize BPM
jrsikken 0:939617e180e8 36 lcd.cls(); //clear the lcd display
jrsikken 0:939617e180e8 37 mscnt.attach_us(&ms_counter, 1000); // the address of the function to be attached (ms_counter) and the interval (1ms)
jrsikken 0:939617e180e8 38 beat.rise(&flip); // attach the address of the flip function to the rising edge
jrsikken 0:939617e180e8 39 while (1) {
jrsikken 0:939617e180e8 40 if (displayBPMFlag == 1) { // program loops around in here
jrsikken 0:939617e180e8 41 displayBPMFlag = 0; // clear displayBPMflag
jrsikken 0:939617e180e8 42 if (CNT>250&CNT<2000) { //when heart rate is within 30-240BPM
jrsikken 0:939617e180e8 43 BPM = 60000/CNT; //calculate BPM
jrsikken 0:939617e180e8 44 lcd.cls(); //clear the lcd display
jrsikken 0:939617e180e8 45 lcd.locate(0,0); //set cursor to first character and first line
jrsikken 0:939617e180e8 46 lcd.printf("%i ms", CNT); //display the time in ms on the lcd
jrsikken 0:939617e180e8 47 lcd.locate(0,1); //set cursor to first character and second line
jrsikken 0:939617e180e8 48 lcd.printf("%i BPM",BPM); //display the beats per minute on the lcd
jrsikken 0:939617e180e8 49 printf("%i\r\n", CNT); //print the time in ms to the serial port
jrsikken 0:939617e180e8 50 } else {//when heart rate is NOT within 30-240BPM
jrsikken 0:939617e180e8 51 lcd.cls(); //clear the lcd display
jrsikken 0:939617e180e8 52 lcd.locate(0,0); //set cursor to first character and first line
jrsikken 0:939617e180e8 53 lcd.printf("- ms"); //display empty time in ms on the lcd
jrsikken 0:939617e180e8 54 lcd.locate(0,1); //set cursor to first character and second line
jrsikken 0:939617e180e8 55 lcd.printf("- BPM"); //display empty beats per minute on the lcd
jrsikken 0:939617e180e8 56 printf("- \r\n", CNT); //print the time in ms to the serial port
jrsikken 0:939617e180e8 57 }
jrsikken 0:939617e180e8 58
jrsikken 0:939617e180e8 59 }
jrsikken 0:939617e180e8 60
jrsikken 0:939617e180e8 61 }
jrsikken 0:939617e180e8 62 }