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
main.cpp
- Committer:
- jrsikken
- Date:
- 2010-11-24
- Revision:
- 0:939617e180e8
- Child:
- 1:8b001f936bb0
File content as of revision 0:939617e180e8:
//This program measures heart rate and displays it on the LCD and sends the time between heart beats to the serial port. //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 character. #include "mbed.h" #include "TextLCD.h" TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d0-d3 InterruptIn beat(p8); DigitalOut led(LED1); Ticker mscnt; //initialize int count, CNT,displayBPMFlag ; void ms_counter() { //this interrupt routine starts every ms count++; //the counter is increased with 1 if (count>1999) { //when no heart beat is detected for >2ms, then display "-" in the main loop CNT=count; // copy counter value to CNT displayBPMFlag = 1; // set flag that the BPM can be put to LCD in the main loop count=0; // reset counter value } } void flip() { //this interrupt routine starts on every heart beat CNT = count; // copy counter value to CNT count = 0 ; // reset counter value displayBPMFlag = 1; // set flag that the BPM can be put to LCD in the main loop led = !led; // toggle the led on/off } int main() { int BPM; //initialize BPM lcd.cls(); //clear the lcd display mscnt.attach_us(&ms_counter, 1000); // the address of the function to be attached (ms_counter) and the interval (1ms) beat.rise(&flip); // attach the address of the flip function to the rising edge while (1) { if (displayBPMFlag == 1) { // program loops around in here displayBPMFlag = 0; // clear displayBPMflag if (CNT>250&CNT<2000) { //when heart rate is within 30-240BPM BPM = 60000/CNT; //calculate BPM lcd.cls(); //clear the lcd display lcd.locate(0,0); //set cursor to first character and first line lcd.printf("%i ms", CNT); //display the time in ms on the lcd lcd.locate(0,1); //set cursor to first character and second line lcd.printf("%i BPM",BPM); //display the beats per minute on the lcd printf("%i\r\n", CNT); //print the time in ms to the serial port } else {//when heart rate is NOT within 30-240BPM lcd.cls(); //clear the lcd display lcd.locate(0,0); //set cursor to first character and first line lcd.printf("- ms"); //display empty time in ms on the lcd lcd.locate(0,1); //set cursor to first character and second line lcd.printf("- BPM"); //display empty beats per minute on the lcd printf("- \r\n", CNT); //print the time in ms to the serial port } } } }