To make the testbed for mbed work with the SRF04 sensor.

Dependencies:   mbed

Fork of TestBed-LCD20x4 by Elmicro Computer

Revision:
1:abf7a830aa39
Parent:
0:7c694e032688
--- a/main.cpp	Tue Oct 11 08:13:19 2011 +0000
+++ b/main.cpp	Mon Dec 16 11:57:45 2013 +0000
@@ -1,32 +1,34 @@
 #include "mbed.h"
-//the library "TextLCD.h" was slightly altered to work with the GDM2004D LCD
 #include "TextLCD.h"
+DigitalIn echo(p18);
+DigitalOut trigger(p17);
+TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);
 
-//the object "lcd" is initialized to act as a TextLCD with 20x4 characters
-TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);
+Timer t;
+float i;
 
 int main() {
-    //each line of the LCD can be accessed directly using the .locate(column, line) function
-    lcd.locate(0,0);
-    lcd.printf("12345678901234567890");
-    lcd.locate(0,1);
-    lcd.printf("UVWXYZabcdefghijklmn");    
-    lcd.locate(0,2);    
-    lcd.printf("ABCDEFGHIJKLMNOPQRST");
-    lcd.locate(0,3);
-    lcd.printf("12345678901234567890");    
-    wait(2);
+        //Testen van het scherm
+    lcd.printf("--UltraSonic Range--");
+    wait(1);
+    lcd.cls();  
     
-    //the LCD is cleared using function .cls()
-    lcd.cls();
-    //a "\n" in a text string causes a line feed
-    lcd.printf("HELLO WORLD\n");
-    //if the end of a line is reached, the text is written to the next line automatically
-    lcd.printf("Testbed for mbed\nLCD example softwarewith altered library");
-    
-    //the endless loop keeps mbed in low power mode
-    while(1)
-    {
-    __WFI();
-    }
+    t.start();
+     while(1) { 
+            //Pulstrein 
+        trigger=1;
+        wait(0.00004);
+        trigger=0;
+        while(!echo);
+        
+        t.reset();
+        while(echo);
+        i=t.read_us();
+        
+        lcd.cls();
+         lcd.printf("Pulse length= \n%6.0f us", i);              
+         i=i/58.479;
+         lcd.printf("\nDistance = %4.1f cm", i);  
+         wait(0.2);
+        }
 }