Ejemplo para entender funcionamiento del sensor Ultrasonico HCSR04

Dependencies:   mbed HCSR04

main.cpp

Committer:
lscordovar
Date:
2020-02-04
Revision:
2:287be83ed6a0
Parent:
1:4a5586eb1765
Child:
3:3e528b02b8d7

File content as of revision 2:287be83ed6a0:

#include "mbed.h"
#include "HCSR04.h"     //https://os.mbed.com/users/aralshukaili/code/HCSR04/

HCSR04 sensor(PB_6, PB_7);

DigitalOut GREEN(PD_12);
DigitalOut ORANGE(PD_13);



int main()
{
    while(1) {
        long d = sensor.distance(1);
        printf("Distancia:%d ",sensor.distance(1));

        if(d<=10) {
            GREEN = 0;
            ORANGE = 1;
        }

        if(d>=200) {
            ORANGE = 0;
            GREEN = 1;
        }
        if(d>=11 && d<=39) {
            ORANGE = 0;
            GREEN=0;
        }


    }
}