ver 2 ultrasonic
Dependencies: mbed mbed-rtos HCSR04
Diff: main.cpp
- Revision:
- 0:de082043a69d
- Child:
- 1:a38d3531c822
diff -r 000000000000 -r de082043a69d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 11 19:25:58 2019 +0000 @@ -0,0 +1,69 @@ +#include "mbed.h" +#include "hcsr04.h" +float a=0; +float b=0; +float x=0; +float y=0; +float z=0; +unsigned int dist; + +void avanza(float); +void espera(float); +void ireversa(float); +void reversa(float); +void derecha(float); + + +HCSR04 usensor(p25,p6); +DigitalOut pin1(p21); +DigitalOut pin2(p22); +DigitalOut pin3(p23); +DigitalOut pin4(p24); + +int main() { + usensor.start(); + dist=usensor.get_dist_cm(); + + if(dist<=10){ + reversa(2); + } + if(dist>10){ + avanza(1); + } + } +void avanza(float a) + { + pin1 = 1; + pin2 = 0; + pin3 = 1; + pin4 = 0; + wait(a); + } +void espera(float b){ + pin1 = 0; + pin2 = 0; + pin3 = 0; + pin4 = 0; + wait(b); + } +void ireversa(float x){ + pin1 = 1; + pin2 = 0; + pin3 = 0; + pin4 = 0; + wait(x); + } +void reversa(float y){ + pin1 = 0; + pin2 = 1; + pin3 = 0; + pin4 = 1; + wait(y); + } +void derecha(float z){ + pin1 = 0; + pin2 = 0; + pin3 = 1; + pin4 = 0; + wait(z); + } \ No newline at end of file