yuki hashimoto / Mbed 2 deprecated MaxSonar_EZ1_Analog

Dependencies:   TextLCD mbed

Dependents:   BodySwap1

Fork of MaxSonar_EZ1_Analog by Michael Shimniok

Files at this revision

API Documentation at this revision

Comitter:
hasimo
Date:
Wed Jul 23 10:33:12 2014 +0000
Parent:
0:9dfac5da16a9
Commit message:
????????????

Changed in this revision

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Jul 23 10:33:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#e4cb7ddee0d3
--- a/main.cpp	Tue Jan 25 00:05:16 2011 +0000
+++ b/main.cpp	Wed Jul 23 10:33:12 2014 +0000
@@ -1,37 +1,28 @@
 #include "mbed.h"
+#include "TextLCD.h"
 
-// MaxSonar EZ1 test program
-// by Michael Shimniok http://www.bot-thoughts.com/
-//
-// Based on datasheet here: http://www.maxbotix.com/uploads/LV-MaxSonar-EZ1-Datasheet.pdf
-// Reads from AN (analog) pin connected to mbed p20, assumes 3.3V supply to EZ1 module.
-//
 // mbed -> EZ1
 // -----------
 // VOUT -> +5
 // GND  -> GND
 // p20  -> AN
-//
+
 
-AnalogIn ain(p20);
-Serial pc(USBTX, USBRX); // tx, rx
+TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
+AnalogIn ain(p15);
 
 int main() {
-    float adc, volts, inches;
-    int feet, in;
-    
-    pc.baud(115200);
+    float adc, volts, inches, cm;
     
     while (1){
+        lcd.locate(0,0);
         adc = ain.read();           // read analog as a float
         volts = adc * 3.3;          // convert to volts
-        inches = volts / 0.0064;    // 3.3V supply: 6.4mV per inch
-        feet = (int) inches / 12;   // inches to feet (trunc)
-        in = (int) inches % 12;     // remainder -> in(ches)
-        
-        pc.printf("%8.2f adc %8.2fV %8.2f in %d'%d\"\n", adc, volts, inches, feet, in);
+        inches = volts / (3.3 / 512.0);    // 3.3V supply: 6.4mV per inch
+        cm = inches * 2.54;    // inch to cm
+        lcd.printf("%8.3f cm\n", cm);
 
-        wait(0.05);                 // 20Hz update rate ; note we aren't truly synchronized to the device or anything...   
+        wait(0.05);                 // 20Hz update rate
     }
 }