Cheap ultrasonic range finder works with interrupts. Fork of original https://os.mbed.com/components/HC-SR04/ and update for MbedOS6+

Dependents:   Nucleo_UltrasonicHelloWorld xxx_Sonar-HC-SR04_Lsg

Files at this revision

API Documentation at this revision

Comitter:
JohnnyK
Date:
Thu Jun 10 18:53:38 2021 +0000
Parent:
5:6fd0e9c7ead4
Commit message:
add example into .h

Changed in this revision

ultrasonic.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6fd0e9c7ead4 -r 9808e2c61247 ultrasonic.h
--- a/ultrasonic.h	Thu Jun 10 18:45:59 2021 +0000
+++ b/ultrasonic.h	Thu Jun 10 18:53:38 2021 +0000
@@ -1,6 +1,36 @@
 #ifndef MBED_ULTRASONIC_H
 #define MBED_ULTRASONIC_H
 
+/**
+    @code
+    
+    #include "mbed.h"
+    #include "ultrasonic.h"
+    
+     void dist(int distance)
+    {
+        //put code here to happen when the distance is changed
+        printf("Distance changed to %dmm\r\n", distance);
+    }
+    
+    ultrasonic mu(D8, D9, 100ms, 1s, &dist);    //Set the trigger pin to D8 and the echo pin to D9
+                                                //have updates every .1 seconds and a timeout after 1
+                                                //second, and call dist when the distance changes
+    
+    int main()
+    {
+        mu.startUpdates();//start mesuring the distance
+        while(1)
+        {
+            //Do something else here
+            mu.checkDistance();     //call checkDistance() as much as possible, as this is where
+                                    //the class checks if dist needs to be called.
+        }
+    }
+    
+    @endcode
+*/
+
 #include "mbed.h"
 
 class ultrasonic