This program demonstrates how to use ultrasonic sensor and how to display measured distance on both 16x2 LCD and seven segment display.

Dependencies:   HCSR04 SevenSegmentDisplay TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
triple
Date:
Fri Aug 22 19:24:38 2014 +0000
Commit message:
FIN

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
SevenSegmentDisplay.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.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.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 153f3254e133 HCSR04.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Fri Aug 22 19:24:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
diff -r 000000000000 -r 153f3254e133 SevenSegmentDisplay.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SevenSegmentDisplay.lib	Fri Aug 22 19:24:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/jf1452/code/SevenSegmentDisplay/#cb7339a2e196
diff -r 000000000000 -r 153f3254e133 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Aug 22 19:24:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 153f3254e133 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 22 19:24:38 2014 +0000
@@ -0,0 +1,37 @@
+/*******************************************************************************
+* This program demonstrates how to use ultrasonic sensor HCSR04 and  how       *
+* to display measured distance on both 16x2 LCD and seven segment display      *                                                                           *
+*******************************************************************************/
+#include "mbed.h"
+#include "hcsr04.h"
+#include "TextLCD.h"
+#include "SevenSegmentDisplay.h"
+
+// Options to instantiate SevenSegmentDisplay are...
+// FADE: causes the number changes to fade in smoothly
+// INSTANT: causes the an instant number change
+// + FLASH: causes the display to flash
+SevenSegmentDisplay segmentled( FADE );
+// p1_27, p1_26
+HCSR04  usensor(p9,p10);// trigger, echo
+// p0_9, p0_8, p1_29, p1_22, p1_21, p1_20
+TextLCD lcd(p11, p12, p15, p16, p17, p18, TextLCD::LCD16x2); // rs, e, d4-d7
+
+unsigned int dist;
+int main()
+{       
+    while(1) {
+        usensor.start();
+        wait_ms(500); 
+        dist=usensor.get_dist_cm();
+        lcd.cls();
+        lcd.locate(0,0);
+        lcd.printf("cm:%ld",dist );
+        if(dist<100){
+            segmentled.DisplayInt(dist);
+        }
+        else {
+            segmentled.DisplayInt(99);
+        }
+    }
+}
diff -r 000000000000 -r 153f3254e133 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 22 19:24:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file