Trying to use maxsonar ez ae mb1300 with lpc1768

Dependencies:   mbed

Fork of MaxSonar_EZ1_Analog by Michael Shimniok

Committer:
pinguimmaxi
Date:
Fri May 05 11:27:34 2017 +0000
Revision:
1:d91cac1628f9
Parent:
0:9dfac5da16a9
hi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:9dfac5da16a9 1 #include "mbed.h"
shimniok 0:9dfac5da16a9 2
shimniok 0:9dfac5da16a9 3 // MaxSonar EZ1 test program
shimniok 0:9dfac5da16a9 4 // by Michael Shimniok http://www.bot-thoughts.com/
shimniok 0:9dfac5da16a9 5 //
shimniok 0:9dfac5da16a9 6 // Based on datasheet here: http://www.maxbotix.com/uploads/LV-MaxSonar-EZ1-Datasheet.pdf
shimniok 0:9dfac5da16a9 7 // Reads from AN (analog) pin connected to mbed p20, assumes 3.3V supply to EZ1 module.
shimniok 0:9dfac5da16a9 8 //
shimniok 0:9dfac5da16a9 9 // mbed -> EZ1
shimniok 0:9dfac5da16a9 10 // -----------
shimniok 0:9dfac5da16a9 11 // VOUT -> +5
shimniok 0:9dfac5da16a9 12 // GND -> GND
shimniok 0:9dfac5da16a9 13 // p20 -> AN
shimniok 0:9dfac5da16a9 14 //
shimniok 0:9dfac5da16a9 15
shimniok 0:9dfac5da16a9 16 AnalogIn ain(p20);
shimniok 0:9dfac5da16a9 17 Serial pc(USBTX, USBRX); // tx, rx
shimniok 0:9dfac5da16a9 18
shimniok 0:9dfac5da16a9 19 int main() {
pinguimmaxi 1:d91cac1628f9 20 float adc, volts, cent;
shimniok 0:9dfac5da16a9 21
pinguimmaxi 1:d91cac1628f9 22 pc.baud(9600);
shimniok 0:9dfac5da16a9 23
shimniok 0:9dfac5da16a9 24 while (1){
shimniok 0:9dfac5da16a9 25 adc = ain.read(); // read analog as a float
shimniok 0:9dfac5da16a9 26 volts = adc * 3.3; // convert to volts
pinguimmaxi 1:d91cac1628f9 27 cent = volts / 0.0032; // 3.3V supply: 3.2mV per centimeter
shimniok 0:9dfac5da16a9 28
pinguimmaxi 1:d91cac1628f9 29 pc.printf("%f adc - %f cent \n", adc, cent);
pinguimmaxi 1:d91cac1628f9 30 wait(2); // 20Hz update rate ; note we aren't truly synchronized to the device or anything...
shimniok 0:9dfac5da16a9 31 }
shimniok 0:9dfac5da16a9 32 }
shimniok 0:9dfac5da16a9 33
shimniok 0:9dfac5da16a9 34