han back
/
CLEO_ULTRASONIC
SMART CLEO Ultrasonic
main.cpp
- Committer:
- SMART_CLEO
- Date:
- 2017-09-28
- Revision:
- 0:e7c4d23dbc05
File content as of revision 0:e7c4d23dbc05:
#include "mbed.h" #include "TextLCD.h" #include "HCSR04.h" PinName pin_ECHO = PB_7; PinName pin_TRIG = PB_10; HCSR04 Ultrasonic(pin_ECHO, pin_TRIG); // rs, rw, e, d0-d3 TextLCD lcd(PB_12, PB_13, PB_14, PB_15, PA_9, PA_10, PA_11); float Ultrasonic_cm(void); int main() { uint16_t dist = 0; lcd.printf(" Ultrasonic\n"); lcd.printf(" Dist : [cm]"); while(1) { dist = Ultrasonic_cm(); lcd.locate(8, 1); lcd.printf("%3d", dist); wait(0.5); } } float Ultrasonic_cm(void) { Ultrasonic.startMeasurement(); while(!Ultrasonic.isNewDataReady()); return Ultrasonic.getDistance_cm(); }