vehicle detection

Dependencies:   mbed HCSR04 DHT

main.cpp

Committer:
khp007
Date:
2018-03-23
Revision:
1:8711db3189d0
Parent:
0:a804a58b647b
Child:
2:74cfa9f8251d

File content as of revision 1:8711db3189d0:

#include "mbed.h"
#include "HCSR04.h"

 Serial pc(USBTX,USBRX);     // Create a serial connection to pc through the mbed USB cable

 void dist(int distance)
{
    //put code here to execute when the distance has changed
    printf("Distance %d mm\r\n", distance);
}

HCSR04 sensor(D8,D9);
DigitalOut Green(LED2);

int main()
{
   wait_ms(4000);

int echoVal = sensor.echo_duration();
   Green = 1;
   
    while(1){
    int a = sensor.echo_duration();
    if (a - echoVal > 75 || echoVal - a > 75){
        Green=0;
        wait(.2);
        Green=1;
        wait(.2);
    }
    pc.printf("%d \n\r",a);
    wait_ms(50);
    }
}