smd.iotkit.ch / Mbed 2 deprecated UltraschallSensor_LowLevelV2

Dependencies:   HC_SR04_Ultrasonic_Library OLEDDisplay mbed

Fork of UltraschallSensor by smd.iotkit.ch

Files at this revision

API Documentation at this revision

Comitter:
dbdata
Date:
Sat Oct 29 12:19:28 2016 +0000
Parent:
0:b84310cad4b3
Commit message:
New with OLED Output.

Changed in this revision

OLEDDisplay.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
diff -r b84310cad4b3 -r 48e4876a3868 OLEDDisplay.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OLEDDisplay.lib	Sat Oct 29 12:19:28 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/smdiotkitch/code/OLEDDisplay/#1dee22d82bd2
diff -r b84310cad4b3 -r 48e4876a3868 main.cpp
--- a/main.cpp	Fri Apr 17 18:34:17 2015 +0000
+++ b/main.cpp	Sat Oct 29 12:19:28 2016 +0000
@@ -1,24 +1,45 @@
-/** Ultraschall Abstandsmesser 
- */
 #include "mbed.h"
-#include "ultrasonic.h"
+#include "OLEDDisplay.h" 
+ 
+DigitalIn echo( A4 );
+DigitalOut trigger( A5 );
+Timer t;
+OLEDDisplay oled;
  
- void dist(int distance)
+float i;
+ 
+int main() 
 {
-    // Abhandlung der Entfernung
-    printf("Entfernung %dmm\n", distance);
-}
+    t.start();
+    printf(" ===[ Ultrasonic Range ]===");
+ 
+    // OLED Display
+    oled.clear();
  
-ultrasonic mu(D5, D6, .1, 1, &dist);    // setzt den Trigger Pin auf D5, den Echo Pin auf D6
-                                        // liefert all 0.1 Sekunten einen neuen Wert mit einem
-                                        // Timeout von 1 Sekunden. Fuer die Ausgabe des Wertes
-                                        // wird die Funktion dist aufgerufen.
-int main()
-{
-    mu.startUpdates();                  // Start der Abstandsmessung
-    while(1)
+    while (1) 
     {
-        mu.checkDistance();             // Pooling vom Distanzmesser, sollte moeglichst oft erfolgen
-        // weitere Abhandlungen
+        oled.clear();
+        oled.printf( "Ultrasonic Range" );
+
+        // send pulse
+        trigger=1;
+        wait(0.000004);
+        trigger=0;
+ 
+        // wait for the echo line to go high
+        while (!echo);
+ 
+        // measure the length of the pulse
+        t.reset();
+        while (echo);
+        i = t.read_us();
+ 
+        // display result
+        printf("\n\n\rPulselength %6.0f uS",i);
+        oled.printf("\n\rPulselength %6.0f uS",i);
+        i=i/58;
+        printf("\n\n\rDistance %4.0f cm",i);
+        oled.printf("\rDistance %4.0f cm",i);
+        wait(2);
     }
-}         
\ No newline at end of file
+}
\ No newline at end of file