Obstacle avoidance using ultrasonic sensor with FRDM K64F and S32K144
Fork of hcsr04-test-1 by
Revision 2:74cfa9f8251d, committed 2018-03-29
- Comitter:
- saranyachitta
- Date:
- Thu Mar 29 18:40:24 2018 +0000
- Parent:
- 1:8711db3189d0
- Commit message:
- Obstacle avoidance using ultrasonic sensor
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8711db3189d0 -r 74cfa9f8251d main.cpp --- a/main.cpp Fri Mar 23 22:23:48 2018 +0000 +++ b/main.cpp Thu Mar 29 18:40:24 2018 +0000 @@ -1,7 +1,8 @@ #include "mbed.h" #include "HCSR04.h" - Serial pc(USBTX,USBRX); // Create a serial connection to pc through the mbed USB cable + Serial pc(USBTX,USBRX); + Serial device(PTC17,NC); // Create a serial connection to pc through the mbed USB cable void dist(int distance) { @@ -14,6 +15,8 @@ int main() { + pc.baud(115200); +device.baud(115200); wait_ms(4000); int echoVal = sensor.echo_duration(); @@ -27,10 +30,18 @@ Green=1; wait(.2); } - pc.printf("%d \n\r",a); - wait_ms(50); + if(a > 1 and a <= 170) + { + device.printf("1"); + pc.printf("Object Detected: Value = 0 \r\n"); + wait(0.5); } -} - - - + else + { + device.printf("0"); + pc.printf("No object detected: Value = 1 \r\n"); + wait(0.5); + } + wait_ms(1000); + } + }