Luis Silvio Cordova Rivadeneira
/
Ultrasonic_Sensor
Ejemplo para entender funcionamiento del sensor Ultrasonico HCSR04
main.cpp
- Committer:
- lscordovar
- Date:
- 2020-02-05
- Revision:
- 3:3e528b02b8d7
- Parent:
- 2:287be83ed6a0
File content as of revision 3:3e528b02b8d7:
#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); Serial device(PA_2,PA_3); int main() { device.baud(115200); device.printf("Start\n"); while(1) { long d = sensor.distance(1); device.printf("Distancia:%i \r\n",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; } wait(0.1); } }