Tarea 1 agregando el incremental

Dependencies:   Debounced TextLCD2 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 
00015 
00016 
00017 int C1=0x0F;
00018 int spnum=0,kinum=0,kpnum=0,kdnum=0,pos=1;
00019 int incremento=1,flagt=0;
00020 Timer t;
00021 
00022 int main()
00023 {
00024     lcd.cls(); // Borrar Pantalla
00025     lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
00026 
00027     lcd.locate(8,0);
00028     lcd.printf("Kp=%d",kpnum);
00029     lcd.locate(0,1);
00030     lcd.printf("Ki=%d",kinum);
00031     lcd.locate(8,1);
00032     lcd.printf("Kd=%d",kdnum);
00033     lcd.locate(0,0);
00034     lcd.printf("Sp=%d",spnum);
00035 
00036     while(1)
00037     {
00038         if (!button1)
00039         {
00040             if(flagt==0)
00041             {
00042                 t.start();
00043                 flagt=1;
00044             }
00045 
00046             led1 =!led1;
00047             wait(0.50);
00048             if(!button1)
00049             {
00050                 if(t.read()>10)
00051                 {
00052                     incremento=100;
00053                 }
00054                 else if(t.read()>5.5)
00055                 {
00056                     incremento=10;
00057                 }
00058 
00059                 if(pos==1)
00060                 {
00061                     if(spnum+incremento>=999)
00062                     {
00063                         spnum=999;
00064                         lcd.locate(3,0);
00065                         lcd.printf("    ");
00066                         lcd.locate(3,0);
00067                         lcd.printf("%d", spnum);
00068                     }
00069                     else
00070                     {
00071                         spnum+=incremento;
00072                         lcd.locate(3,0);
00073                         lcd.printf("%d", spnum);
00074                     }                        
00075                 }
00076                 else if(pos==2)
00077                 {
00078                     if(kpnum+incremento>=999)
00079                     {
00080                         kpnum=999;
00081                         lcd.locate(11,0);
00082                         lcd.printf("    ");
00083                         lcd.locate(11,0);
00084                         lcd.printf("%d", kpnum);
00085                     }
00086                     else
00087                     {
00088                         kpnum+=incremento;
00089                         lcd.locate(11,0);
00090                         lcd.printf("%d", kpnum);
00091                     }
00092                 }
00093                 else if(pos==3)
00094                 {
00095                     if(kinum+incremento>=999)
00096                     {
00097                         kinum=999;
00098                         lcd.locate(3,1);
00099                         lcd.printf("    ");
00100                         lcd.locate(3,1);
00101                         lcd.printf("%d", kinum);
00102                     }
00103                     else
00104                     {
00105                         kinum+=incremento;
00106                         lcd.locate(3,1);
00107                         lcd.printf("%d", kinum);
00108                     }
00109                 }
00110                 else if(pos==4)
00111                 {
00112                     if(kdnum+incremento>=999)
00113                     {
00114                         kdnum=999;
00115                         lcd.locate(11,1);
00116                         lcd.printf("    ");
00117                         lcd.locate(11,1);
00118                         lcd.printf("%d", kdnum);
00119                     }
00120                     else
00121                     {
00122                         kdnum+=incremento;
00123                         lcd.locate(11,1);
00124                         lcd.printf("%d", kdnum);
00125                     }
00126                 }
00127             }
00128         }
00129         
00130         if (!button2)
00131         {
00132             if(flagt==0)
00133             {
00134                 //t.reset();
00135                 t.start();
00136                 flagt=1;
00137             }
00138 
00139             led1 =!led1;
00140             wait(0.50);
00141 
00142             if(!button2)
00143             {
00144                 if(t.read()>10)
00145                 {
00146                     incremento=100;
00147                 }
00148                 else if(t.read()>5.5)
00149                 {
00150                     incremento=10;
00151                 }
00152 
00153                 led2 =!led2;
00154                 if(pos==1)
00155                 {
00156                     if(spnum-incremento<0)
00157                     {
00158                         //No ocurre nada
00159                     }
00160                     else
00161                     {
00162                         spnum-=incremento;
00163                         lcd.locate(3,0);
00164                         lcd.printf("    ");
00165                         lcd.locate(3,0);
00166                         lcd.printf("%d", spnum);
00167                     }
00168                 }
00169                 else if(pos==2)
00170                 {
00171                     if(kpnum-incremento<0)
00172                     {
00173                         //No ocurre nada
00174                     }
00175                     else
00176                     {
00177                         kpnum-=incremento;
00178                         lcd.locate(11,0);
00179                         lcd.printf("    ");
00180                         lcd.locate(11,0);
00181                         lcd.printf("%d", kpnum);
00182                     }
00183                 }
00184                 else if(pos==3)
00185                 {
00186                     if(kinum-incremento<0)
00187                     {
00188                         //No ocurre nada
00189                     }
00190                     else
00191                     {
00192                         kinum-=incremento;
00193                         lcd.locate(3,1);
00194                         lcd.printf("    ");
00195                         lcd.locate(3,1);
00196                         lcd.printf("%d", kinum);
00197                     }
00198                 }
00199                 else if(pos==4)
00200                 {
00201                     if(kdnum-incremento<0)
00202                     {
00203                         //No ocurre nada
00204                     }
00205                     else
00206                     {
00207                         kdnum-=incremento;
00208                         lcd.locate(11,1);
00209                         lcd.printf("    ");
00210                         lcd.locate(11,1);
00211                         lcd.printf("%d", kdnum);
00212                     }
00213                 }
00214             }
00215         }
00216 
00217         if (!button3)
00218         {
00219             led3 =!led3;
00220             if(pos==4)
00221             {
00222                 pos=1;
00223                 lcd.locate(3,0);
00224                 lcd.printf("%d", spnum);
00225             }
00226             else if (pos==1)
00227             {
00228                 pos++;
00229                 lcd.locate(11,0);
00230                 lcd.printf("%d", kpnum);
00231             }
00232             else if(pos==2)
00233             {
00234                 pos++;
00235                 lcd.locate(3,1);
00236                 lcd.printf("%d", kinum);
00237             }
00238             else if(pos==3)
00239             {
00240                 pos++;
00241                 lcd.locate(11,1);
00242                 lcd.printf("%d", kdnum);
00243             }
00244             wait(0.25);
00245 
00246         }
00247         
00248         if (button1 && button2)
00249         {
00250             flagt=0;
00251             t.reset();
00252             incremento=1;
00253         }
00254        
00255     }
00256 }