Santiago Alvarez / Mbed 2 deprecated tarea_1

Dependencies:   Debounced TextLCD mbed

Fork of pid_1 by Santiago Alvarez

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 AnalogIn Vin(PTC2);
00005 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7  //documentacion de las librerias y disposicion de pines
00006 
00007 DigitalOut led1(LED1);
00008 DigitalOut led2(LED2);
00009 DebouncedIn b1(PTC12);
00010 DebouncedIn b2(PTC13);
00011 DebouncedIn b3(PTC16);
00012 DebouncedIn b4(PTC17);
00013      
00014 
00015 int C1=0x0E; // solo muestra el cursor
00016 int C2=0x18; // desplaza el cursor a la  izquierda
00017 int C3=0x1A; // desplaza el cursor derecha
00018 int C4=0x1C; // quita el  cursor bajo
00019 int a; 
00020 int b;
00021 int kp, ki, kd, sp, err, med, yr, pid, ap, ai, ad, err_v, cycle; //revisar antes de la primera tarear(PID)
00022 
00023 int main() {
00024     lcd.cls();
00025     lcd.printf("Sp%d",sp);      //ubicacion de las variables en la pantalla
00026     lcd.locate(8,0);
00027     lcd.printf("Kp%d",kp);
00028     lcd.locate(0,1);
00029     lcd.printf("Ki%d",ki);
00030     lcd.locate(8,1);
00031     lcd.printf("Kd%d",kd);
00032     lcd.writeCommand(C1);
00033     lcd.locate(0,0);
00034     lcd.printf("Sp%d",sp);
00035 
00036 
00037     while(1) {              //inicio cliclos del pid
00038         if (b1.falling()) { // incrementa
00039            led1 =!led1;
00040            ++a;
00041            lcd.locate(7,0);
00042            lcd.printf("%d", a);
00043         }
00044     if (b2.falling()) { //decrementa
00045            led2 =!led2;
00046            --a;
00047            lcd.locate(7,0); lcd.printf("   ");
00048            lcd.locate(7,0);
00049            lcd.printf("%d", a);
00050   
00051      if (b3.falling()) { 
00052                        
00053           ++b;      
00054                                               //cambia la posicion del menu
00055      if (b==0){
00056          lcd.locate(2,0);
00057          lcd.printf("%d",sp);
00058              if (b1.falling()) {                            
00059              ++sp;                 //incrementa el sp
00060              }
00061                if (b2.falling()) {                            
00062                --sp;                 //decrementa el sp
00063                } 
00064        }
00065         if (b==1) {                  //posiciones de los botones
00066            lcd.locate(10,0);
00067            lcd.printf("%d",kp);
00068             if (b1.falling()) {
00069                 ++kp;
00070              }
00071              if (b2.falling()) {                            
00072                  --kp;
00073               }
00074           }
00075           if (b==2) {
00076             lcd.locate(2,1);
00077             lcd.printf("%d",ki);
00078                   if (b1.falling()){
00079                      ++ki;
00080                   }
00081                   if (b2.falling()){                            
00082                      --ki;
00083                   }               
00084               }
00085            if (b==3) {
00086                lcd.locate(10,1);
00087                lcd.printf("%d",kd);
00088                   if (b1.falling()){
00089                      ++kd;
00090                   }
00091                   if (b2.falling()){                            
00092                      --kd;
00093                   }
00094               } 
00095             }  
00096            if (b==4) {
00097                b=0;
00098                }                          
00099     
00100            if (b4.falling()){
00101            break;                       //sale del menu de trabajo
00102                }
00103   }                      
00104 }
00105 }