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: Debounced TextLCDm mbed
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 #include "DebouncedIn.h" 00004 00005 TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7.. Nota: No se quiere función de lectura, luego ese puerto a tierra. 00006 //lectura=1, escritura=0 00007 00008 //Aumento en rampa de Sp, Kp, Ki, Kd 00009 PwmOut rled(LED_RED); 00010 00011 DebouncedIn next(PTE2); 00012 DebouncedIn up(PTE3); 00013 DebouncedIn down(PTE4); 00014 00015 Timer timer1; 00016 00017 int C1=0x0F; 00018 int i,j,k,l; 00019 00020 int main() { 00021 00022 int c; 00023 c=0; 00024 00025 lcd.cls(); 00026 lcd.locate(0,0); 00027 lcd.printf("sp:%d",i); 00028 lcd.locate(8,0); 00029 lcd.printf("kp:%d",j); 00030 lcd.locate(0,1); 00031 lcd.printf("ki:%d",k); 00032 lcd.locate(8,1); 00033 lcd.printf("kd:%d",l); 00034 00035 //SP 00036 00037 while (1){ 00038 00039 if (next.falling()){ 00040 c++; 00041 } 00042 00043 //Salto a SP 00044 if (c==0){ 00045 00046 lcd.locate(3,0); 00047 lcd.putc(0xFE); 00048 lcd.writeCommand(C1); 00049 lcd.locate(3,0); 00050 lcd.printf("%d",i); 00051 00052 while(c==0){ 00053 00054 //espacio de trabajo 00055 00056 if(up.falling()||down.falling()){ 00057 timer1.start(); 00058 00059 while(up==0||down==0){ 00060 if(up==1&&down==1){ 00061 timer1.stop(); 00062 timer1.reset(); 00063 } 00064 if (timer1.read()>0&&timer1.read()<=5&&up==0&&i>=0&&i<=9999) { 00065 ++i; 00066 wait(0.1); 00067 } 00068 if (timer1.read()>0&&timer1.read()<=5&&down==0&&i>=0&&i<=9999) { 00069 --i; 00070 wait(0.1); 00071 } 00072 00073 if (timer1.read()>5&&timer1.read()<=10&&up==0&&i>=0&&i<=9999) { 00074 i+=5; 00075 wait(0.1/5); 00076 } 00077 00078 if (timer1.read()>5&&timer1.read()<=10&&down==0&&i>=0&&i<=9999) { 00079 i-=5; 00080 wait(0.1/5); 00081 } 00082 00083 00084 if (timer1.read()>10&&timer1.read()<=100&&up==0&&i>=0&&i<=9999) { 00085 i+=10; 00086 wait(0.03); 00087 } 00088 00089 if (timer1.read()>10&&timer1.read()<=100&&down==0&&i>=0&&i<=9999) { 00090 i-=10; 00091 wait(0.03); 00092 } 00093 if (timer1.read()>10&&timer1.read()<=1000&&up==0&&i>=0&&i<=9999) { 00094 i+=100; 00095 wait(0.003); 00096 } 00097 00098 if (timer1.read()>10&&timer1.read()<=1000&&down==0&&i>=0&&i<=9999) { 00099 i-=100; 00100 wait(0.003); 00101 } 00102 00103 if(i<0){ 00104 i=0; 00105 } 00106 00107 if(i>9999){ 00108 i=9999; 00109 } 00110 00111 //NEW !! (not zeros in -- process) 00112 if(i<10){ 00113 lcd.locate(4,0); 00114 lcd.putc(0xFE); 00115 } 00116 00117 if(i<100){ 00118 lcd.locate(5,0); 00119 lcd.putc(0xFE); 00120 } 00121 00122 if(i<1000){ 00123 lcd.locate(6,0); 00124 lcd.putc(0xFE); 00125 } 00126 // 00127 00128 i=i; 00129 //lcd.locate(3,0); 00130 //lcd.printf(" "); 00131 lcd.locate(3,0); 00132 lcd.printf("%d", i); 00133 wait(0.2); 00134 00135 } 00136 } 00137 00138 //fin espacio de trabajo 00139 00140 if(next.falling()){ 00141 c++; 00142 } 00143 } 00144 } 00145 00146 00147 //Salto a Kp 00148 if (c==1){ 00149 00150 lcd.locate(11,0); 00151 lcd.putc(0xFE); 00152 lcd.writeCommand(C1); 00153 lcd.locate(11,0); 00154 lcd.printf("%d",j); 00155 00156 while(c==1){ 00157 00158 //Work space 00159 00160 if(up.falling()||down.falling()){ 00161 timer1.start(); 00162 00163 while(up==0||down==0){ 00164 if(up==1&&down==1){ 00165 timer1.stop(); 00166 timer1.reset(); 00167 } 00168 if (timer1.read()>0&&timer1.read()<=5&&up==0&&j>=0&&j<=9999) { 00169 ++j; 00170 wait(0.1); 00171 } 00172 if (timer1.read()>0&&timer1.read()<=5&&down==0&&j>=0&&j<=9999) { 00173 --j; 00174 wait(0.1); 00175 } 00176 00177 if (timer1.read()>5&&timer1.read()<=10&&up==0&&j>=0&&j<=9999) { 00178 j+=5; 00179 wait(0.1/5); 00180 } 00181 00182 if (timer1.read()>5&&timer1.read()<=10&&down==0&&j>=0&&j<=9999) { 00183 j-=5; 00184 wait(0.1/5); 00185 } 00186 00187 00188 if (timer1.read()>10&&timer1.read()<=100&&up==0&&j>=0&&j<=9999) { 00189 j+=10; 00190 wait(0.03); 00191 } 00192 00193 if (timer1.read()>10&&timer1.read()<=100&&down==0&&j>=0&&j<=9999) { 00194 j-=10; 00195 wait(0.03); 00196 } 00197 if (timer1.read()>10&&timer1.read()<=1000&&up==0&&j>=0&&j<=9999) { 00198 j+=100; 00199 wait(0.003); 00200 } 00201 00202 if (timer1.read()>10&&timer1.read()<=1000&&down==0&&j>=0&&j<=9999) { 00203 j-=100; 00204 wait(0.003); 00205 } 00206 00207 if(j<0){ 00208 j=0; 00209 } 00210 00211 if(j>9999){ 00212 j=9999; 00213 } 00214 00215 //NEW !! (not zeros in -- process) 00216 if(j<10){ 00217 lcd.locate(12,0); 00218 lcd.putc(0xFE); 00219 } 00220 00221 if(j<100){ 00222 lcd.locate(13,0); 00223 lcd.putc(0xFE); 00224 } 00225 00226 if(j<1000){ 00227 lcd.locate(14,0); 00228 lcd.putc(0xFE); 00229 } 00230 // 00231 00232 j=j; 00233 //lcd.locate(11,0); 00234 //lcd.printf(" "); 00235 lcd.locate(11,0); //before lcd.locate(12,0); 00236 lcd.printf("%d", j); 00237 wait(0.2); 00238 00239 } 00240 } 00241 00242 //End work space 00243 00244 if(next.falling()){ 00245 c++; 00246 } 00247 } 00248 } 00249 00250 //Salto a Kp 00251 if (c==2){ 00252 00253 lcd.locate(3,1); 00254 lcd.putc(0xFE); 00255 lcd.writeCommand(C1); 00256 lcd.locate(3,1); 00257 lcd.printf("%d",k); 00258 00259 while(c==2){ 00260 00261 //Work space 00262 00263 if(up.falling()||down.falling()){ 00264 timer1.start(); 00265 00266 while(up==0||down==0){ 00267 if(up==1&&down==1){ 00268 timer1.stop(); 00269 timer1.reset(); 00270 } 00271 if (timer1.read()>0&&timer1.read()<=5&&up==0&&k>=0&&k<=9999) { 00272 ++k; 00273 wait(0.1); 00274 } 00275 if (timer1.read()>0&&timer1.read()<=5&&down==0&&k>=0&&k<=9999) { 00276 --k; 00277 wait(0.1); 00278 } 00279 00280 if (timer1.read()>5&&timer1.read()<=10&&up==0&&k>=0&&k<=9999) { 00281 k+=5; 00282 wait(0.1/5); 00283 } 00284 00285 if (timer1.read()>5&&timer1.read()<=10&&down==0&&k>=0&&k<=9999) { 00286 k-=5; 00287 wait(0.1/5); 00288 } 00289 00290 00291 if (timer1.read()>10&&timer1.read()<=100&&up==0&&k>=0&&k<=9999) { 00292 k+=10; 00293 wait(0.03); 00294 } 00295 00296 if (timer1.read()>10&&timer1.read()<=100&&down==0&&k>=0&&k<=9999) { 00297 k-=10; 00298 wait(0.03); 00299 } 00300 if (timer1.read()>10&&timer1.read()<=1000&&up==0&&k>=0&&k<=9999) { 00301 k+=100; 00302 wait(0.003); 00303 } 00304 00305 if (timer1.read()>10&&timer1.read()<=1000&&down==0&&k>=0&&k<=9999) { 00306 k-=100; 00307 wait(0.003); 00308 } 00309 00310 if(k<0){ 00311 k=0; 00312 } 00313 00314 if(k>9999){ 00315 k=9999; 00316 } 00317 00318 //NEW !! (not zeros in -- process) 00319 if(k<10){ 00320 lcd.locate(4,1); 00321 lcd.putc(0xFE); 00322 } 00323 00324 if(k<100){ 00325 lcd.locate(5,1); 00326 lcd.putc(0xFE); 00327 } 00328 00329 if(k<1000){ 00330 lcd.locate(6,1); 00331 lcd.putc(0xFE); 00332 } 00333 // 00334 00335 k=k; 00336 //lcd.locate(3,1); 00337 //lcd.printf(" "); 00338 lcd.locate(3,1); //before lcd.locate(4,1); 00339 lcd.printf("%d", k); 00340 wait(0.2); 00341 00342 } 00343 } 00344 00345 //End work space 00346 00347 if(next.falling()){ 00348 c++; 00349 } 00350 } 00351 } 00352 00353 //Salto a Kp 00354 if (c==3){ 00355 00356 lcd.locate(11,1); 00357 lcd.putc(0xFE); 00358 lcd.writeCommand(C1); 00359 lcd.locate(11,1); 00360 lcd.printf("%d",l); 00361 00362 while(c==3){ 00363 00364 //Work space 00365 00366 if(up.falling()||down.falling()){ 00367 timer1.start(); 00368 00369 while(up==0||down==0){ 00370 if(up==1&&down==1){ 00371 timer1.stop(); 00372 timer1.reset(); 00373 } 00374 if (timer1.read()>0&&timer1.read()<=5&&up==0&&l>=0&&l<=9999) { 00375 ++l; 00376 wait(0.1); 00377 } 00378 if (timer1.read()>0&&timer1.read()<=5&&down==0&&l>=0&&l<=9999) { 00379 --l; 00380 wait(0.1); 00381 } 00382 00383 if (timer1.read()>5&&timer1.read()<=10&&up==0&&l>=0&&l<=9999) { 00384 l+=5; 00385 wait(0.1/5); 00386 } 00387 00388 if (timer1.read()>5&&timer1.read()<=10&&down==0&&l>=0&&l<=9999) { 00389 l-=5; 00390 wait(0.1/5); 00391 } 00392 00393 00394 if (timer1.read()>10&&timer1.read()<=100&&up==0&&l>=0&&l<=9999) { 00395 l+=10; 00396 wait(0.03); 00397 } 00398 00399 if (timer1.read()>10&&timer1.read()<=100&&down==0&&l>=0&&l<=9999) { 00400 l-=10; 00401 wait(0.03); 00402 } 00403 if (timer1.read()>10&&timer1.read()<=1000&&up==0&&l>=0&&l<=9999) { 00404 l+=100; 00405 wait(0.003); 00406 } 00407 00408 if (timer1.read()>10&&timer1.read()<=1000&&down==0&&l>=0&&l<=9999) { 00409 l-=100; 00410 wait(0.003); 00411 } 00412 00413 if(l<0){ 00414 l=0; 00415 } 00416 00417 if(l>9999){ 00418 l=9999; 00419 } 00420 00421 //NEW !! (not zeros in -- process) 00422 if(l<10){ 00423 lcd.locate(12,1); 00424 lcd.putc(0xFE); 00425 } 00426 00427 if(l<100){ 00428 lcd.locate(13,1); 00429 lcd.putc(0xFE); 00430 } 00431 00432 if(l<1000){ 00433 lcd.locate(14,1); 00434 lcd.putc(0xFE); 00435 } 00436 // 00437 00438 l=l; 00439 //lcd.locate(11,1); 00440 //lcd.printf(" "); 00441 lcd.locate(11,1); //before lcd.locate(12,1); 00442 lcd.printf("%d", l); 00443 wait(0.2); 00444 00445 } 00446 } 00447 00448 //End work space 00449 00450 if(next.falling()){ 00451 c++; 00452 } 00453 } 00454 } 00455 00456 // 00457 if(c==4 || c>4){ 00458 c=0; 00459 } 00460 00461 } 00462 }
Generated on Wed Jul 20 2022 22:24:33 by
1.7.2