vehicle detection

Dependencies:   mbed HCSR04 DHT

Revision:
2:74cfa9f8251d
Parent:
1:8711db3189d0
Child:
3:d520a6ecf90c
--- 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);
+   }
+   }