algo
Dependencies: Debounced TextLCD2 mbed
Fork of tarea2 by
main.cpp
00001 #include "mbed.h" 00002 #include "DebouncedIn.h" 00003 #include "TextLCD.h" 00004 00005 AnalogIn Vin(PTC2); 00006 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00007 00008 DigitalOut led1(LED1); 00009 DigitalOut led2(LED2); 00010 DigitalOut led3(LED3); 00011 DigitalIn button1(PTC12); 00012 DigitalIn button2(PTC13); 00013 DigitalIn button3(PTC16); 00014 DebouncedIn button4(PTC17); 00015 00016 00017 00018 int C1=0x0F; 00019 int spnum=0,kinum=0,kpnum=0,kdnum=0,pos=1; 00020 int incremento=1,decremento=1,flagt=0; 00021 Timer t; 00022 00023 int main() 00024 { 00025 lcd.cls(); // Borrar Pantalla 00026 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD 00027 00028 lcd.locate(8,0); 00029 lcd.printf("Kp=%d",kpnum); 00030 lcd.locate(0,1); 00031 lcd.printf("Ki=%d",kinum); 00032 lcd.locate(8,1); 00033 lcd.printf("Kd=%d",kdnum); 00034 lcd.locate(0,0); 00035 lcd.printf("Sp=%d",spnum); 00036 00037 while(1) 00038 { 00039 if (!button1) 00040 { 00041 if(flagt==0) 00042 { 00043 t.start(); 00044 flagt=1; 00045 } 00046 00047 led1 =!led1; 00048 wait(0.50); 00049 if(!button1) 00050 { 00051 if(t.read()>10) 00052 { 00053 incremento=100; 00054 } 00055 else if(t.read()>5.5) 00056 { 00057 incremento=10; 00058 } 00059 00060 if(pos==1) 00061 { 00062 if(spnum+incremento>=999) 00063 { 00064 spnum=999; 00065 lcd.locate(3,0); 00066 lcd.printf(" "); 00067 lcd.locate(3,0); 00068 lcd.printf("%d", spnum); 00069 } 00070 else 00071 { 00072 spnum+=incremento; 00073 lcd.locate(3,0); 00074 lcd.printf("%d", spnum); 00075 } 00076 } 00077 else if(pos==2) 00078 { 00079 if(kpnum+incremento>=999) 00080 { 00081 kpnum=999; 00082 lcd.locate(11,0); 00083 lcd.printf(" "); 00084 lcd.locate(11,0); 00085 lcd.printf("%d", kpnum); 00086 } 00087 else 00088 { 00089 kpnum+=incremento; 00090 lcd.locate(11,0); 00091 lcd.printf("%d", kpnum); 00092 } 00093 } 00094 else if(pos==3) 00095 { 00096 if(kinum+incremento>=999) 00097 { 00098 kinum=999; 00099 lcd.locate(3,1); 00100 lcd.printf(" "); 00101 lcd.locate(3,1); 00102 lcd.printf("%d", kinum); 00103 } 00104 else 00105 { 00106 kinum+=incremento; 00107 lcd.locate(3,1); 00108 lcd.printf("%d", kinum); 00109 } 00110 } 00111 else if(pos==4) 00112 { 00113 if(kdnum+incremento>=999) 00114 { 00115 kdnum=999; 00116 lcd.locate(11,1); 00117 lcd.printf(" "); 00118 lcd.locate(11,1); 00119 lcd.printf("%d", kdnum); 00120 } 00121 else 00122 { 00123 kdnum+=incremento; 00124 lcd.locate(11,1); 00125 lcd.printf("%d", kdnum); 00126 } 00127 } 00128 } 00129 } 00130 00131 if (!button2) 00132 { 00133 if(flagt==0) 00134 { 00135 t.start(); 00136 flagt=1; 00137 } 00138 00139 led1 =!led1; 00140 wait(0.50); 00141 if(!button2) 00142 { 00143 if(t.read()>10) 00144 { 00145 decremento=100; 00146 } 00147 else if(t.read()>5.5) 00148 { 00149 decremento=10; 00150 } 00151 00152 if(pos==1) 00153 { 00154 00155 if(spnum>=999) 00156 { 00157 spnum=999; 00158 lcd.locate(3,0); 00159 lcd.printf(" "); 00160 lcd.locate(3,0); 00161 lcd.printf("%d", spnum); 00162 00163 } 00164 00165 else 00166 { 00167 if(spnum==0) 00168 { spnum=0; 00169 lcd.locate(0,0); 00170 lcd.printf("Sp=%d",spnum); 00171 lcd.locate(3,0); 00172 lcd.printf("%d", spnum); 00173 } 00174 00175 spnum-=decremento; 00176 lcd.locate(3,0); 00177 lcd.printf("%d", spnum); 00178 } 00179 } 00180 else if(pos==2) 00181 { 00182 if(kpnum>=999) 00183 { 00184 kpnum=999; 00185 lcd.locate(11,0); 00186 lcd.printf(" "); 00187 lcd.locate(11,0); 00188 lcd.printf("%d", kpnum); 00189 } 00190 else 00191 { 00192 kpnum-=decremento; 00193 lcd.locate(11,0); 00194 lcd.printf("%d", kpnum); 00195 } 00196 } 00197 else if(pos==3) 00198 { 00199 if(kinum>=999) 00200 { 00201 kinum=999; 00202 lcd.locate(3,1); 00203 lcd.printf(" "); 00204 lcd.locate(3,1); 00205 lcd.printf("%d", kinum); 00206 } 00207 else 00208 { 00209 kinum-=decremento; 00210 lcd.locate(3,1); 00211 lcd.printf("%d", kinum); 00212 } 00213 } 00214 else if(pos==4) 00215 { 00216 if(kdnum>=999) 00217 { 00218 kdnum=999; 00219 lcd.locate(11,1); 00220 lcd.printf(" "); 00221 lcd.locate(11,1); 00222 lcd.printf("%d", kdnum); 00223 } 00224 else 00225 { 00226 kdnum-=decremento; 00227 lcd.locate(11,1); 00228 lcd.printf("%d", kdnum); 00229 } 00230 } 00231 } 00232 } 00233 00234 00235 /*if (!button2) 00236 { 00237 if(flagt==0) 00238 { 00239 //t.reset(); 00240 t.start(); 00241 flagt=1; 00242 } 00243 00244 led1 =!led1; 00245 wait(0.50); 00246 00247 if(!button2) 00248 { 00249 if(t.read()>10) 00250 { 00251 incremento=100; 00252 } 00253 else if(t.read()>5.5) 00254 { 00255 incremento=10; 00256 } 00257 00258 led2 =!led2; 00259 if(pos==1) 00260 { 00261 if(spnum-incremento<0) 00262 { 00263 //No ocurre nada 00264 } 00265 else 00266 { 00267 spnum-=incremento; 00268 lcd.locate(3,0); 00269 lcd.printf(" "); 00270 lcd.locate(3,0); 00271 lcd.printf("%d", spnum); 00272 } 00273 } 00274 else if(pos==2) 00275 { 00276 if(kpnum-incremento<0) 00277 { 00278 //No ocurre nada 00279 } 00280 else 00281 { 00282 kpnum-=incremento; 00283 lcd.locate(11,0); 00284 lcd.printf(" "); 00285 lcd.locate(11,0); 00286 lcd.printf("%d", kpnum); 00287 } 00288 } 00289 else if(pos==3) 00290 { 00291 if(kinum-incremento<0) 00292 { 00293 //No ocurre nada 00294 } 00295 else 00296 { 00297 kinum-=incremento; 00298 lcd.locate(3,1); 00299 lcd.printf(" "); 00300 lcd.locate(3,1); 00301 lcd.printf("%d", kinum); 00302 } 00303 } 00304 else if(pos==4) 00305 { 00306 if(kdnum-incremento<0) 00307 { 00308 //No ocurre nada 00309 } 00310 else 00311 { 00312 kdnum-=incremento; 00313 lcd.locate(11,1); 00314 lcd.printf(" "); 00315 lcd.locate(11,1); 00316 lcd.printf("%d", kdnum); 00317 } 00318 } 00319 } 00320 }*/ 00321 00322 if (!button3) 00323 { 00324 led3 =!led3; 00325 if(pos==4) 00326 { 00327 pos=1; 00328 lcd.locate(3,0); 00329 lcd.printf("%d", spnum); 00330 } 00331 else if (pos==1) 00332 { 00333 pos++; 00334 lcd.locate(11,0); 00335 lcd.printf("%d", kpnum); 00336 } 00337 else if(pos==2) 00338 { 00339 pos++; 00340 lcd.locate(3,1); 00341 lcd.printf("%d", kinum); 00342 } 00343 else if(pos==3) 00344 { 00345 pos++; 00346 lcd.locate(11,1); 00347 lcd.printf("%d", kdnum); 00348 } 00349 wait(0.25); 00350 00351 } 00352 00353 if (button1 && button2) 00354 { 00355 flagt=0; 00356 t.reset(); 00357 incremento=1; 00358 } 00359 00360 } 00361 }
Generated on Wed Jul 13 2022 04:35:25 by
1.7.2
