This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.

Dependencies:   RemoteIR

Revision:
130:d19783810c05
Parent:
129:53f2df333d65
Child:
131:8fb226cc407c
--- a/main.cpp	Tue Apr 28 08:22:30 2020 +0000
+++ b/main.cpp	Fri May 01 09:15:12 2020 +0000
@@ -6,10 +6,48 @@
 
 DigitalOut led2(LED2);
 Serial pc(PA_2, PA_3, 115200);
+PwmOut buzzer(PB_4);
 
+Ticker ticker;
+
+bool sing = false;
+
+float m_distance;
 
+void m_on() {
+    led2 = 1;
+    
+    
+       buzzer = 1.0 - 0.05;
+       
+       int period_us;
+       period_us = 1000000/880.0;
+       
+       buzzer.period_us(period_us);
+}
+void m_off() {
+    led2 = 0;
+    
+    
+       buzzer = 1.0 - 0.05;
+       
+       buzzer.period_us(100);
+}
+
+void Bell() {
+       
+       if(m_distance > 100.0) {
+            sing = false;
+            m_off();   
+        } else if(sing) {
+            m_on();
+            sing = false;
+        } else {
+            m_off();
+            sing = true;
+        }
+}
 int main() {
-    float distance;
     
     trigger = 0;
     pc.printf("\r\nWelcome to Utrasonic Sensor Lab!\r\n");;
@@ -19,16 +57,23 @@
         timer1.reset();
         trigger = 1;
         wait_us(10.0);
-        led2 = 1;
         trigger = 0;
         
         while(echo == 0) {}
         timer1.start();
         while(echo == 1) {}
         timer1.stop();
-        led2 = 0;
-        distance = timer1.read_us()/58.0;
-        pc.printf("The distance is %f [cm] \n\r", distance);
+        m_distance = timer1.read_us()/58.0;
+        pc.printf("The distance is %f [cm] \n\r", m_distance);
+
+        
+        ticker.detach();
+        if(m_distance / 200 < 0.05) {
+            ticker.attach(&Bell, 0.05);
+            
+        } else {
+            ticker.attach(&Bell, m_distance / 200);
+        }
 
         ThisThread::sleep_for(1000);        
     }