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 Servo HC_SR04_Ultrasonic_Library
main.cpp
00001 #include "mbed.h" 00002 #include "ultrasonic.h" 00003 #include "Servo.h" 00004 00005 00006 Serial pc(USBTX,USBRX); 00007 DigitalOut L(LED2); 00008 DigitalOut led1(PTC1); 00009 DigitalOut led2(PTC2); 00010 PwmOut buzzer(A0); 00011 00012 char c; 00013 int a,i=0; 00014 int conteo=0; 00015 00016 //SERVOMOTRO 00017 Servo myservo2(PTD4); 00018 00019 00020 void dist(int distance){ 00021 a=distance; 00022 printf("Distance changed to %dmm\r\n", distance); 00023 } 00024 00025 //ULTRASONICO 00026 ultrasonic mu(D8, D9, .1, 1, &dist); 00027 00028 int main(){ 00029 mu.startUpdates(); 00030 myservo2.calibrate(0.00095, 180.0); 00031 myservo2.write(0); 00032 L=1; 00033 00034 while(1){ 00035 mu.checkDistance(); 00036 //pc.printf("Active\n"); 00037 00038 //DETECCION PUERTO SERIE 00039 while(pc.readable()) { 00040 c = pc.getc(); 00041 } 00042 00043 //ENCENDIDO 00044 if(c == 's'){ 00045 00046 L=0; 00047 led1=1; 00048 led2=1; 00049 pc.printf("Active\n"); 00050 00051 for(i=0; i<200; i++) { 00052 myservo2 = i/100.0; 00053 conteo=conteo+1; 00054 wait(0.02); 00055 } 00056 00057 for(i=200; i>0; i--) { 00058 myservo2 = i/100.0; 00059 conteo=conteo-1; 00060 wait(0.02); 00061 } 00062 wait(2); 00063 00064 00065 00066 if(a>=1200){ 00067 L=0; 00068 led1=1; 00069 led2=1; 00070 printf("Conectado \n\r"); 00071 pc.printf("HOLA\n"); 00072 buzzer.period(1.0/969.0); 00073 buzzer = 261.0f; 00074 wait(0.5); 00075 led1=0; 00076 led2=0; 00077 buzzer.period(1.0/800.0); 00078 buzzer = 300.0f; 00079 buzzer.period(1.0/800.0); 00080 buzzer = 400.0f; 00081 wait(0.5); 00082 led1=1; 00083 led2=1; 00084 L=1; 00085 00086 } 00087 } 00088 00089 //APAGADO 00090 if(c =='c') { 00091 00092 if(a<=1200){ 00093 printf("Conectado \n\r"); 00094 pc.printf("CHAO\n"); 00095 L=1; 00096 buzzer=0.0; 00097 myservo2.write(180); 00098 led1=0; 00099 led2=0; 00100 } 00101 } 00102 00103 } 00104 }
Generated on Thu Jul 14 2022 13:51:25 by
1.7.2