Test
Dependencies: MaxSonar_EZ1_Analog TextLCD mbed
Fork of MaxSonar_EZ1_Analog by
main.cpp@1:7931088c5e05, 2014-07-23 (annotated)
- Committer:
- hasimo
- Date:
- Wed Jul 23 10:33:12 2014 +0000
- Revision:
- 1:7931088c5e05
- Parent:
- 0:9dfac5da16a9
- Child:
- 2:010f6e9e7174
????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:9dfac5da16a9 | 1 | #include "mbed.h" |
hasimo | 1:7931088c5e05 | 2 | #include "TextLCD.h" |
shimniok | 0:9dfac5da16a9 | 3 | |
shimniok | 0:9dfac5da16a9 | 4 | // mbed -> EZ1 |
shimniok | 0:9dfac5da16a9 | 5 | // ----------- |
shimniok | 0:9dfac5da16a9 | 6 | // VOUT -> +5 |
shimniok | 0:9dfac5da16a9 | 7 | // GND -> GND |
shimniok | 0:9dfac5da16a9 | 8 | // p20 -> AN |
hasimo | 1:7931088c5e05 | 9 | |
shimniok | 0:9dfac5da16a9 | 10 | |
hasimo | 1:7931088c5e05 | 11 | TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 |
hasimo | 1:7931088c5e05 | 12 | AnalogIn ain(p15); |
shimniok | 0:9dfac5da16a9 | 13 | |
shimniok | 0:9dfac5da16a9 | 14 | int main() { |
hasimo | 1:7931088c5e05 | 15 | float adc, volts, inches, cm; |
shimniok | 0:9dfac5da16a9 | 16 | |
shimniok | 0:9dfac5da16a9 | 17 | while (1){ |
hasimo | 1:7931088c5e05 | 18 | lcd.locate(0,0); |
shimniok | 0:9dfac5da16a9 | 19 | adc = ain.read(); // read analog as a float |
shimniok | 0:9dfac5da16a9 | 20 | volts = adc * 3.3; // convert to volts |
hasimo | 1:7931088c5e05 | 21 | inches = volts / (3.3 / 512.0); // 3.3V supply: 6.4mV per inch |
hasimo | 1:7931088c5e05 | 22 | cm = inches * 2.54; // inch to cm |
hasimo | 1:7931088c5e05 | 23 | lcd.printf("%8.3f cm\n", cm); |
shimniok | 0:9dfac5da16a9 | 24 | |
hasimo | 1:7931088c5e05 | 25 | wait(0.05); // 20Hz update rate |
shimniok | 0:9dfac5da16a9 | 26 | } |
shimniok | 0:9dfac5da16a9 | 27 | } |
shimniok | 0:9dfac5da16a9 | 28 | |
shimniok | 0:9dfac5da16a9 | 29 |