Test

Dependencies:   MaxSonar_EZ1_Analog TextLCD mbed

Fork of MaxSonar_EZ1_Analog by yuki hashimoto

Revision:
1:7931088c5e05
Parent:
0:9dfac5da16a9
Child:
2:010f6e9e7174
--- 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
     }
 }