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 "TextLCD.h" 00003 00004 00005 AnalogIn Vin(PTC2); 00006 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00007 DigitalOut l1(LED1); 00008 DigitalOut l2(LED2); 00009 DigitalIn b1(PTC12); 00010 DigitalIn b2(PTC13); 00011 DigitalIn b3(PTC16); 00012 int c1=0x0E,sp=0,kp=0,ki=0,kd=0,k=1; 00013 int bandera; 00014 Timer t; 00015 float tiempo; 00016 00017 int main() 00018 { 00019 lcd.cls(); 00020 lcd.writeCommand(c1); 00021 //Se localiza las variables del PID 00022 lcd.locate(9,0); //posición 2 00023 lcd.printf("Kp=%d",kp); 00024 lcd.locate(0,1);//posición 3 00025 lcd.printf("Ki=%d",ki); 00026 lcd.locate(9,1);//posición 4 00027 lcd.printf("Kd=%d",kd); 00028 lcd.locate(0,0);//posición 1 00029 lcd.printf("Sp=%d",sp); 00030 00031 while(1) 00032 { 00033 while(k==1) //posición 1 00034 { 00035 if(b1 & sp<=1000) 00036 { 00037 l1 = !l1; 00038 if(bandera==0) 00039 { 00040 t.start(); //inicia el conteo del tiempo que se mantiene pulsado el botón. 00041 bandera=1; 00042 } 00043 wait(0.50); 00044 if(b1 & sp<=1000) //Incremento hasta un límite de 1000 00045 { 00046 tiempo=t.read(); //lectura del tiempo 00047 //si tiempo es menor a 5 segundos, incremente de 1 en 1. 00048 if(tiempo<5) 00049 { 00050 sp++; 00051 lcd.locate(3,0); 00052 lcd.printf("%d",sp); 00053 } 00054 //si tiempo está entre 5 y 10 segundos, incremente de 10 en 10. 00055 if(tiempo>=5 & tiempo<10) 00056 { 00057 sp+=10; 00058 lcd.locate(3,0); 00059 lcd.printf("%d",sp); 00060 } 00061 00062 //si tiempo es mayor a 10 segundos, incremente de 100 en 100. 00063 if(tiempo>=10) 00064 { 00065 sp+=100; 00066 lcd.locate(3,0); 00067 lcd.printf("%d",sp); 00068 } 00069 } 00070 else 00071 { 00072 t.start(); 00073 bandera=0;//detener el conteo del tiempo 00074 } 00075 } 00076 00077 00078 if(b2 & sp>=1) //bótón decremento 00079 { 00080 l2 = !l2; 00081 00082 if(bandera==0) 00083 { 00084 t.start(); 00085 bandera=1; 00086 } 00087 00088 wait(0.50); 00089 00090 if(b2 & sp>=1) 00091 { 00092 tiempo=t.read(); 00093 00094 //si tiempo es menor de 5 segundos, decremento de 1 en 1. 00095 if(tiempo<5) 00096 { 00097 sp--; 00098 lcd.locate(3,0); 00099 lcd.printf("%d",sp); 00100 } 00101 00102 //si tiempo está entre 5 y 10 segundos, decremento de 10 en 10. 00103 if(tiempo>=5 & tiempo<10) 00104 { 00105 sp-=10; 00106 lcd.locate(3,0); 00107 lcd.printf("%d",sp); 00108 } 00109 00110 //si tiempo es mayor a 10 segundos, decremente de 100 en 100. 00111 if(tiempo>=10) 00112 { 00113 sp-=100; 00114 lcd.locate(3,0); 00115 lcd.printf("%d",sp); 00116 } 00117 } 00118 else 00119 { 00120 t.start(); 00121 bandera=0; 00122 } 00123 } 00124 if (b3) //al oprimir el botón 3, cambia a la siguiente posición. 00125 { 00126 k+=1; 00127 wait(0.25); 00128 lcd.locate(12,0);lcd.printf("%d",kp); 00129 } 00130 00131 } 00132 00133 while(k==2)//posición 2 00134 { 00135 if(b1 & kp<=1000) 00136 { 00137 l1 = !l1; 00138 if(bandera==0) 00139 { 00140 t.start(); 00141 bandera=1; 00142 } 00143 wait(0.50); 00144 00145 if(b1 & kp<=1000) 00146 { 00147 tiempo=t.read(); 00148 00149 if(tiempo<5) 00150 { 00151 kp++; 00152 lcd.locate(12,0); 00153 lcd.printf("%d",kp); 00154 } 00155 00156 if(tiempo>=5 & tiempo<10) 00157 { 00158 kp+=10; 00159 lcd.locate(12,0); 00160 lcd.printf("%d",kp); 00161 } 00162 00163 if(tiempo>=10) 00164 { 00165 kp+=100; 00166 lcd.locate(12,0); 00167 lcd.printf("%d",kp); 00168 } 00169 } 00170 else 00171 { 00172 t.start(); 00173 bandera=0; 00174 } 00175 } 00176 if(b2 & kp>=1) 00177 { 00178 l2 = !l2; 00179 00180 if(bandera==0) 00181 { 00182 t.start(); 00183 bandera=1; 00184 } 00185 wait(0.50); 00186 00187 if(b2 & kp>=1) 00188 { 00189 tiempo=t.read(); 00190 00191 if(tiempo<5) 00192 { 00193 kp--; 00194 lcd.locate(12,0); 00195 lcd.printf("%d",kp); 00196 } 00197 00198 if(tiempo>=5 & tiempo<10) 00199 { 00200 kp-=10; 00201 lcd.locate(12,0); 00202 lcd.printf("%d",kp); 00203 } 00204 00205 if(tiempo>=10) 00206 { 00207 kp-=100; 00208 lcd.locate(12,0); 00209 lcd.printf("%d",kp); 00210 } 00211 } 00212 else 00213 { 00214 t.start(); 00215 bandera=0; 00216 } 00217 } 00218 if (b3) 00219 { 00220 k+=1; 00221 wait(0.25); 00222 lcd.locate(3,1); lcd.printf("%d",ki); 00223 } 00224 } 00225 00226 00227 while(k==3) //posición 3 00228 { 00229 if(b1 & ki<=1000) 00230 { 00231 l1 = !l1; 00232 00233 if(bandera==0) 00234 { 00235 t.start(); 00236 bandera=1; 00237 } 00238 wait(0.50); 00239 00240 if(b1 & ki<=1000) 00241 { 00242 tiempo=t.read(); 00243 00244 if(tiempo<5) 00245 { 00246 ki++; 00247 lcd.locate(3,1); 00248 lcd.printf("%d",ki); 00249 } 00250 00251 if(tiempo>=5 & tiempo<10) 00252 { 00253 ki+=10; 00254 lcd.locate(3,1); 00255 lcd.printf("%d",ki); 00256 } 00257 00258 if(tiempo>=10) 00259 { 00260 ki+=100; 00261 lcd.locate(3,1); 00262 lcd.printf("%d",ki); 00263 } 00264 } 00265 00266 else 00267 { 00268 t.start(); 00269 bandera=0; 00270 } 00271 } 00272 00273 if(b2 & ki>=1) 00274 { 00275 l2 = !l2; 00276 if(bandera==0) 00277 { 00278 t.start(); 00279 bandera=1; 00280 } 00281 wait(0.50); 00282 00283 if(b2 & ki>=1) 00284 { 00285 tiempo=t.read(); 00286 00287 if(tiempo<5) 00288 { 00289 ki--; 00290 lcd.locate(3,1); 00291 lcd.printf("%d",ki); 00292 } 00293 00294 if(tiempo>=5 & tiempo<10) 00295 { 00296 ki-=10; 00297 lcd.locate(3,1); 00298 lcd.printf("%d",ki); 00299 } 00300 00301 if(tiempo>=10) 00302 { 00303 ki-=100; 00304 lcd.locate(3,1); 00305 lcd.printf("%d",ki); 00306 } 00307 } 00308 else 00309 { 00310 t.start(); 00311 bandera=0; 00312 } 00313 } 00314 if (b3) 00315 { 00316 k+=1; 00317 wait(0.25); 00318 lcd.locate(12,1); lcd.printf("%d",kd); 00319 } 00320 } 00321 00322 while(k==4) //posición 4 00323 { 00324 if(b1 & kd<=1000) 00325 { 00326 l1 = !l1; 00327 if(bandera==0) 00328 { 00329 t.start(); 00330 bandera=1; 00331 } 00332 00333 wait(0.50); 00334 00335 if(b1 & kd<=1000) 00336 { 00337 tiempo=t.read(); 00338 00339 if(tiempo<5) 00340 { 00341 kd++; 00342 lcd.locate(12,1); 00343 lcd.printf("%d",kd); 00344 } 00345 00346 if(tiempo>=5 & tiempo<10) 00347 { 00348 kd+=10; 00349 lcd.locate(12,1); 00350 lcd.printf("%d",kd); 00351 } 00352 00353 if(tiempo>=10) 00354 { 00355 kd+=100; 00356 lcd.locate(12,1); 00357 lcd.printf("%d",kd); 00358 } 00359 } 00360 else 00361 { 00362 t.start(); 00363 bandera=0; 00364 } 00365 } 00366 00367 00368 if(b2 & kd>=1) 00369 { 00370 l2 = !l2; 00371 00372 if(bandera==0) 00373 { 00374 t.start(); 00375 bandera=1; 00376 } 00377 wait(0.50); 00378 00379 if(b2 & kd>=1) 00380 { 00381 tiempo=t.read(); 00382 00383 if(tiempo<5) 00384 { 00385 kd--; 00386 lcd.locate(12,1); 00387 lcd.printf("%d",kd); 00388 } 00389 00390 if(tiempo>=5 & tiempo<10) 00391 { 00392 kd-=10; 00393 lcd.locate(12,1); 00394 lcd.printf("%d",kd); 00395 } 00396 00397 if(tiempo>=10) 00398 { 00399 kd-=100; 00400 lcd.locate(12,1); 00401 lcd.printf("%d",kd); 00402 } 00403 } 00404 else 00405 { 00406 t.start(); 00407 bandera=0; 00408 } 00409 } 00410 00411 if (b3) 00412 { 00413 k=1; 00414 wait(0.25); 00415 lcd.locate(3,0); 00416 lcd.printf("%d",sp); 00417 } 00418 00419 } 00420 continue; 00421 } 00422 00423 } 00424
Generated on Tue Jul 12 2022 21:35:23 by
1.7.2