ver 2 ultrasonic

Dependencies:   mbed mbed-rtos HCSR04

Files at this revision

API Documentation at this revision

Comitter:
oxochimitl
Date:
Mon Mar 11 19:25:58 2019 +0000
Child:
1:a38d3531c822
Commit message:
ver 2

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Mon Mar 11 19:25:58 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/vamgehealthcare11/code/HCSR04/#4b8a22181c7a
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 11 19:25:58 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file