Lehrer Busch / Mbed OS xxx_Sonar-HC-SR04_Lsg

Dependencies:   HC_SR04_Ultrasonic_Library

Files at this revision

API Documentation at this revision

Comitter:
itbusch
Date:
Wed Feb 23 19:22:03 2022 +0000
Parent:
0:b0a3597dffa9
Commit message:
xxx_Sonar-HC-SR04_Lsg

Changed in this revision

HC-SR04.lib Show diff for this revision Revisions of this file
HC_SR04_Ultrasonic_Library.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
diff -r b0a3597dffa9 -r ea41d3c33200 HC-SR04.lib
--- a/HC-SR04.lib	Thu Feb 05 19:04:15 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/Nestordp/code/HC-SR04/#d1d7bb1c1f6c
diff -r b0a3597dffa9 -r ea41d3c33200 HC_SR04_Ultrasonic_Library.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HC_SR04_Ultrasonic_Library.lib	Wed Feb 23 19:22:03 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/JohnnyK/code/HC_SR04_Ultrasonic_Library/#9808e2c61247
diff -r b0a3597dffa9 -r ea41d3c33200 main.cpp
--- a/main.cpp	Thu Feb 05 19:04:15 2015 +0000
+++ b/main.cpp	Wed Feb 23 19:22:03 2022 +0000
@@ -1,17 +1,23 @@
-#include "mbed.h"
-#include "HCSR04.h"
-
-DigitalOut myled(LED1);
-Serial pc(USBTX,USBRX);     
-
-HCSR04 sonar(A2, D12);
-
-int main() {
-    printf("INICIO PROGRAMA\n");
-    while(1) {
-        printf("Distancia detectada pelo sensor Frente %.2f cm \n", sonar.getCm()); 
-        wait_ms(1000);
-        printf("Distancia detectada pelo sensor Frente %.2f in \n", sonar.getIn()); 
-        wait_ms(1000);
+    #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);
     }
-}
\ No newline at end of file
+    
+    ultrasonic mu(D2, D4, 100ms, 1s, &dist);    //Set the trigger pin to D2 and the echo pin to D4
+                                                //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.
+        }
+    }
\ No newline at end of file
diff -r b0a3597dffa9 -r ea41d3c33200 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Feb 23 19:22:03 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#b1796dedeb8accde1cbaecf136fab96895e23d81
diff -r b0a3597dffa9 -r ea41d3c33200 mbed.bld
--- a/mbed.bld	Thu Feb 05 19:04:15 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa
\ No newline at end of file