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.
main.cpp
00001 #include "mbed.h" 00002 #include "string" 00003 #include "mbed.h" 00004 #include "sstream" 00005 #include <string> 00006 #include "TextLCD.h" 00007 00008 TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2);// Rs, E, d4, d5, d6, d7, RW=GND 00009 Serial pc(USBTX,USBRX); 00010 DigitalIn pulso(PTC5); 00011 DigitalOut right(PTC7); 00012 DigitalOut left(PTC0); 00013 DigitalIn start(PTC3),finish(PTC7); 00014 Timer Timer1; 00015 Ticker rampa; 00016 BusOut step_secuence(PTB0,PTB1,PTB2,PTB3); 00017 int rea,ns; 00018 string cadena; 00019 using namespace std; 00020 void velocidad(int a,float ad); 00021 int dist(char datos[5]); 00022 PwmOut l1(PTB3),l2(PTC2); 00023 int selec; 00024 float cambio; 00025 float rpm=0,auxrpm=0; 00026 int contador=0; 00027 int distancia=0,disa=0; 00028 int second=0; 00029 bool antirebote=false; 00030 int recorrido=0,rpm1=0; 00031 char cade; 00032 bool bit=false; 00033 int velram=20; 00034 float tiempoe=0; 00035 int angulo=0; 00036 //using namespace boost; 00037 float h; 00038 void inicio(){ 00039 while(1){ 00040 if(start==0){ 00041 break; 00042 } 00043 velocidad(2,0.05); 00044 } 00045 } 00046 void rampa1(){ 00047 lcd.cls(); 00048 lcd.locate(0,1); 00049 lcd.printf("millos"); 00050 lcd.locate(0,1); 00051 if(second>0){ 00052 velram=velram-1; 00053 if( velram <= 1){ 00054 velram=1; 00055 } 00056 // if(bit){ 00057 00058 } 00059 } 00060 00061 int main(){ 00062 velocidad(0,0); 00063 second=0; 00064 velocidad(0,0); 00065 selec=1; 00066 rpm1=40; 00067 lcd.printf("esta en los extremos"); 00068 int red=0; 00069 char buffer[15],aux[4]; 00070 rampa.attach(&rampa1,0.5); 00071 while(1){ 00072 00073 if(pc.readable()){// captura string 00074 00075 pc.gets(buffer,15); 00076 buffer[0]=' '; 00077 // cade=buffer[1]; 00078 00079 aux[1]=buffer[1]; 00080 aux[2]=buffer[2]; 00081 aux[3]=buffer[3]; 00082 second=dist(aux); 00083 aux[1]=buffer[4]; 00084 aux[2]=buffer[5]; 00085 aux[3]=buffer[6]; 00086 rpm1=dist(aux); 00087 aux[1]=buffer[7]; 00088 aux[2]=buffer[8]; 00089 aux[3]=buffer[9]; 00090 distancia=dist(aux); 00091 aux[1]=buffer[10]; 00092 aux[2]=buffer[11]; 00093 aux[3]=buffer[12]; 00094 angulo=dist(aux); 00095 if(distancia >0){ 00096 distancia=distancia*50; 00097 } 00098 if(second<1){ 00099 velram=second*2; 00100 } 00101 if(rpm1>45){ 00102 00103 rpm1=40;} 00104 } 00105 if(distancia>0){ 00106 bit=true; 00107 } 00108 00109 00110 if((contador<distancia)&&(distancia>0)){ 00111 auxrpm=(float(60*velram))/(float(rpm1*256)); 00112 velocidad(selec,auxrpm); 00113 } 00114 00115 if((contador==distancia)&&(distancia>0)){ 00116 distancia=0; 00117 contador=0; 00118 rpm1=0; 00119 second=0; 00120 // bit=false; 00121 } 00122 00123 00124 if(cade=='d'){ 00125 selec=1; 00126 00127 } 00128 if (cade=='i'){ 00129 selec=2; 00130 00131 00132 } 00133 if(cade=='n'){selec=0; 00134 } 00135 00136 00137 pc.printf(" v %d , %d ,%d ,%c , %.5f",velram,rpm1,distancia,cade,auxrpm); 00138 00139 00140 } 00141 00142 } 00143 00144 void velocidad(int a ,float ad){ 00145 switch (a){ 00146 case 0: 00147 lcd.cls(); 00148 lcd.locate(0,0); 00149 lcd.printf("%d mm",distancia); 00150 lcd.locate(0,1); 00151 lcd.printf(" V :%.2f rpm",rpm); 00152 l1=0; 00153 l2=0; 00154 00155 break; 00156 case 1: 00157 lcd.cls(); 00158 lcd.locate(0,0); 00159 lcd.printf("izquierda"); 00160 for( int P=0;P<=3;P++){ 00161 contador=contador+1; 00162 switch (P) { 00163 case 0: 00164 step_secuence=0b01; 00165 break; 00166 case 1: 00167 step_secuence=0b10; 00168 break; 00169 case 2: 00170 step_secuence=0b100; 00171 break; 00172 case 3: 00173 step_secuence=0b1000; 00174 break; 00175 00176 } 00177 wait(ad); 00178 } 00179 00180 /* lcd.cls(); 00181 lcd.locate(0,0); 00182 lcd.printf("%d mm",distancia); 00183 lcd.locate(0,1); 00184 lcd.printf(" V :%.2f rpm",rpm); 00185 l1.write(ad); 00186 00187 l2=0;*/ 00188 break; 00189 case 2: 00190 lcd.cls(); 00191 lcd.locate(0,0); 00192 lcd.printf("derecha"); 00193 for( int b=3;b>=0;b--){ 00194 contador=contador+1; 00195 switch (b) { 00196 case 0: 00197 step_secuence=0b01; 00198 break; 00199 case 1: 00200 step_secuence=0b10; 00201 break; 00202 case 2: 00203 step_secuence=0b100; 00204 break; 00205 case 3: 00206 step_secuence=0b1000; 00207 break; 00208 00209 } 00210 wait(ad); 00211 } 00212 00213 /*lcd.cls(); 00214 lcd.locate(0,0); 00215 lcd.printf("%d mm",distancia); 00216 lcd.locate(0,1); 00217 lcd.printf("%.2f rpm",rpm); 00218 00219 l2.write(ad); 00220 l1=0;*/ 00221 break; 00222 00223 } 00224 00225 } 00226 00227 int dist(char datos[4]){ 00228 int numero=0,contador=0; 00229 char c=' '; 00230 for(int i = 4;i >= 0;i --){ 00231 c=datos[i]; 00232 //pc.putc(c); 00233 if(c=='0'){contador=contador+1; } 00234 if(c=='1'){ 00235 contador=contador+1; 00236 if(contador==1){numero=numero+1;} 00237 if(contador==2){numero=numero+10;} 00238 if(contador==3){numero=numero+100;} } 00239 if(c=='2'){ 00240 contador=contador+1; 00241 if(contador==1){numero=numero+2;} 00242 if(contador==2){numero=numero+20;} 00243 if(contador==3){numero=numero+200;} } 00244 if(c=='3'){ 00245 contador=contador+1; 00246 if(contador==1){numero=numero+3;} 00247 if(contador==2){numero=numero+30;} 00248 if(contador==3){numero=numero+300;} } 00249 if(c=='4'){ 00250 contador=contador+1; 00251 if(contador==1){numero=numero+4;} 00252 if(contador==2){numero=numero+40;} 00253 if(contador==3){numero=numero+400;} } 00254 if(c=='5'){ 00255 contador=contador+1; 00256 if(contador==1){numero=numero+5;} 00257 if(contador==2){numero=numero+50;} 00258 if(contador==3){numero=numero+500;} } 00259 if(c=='6'){ 00260 contador=contador+1; 00261 if(contador==1){numero=numero+6;} 00262 if(contador==2){numero=numero+60;} 00263 if(contador==3){numero=numero+600;} } 00264 if(c=='7'){ 00265 contador=contador+1; 00266 if(contador==1){numero=numero+7;} 00267 if(contador==2){numero=numero+70;} 00268 if(contador==3){numero=numero+700;} } 00269 if(c=='8'){ 00270 contador=contador+1; 00271 if(contador==1){numero=numero+8;} 00272 if(contador==2){numero=numero+80;} 00273 if(contador==3){numero=numero+800;} } 00274 if(c=='9'){ 00275 contador=contador+1; 00276 if(contador==1){numero=numero+9;} 00277 if(contador==2){numero=numero+90;} 00278 if(contador==3){numero=numero+900;} } 00279 00280 } 00281 return numero; 00282 }
Generated on Thu Aug 4 2022 17:47:26 by
1.7.2