Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos HCSR04
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "hcsr04.h" 00004 00005 float a=0; 00006 float b=0; 00007 float x=0; 00008 float y=0; 00009 float z=0; 00010 unsigned int dist; 00011 00012 void avanza(float); 00013 void espera(float); 00014 void ireversa(float); 00015 void reversa(float); 00016 void derecha(float); 00017 00018 00019 HCSR04 usensor(p25,p6); 00020 DigitalOut pin1(p21); 00021 DigitalOut pin2(p22); 00022 DigitalOut pin3(p23); 00023 DigitalOut pin4(p24); 00024 00025 int main() { 00026 usensor.start(); 00027 dist=usensor.get_dist_cm(); 00028 00029 if(dist<=10){ 00030 reversa(2); 00031 } 00032 if(dist>10){ 00033 avanza(1); 00034 } 00035 } 00036 00037 00038 //Funciones de control de avance y retroceso del vehículo 00039 void avanza(float a) 00040 { 00041 pin1 = 1; 00042 pin2 = 0; 00043 pin3 = 1; 00044 pin4 = 0; 00045 wait(a); 00046 } 00047 void espera(float b){ 00048 pin1 = 0; 00049 pin2 = 0; 00050 pin3 = 0; 00051 pin4 = 0; 00052 wait(b); 00053 } 00054 void ireversa(float x){ 00055 pin1 = 1; 00056 pin2 = 0; 00057 pin3 = 0; 00058 pin4 = 0; 00059 wait(x); 00060 } 00061 void reversa(float y){ 00062 pin1 = 0; 00063 pin2 = 1; 00064 pin3 = 0; 00065 pin4 = 1; 00066 osDelay(y); 00067 } 00068 void derecha(float z){ 00069 pin1 = 0; 00070 pin2 = 0; 00071 pin3 = 1; 00072 pin4 = 0; 00073 wait(z); 00074 }
Generated on Sun Jul 31 2022 16:20:11 by
