Demo program for the Parallax Laser Range Finder

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Sun Nov 06 02:08:57 2011 +0000
Commit message:

Changed in this revision

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 ccc26a94788d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Nov 06 02:08:57 2011 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+//Demo program for the Parallax Laser Range Finder
+//
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+Serial lrf(p9,p10);
+
+int main() {
+    int mm_range=0;
+    char lrfchar=0;
+
+//Print prompt
+    pc.printf("\f\nLaser Range Finder demo program\n\r");
+//Delay for lrf power on startup
+    wait(2.5);
+    lrf.baud(115200);
+
+// lrf autobaud setup
+    do {
+        lrf.putc('U');
+        pc.putc('.');
+        wait(.2);
+        if (lrf.readable()) lrfchar = lrf.getc();
+    } while (lrfchar != ':');
+    pc.printf("\n\r");
+    // clear out any extra characters - just in case
+    while (lrf.readable()) {
+        lrfchar = lrf.getc();
+    }
+
+
+// Loop taking range readings forever
+    while (1) {
+        myled=1;
+        lrf.putc('B'); //Take Binary range reading
+        // read in the four bytes for the range in mm (MSB first)
+        mm_range=0;
+        mm_range=lrf.getc();
+        mm_range=(mm_range<<8)|lrf.getc();
+        mm_range=(mm_range<<8)|lrf.getc();
+        mm_range=(mm_range<<8)|lrf.getc();
+        myled=0;
+        //eat CR & ":" command prompt
+        do {
+            lrfchar=lrf.getc();
+        } while (lrfchar != ':');
+        //Display readings on PC Virtual Com port via USB cable
+        pc.printf("Range is %d mm\n\r",mm_range);
+    }
+}
diff -r 000000000000 -r ccc26a94788d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Nov 06 02:08:57 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912