HRM with LPC1768, calculating the BPM and communicating with bluetooth

Dependencies:   mbed

Committer:
2675375x
Date:
Sun Jul 31 20:09:30 2022 +0000
Revision:
1:44f270926c4a
Parent:
0:312e7105da24
HRM with LPC1768, calculating the BPM and communicating with bluetooth

Who changed what in which revision?

UserRevisionLine numberNew contents of line
2675375x 0:312e7105da24 1 #include "mbed.h"
2675375x 0:312e7105da24 2 #include "HRM.h"
2675375x 0:312e7105da24 3
2675375x 0:312e7105da24 4
2675375x 0:312e7105da24 5 float data =3.3;
2675375x 0:312e7105da24 6 float previous_data =0;
2675375x 0:312e7105da24 7 int count1= 0;
2675375x 0:312e7105da24 8
2675375x 0:312e7105da24 9 int main(void){
2675375x 0:312e7105da24 10
2675375x 0:312e7105da24 11 bt.baud(9600);
2675375x 0:312e7105da24 12 int count1 = 0;
2675375x 0:312e7105da24 13 float time_perhb;
2675375x 0:312e7105da24 14 bt.printf("Analyse signal\n\r");
2675375x 0:312e7105da24 15
2675375x 0:312e7105da24 16 float samples[2048];
2675375x 0:312e7105da24 17 float adc_value;
2675375x 0:312e7105da24 18 float *p =samples;
2675375x 0:312e7105da24 19 for(int i = 0; i<2048;i++){
2675375x 0:312e7105da24 20 adc_value = sensor.read()* 3.3;
2675375x 0:312e7105da24 21 *(p+i) = adc_value ;
2675375x 0:312e7105da24 22 wait_ms(1);
2675375x 0:312e7105da24 23 }
2675375x 0:312e7105da24 24
2675375x 0:312e7105da24 25 float max = Get_Array_Max(samples,2048);
2675375x 0:312e7105da24 26 float min = Get_Array_Min(samples,2048);
2675375x 0:312e7105da24 27 float maxrate = Get_MaxRate(samples,2048);
2675375x 0:312e7105da24 28 float threshold = (max - min)*0.7+ min;
2675375x 0:312e7105da24 29
2675375x 0:312e7105da24 30 int BPM;
2675375x 0:312e7105da24 31 int swi = 1;
2675375x 0:312e7105da24 32 bool firstcircle = true;
2675375x 0:312e7105da24 33
2675375x 0:312e7105da24 34 while(1){
2675375x 0:312e7105da24 35 //swi = bt.getc();
2675375x 0:312e7105da24 36 if(swi == 1){
2675375x 0:312e7105da24 37 bt.printf("max = %f\n",max);
2675375x 0:312e7105da24 38 bt.printf("min = %f\n",min);
2675375x 0:312e7105da24 39 bt.printf("maxrate = %f\n",maxrate);
2675375x 0:312e7105da24 40 bt.printf("threshold = %f\n",threshold);
2675375x 0:312e7105da24 41
2675375x 0:312e7105da24 42 while(swi == 1){
2675375x 0:312e7105da24 43 previous_data = data;
2675375x 0:312e7105da24 44 data = sensor.read()*3.3;
2675375x 0:312e7105da24 45
2675375x 0:312e7105da24 46 if(data>=threshold && previous_data<threshold){
2675375x 0:312e7105da24 47 if(firstcircle){
2675375x 0:312e7105da24 48 count1 = 0;
2675375x 0:312e7105da24 49 firstcircle = false;
2675375x 0:312e7105da24 50 }
2675375x 0:312e7105da24 51 else{
2675375x 0:312e7105da24 52 if(count1 >20){
2675375x 0:312e7105da24 53
2675375x 0:312e7105da24 54 if((data - previous_data)/0.005 < maxrate * 0.7 && count1<100 ){
2675375x 0:312e7105da24 55 bt.printf("Find error point,removed!\n");
2675375x 0:312e7105da24 56 count1++;
2675375x 0:312e7105da24 57 wait(0.005);
2675375x 0:312e7105da24 58 }
2675375x 0:312e7105da24 59 else{
2675375x 0:312e7105da24 60 time_perhb = count1 * 0.005;
2675375x 0:312e7105da24 61 BPM = 60/time_perhb;
2675375x 0:312e7105da24 62
2675375x 0:312e7105da24 63 if(BPM<200&&BPM>30){
2675375x 0:312e7105da24 64 bt.printf("BPM=%d\n", BPM);
2675375x 0:312e7105da24 65 }
2675375x 0:312e7105da24 66 count1 = 0;
2675375x 0:312e7105da24 67 wait(0.005);
2675375x 0:312e7105da24 68 }
2675375x 0:312e7105da24 69 }
2675375x 0:312e7105da24 70
2675375x 0:312e7105da24 71 }
2675375x 0:312e7105da24 72
2675375x 0:312e7105da24 73 }
2675375x 0:312e7105da24 74 else{
2675375x 0:312e7105da24 75 count1++;
2675375x 0:312e7105da24 76 wait(0.005);
2675375x 0:312e7105da24 77 }
2675375x 0:312e7105da24 78 }
2675375x 0:312e7105da24 79 }
2675375x 0:312e7105da24 80 }
2675375x 0:312e7105da24 81 }