Sensors with Distance
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of LPC1768_HCSR04_HelloWorld by
Diff: main.cpp
- Revision:
- 3:65b2a102e23e
- Parent:
- 2:3566c2d1e86b
diff -r 3566c2d1e86b -r 65b2a102e23e main.cpp --- a/main.cpp Tue Sep 13 18:16:42 2016 +0000 +++ b/main.cpp Wed Feb 28 09:55:03 2018 +0000 @@ -1,10 +1,14 @@ #include "mbed.h" #include "ultrasonic.h" + +Serial pc(USBTX, USBRX); void dist(int distance) { //put code here to execute when the distance has changed - printf("Distance %d mm\r\n", distance); + float feet_distance = distance * 0.00328084f; + pc.printf("Distance %d mm\rt\n", distance); + pc.printf("Distance %.5f ft\r\n", feet_distance); } ultrasonic mu(p6, p7, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9