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.
Diff: main.cpp
- Revision:
 - 2:c65e1c89824c
 - Parent:
 - 1:08d5b02b7eb4
 - Child:
 - 3:937505b99ca7
 
--- a/main.cpp	Tue Feb 28 17:09:27 2017 +0000
+++ b/main.cpp	Wed Mar 01 16:52:25 2017 +0000
@@ -1,41 +1,68 @@
 #include "mbed.h"
 
-DigitalOut myled(LED1);
+DigitalOut myBuzzer(D6);
+
+DigitalOut myLedGreen(LED1);
+
+DigitalIn myButton(PC_13);
 DigitalIn myPulse(D7);
+
 Timer timer;
-//void serviceMyPulse(void);
+
+float getpulse(void);
+void Sound_AlarmBuzzer(void);
+
+int main()
+{
+    myBuzzer=0;
+    myLedGreen=0;
+
+    float HeartBeat=0.0f;
+    //myPulse.rise(&serviceMyPulse);
+    printf("Heart Beat Monitor!\n\r");
+    timer.start();
+    timer.reset();
+    //float HB_Array[6]={0.0f};
+
+    while(1) {
+
+        //to convert this time we need to perform a BPM=(1/t)*60
+        HeartBeat=getpulse();//(1.0f/HeartBeat)*60.0f;
+
 
-int main() {
-  myled=0;
-  float HeartBeat=0.0f;
-  //myPulse.rise(&serviceMyPulse);
-  printf("Heart Beat Monitor!\n\r");
-  timer.start();
-  timer.reset();
-  while(true){
-      while(myPulse==0){wait_ms(50);}
-      while(myPulse==1){wait_ms(50);}
-      HeartBeat=timer.read();
-      //to convert this time we need to perform a BPM=(1/t)*60
-      HeartBeat=(1.0f/HeartBeat)*60.0f;
-      printf("Heart Beat is: %5.1f\n\r",HeartBeat);
-      if (HeartBeat < 50.0f){
+        printf("Heart Beat is: %5.1f\n\r",HeartBeat);
+        if (HeartBeat < 50.0f) {
             printf( "Warning, low Heartbeat \n\r");
-      }
-      if (HeartBeat > 90.0f){
-          printf("Warning, high HeartBeart \n\r");
-           }
-           
-        if (HeartBeat == NULL){
-                printf("WARNING, Heart Stopped!!!! \n\r");
-           }
-        
-      timer.reset();
-      myled=1;
-      wait_ms(100);
-      myled=0;
-      }
-  
+            while(myButton == 1) {
+                
+            Sound_AlarmBuzzer();
+            
+            }
+            deepsleep();
+        }
+        if (HeartBeat > 90.0f) {
+            printf("Warning, high HeartBeart \n\r");
+            while(myButton == 1) {
+
+            Sound_AlarmBuzzer();
+            
+            }
+            deepsleep();
+
+        }
+
+        if (HeartBeat < 1.0f) {
+            printf("WARNING, Heart Stopped!!!! \n\r");
+            while(myButton == 1) {
+
+             Sound_AlarmBuzzer();
+            }
+            deepsleep();
+
+        }
+
+    }
+
 }
 /*
 void serviceMyPulse(void){
@@ -43,4 +70,49 @@
     wait_ms(100);
     myled=0;
     }
-*/
\ No newline at end of file
+*/
+
+float getpulse(void)
+{
+
+    float localHB;
+    while(myPulse==0) {
+        wait_ms(50);
+    }
+    while(myPulse==1) {
+        wait_ms(50);
+    }
+    timer.reset();
+
+    myLedGreen=1;
+    wait_ms(100);
+    myLedGreen=0;
+
+
+    while(myPulse==0) {
+        wait_ms(50);
+    }
+    while(myPulse==1) {
+        wait_ms(50);
+    }
+    localHB=timer.read();
+
+    myLedGreen=1;
+    wait_ms(100);
+    myLedGreen=0;
+
+
+
+    //to convert this time we need to perform a BPM=(1/t)*60
+    localHB=(1.0f/localHB)*60.0f;
+
+    return localHB;
+}
+
+void Sound_AlarmBuzzer(void)
+{
+        myBuzzer=1;
+        wait_ms(500);
+        myBuzzer=0;
+        wait_ms(500);
+}
\ No newline at end of file