graphical interface for a PID controller

Dependencies:   DebounceIn TextLCD mbed

main.cpp

Committer:
salondonog
Date:
2013-10-11
Revision:
0:527c9de31b3c

File content as of revision 0:527c9de31b3c:

#include "mbed.h"
#include "TextLCD.h"
#include "DebounceIn.h"

TextLCD lcd(PTE0,PTE1,PTE2,PTE3,PTE4,PTE5); //configura los puestos PTE0,PTE1,PTE2,PTE3,PTE4,PTE5, donde se conectara el LCD 16x2
DebounceIn mas(PTA1);
DebounceIn menos(PTA2);
DebounceIn salto(PTA3);

int s=0;       //set point
int p=0;       //ganancia proporcional
int i=0;       //ganancia integral
int d=0;       //ganancia derivativa
int k=1;       //variable de control}

void def_posicion(int h){
    if (h==0){
    lcd.locate(3,0);
    }
    else if(h==1){
    lcd.locate(10,0);
    }
    else if (h==2){
    lcd.locate(3,1);
    }
    else {
    lcd.locate(10,1);
    }
}
void decremento(int u){             //Funcion que decrementa los valores
if(u==0){
    if(s<=0){
    s=0;
    lcd.printf("%d",s);
    }
    else{    
        s--;
        lcd.printf("%d",s);
        }
 }
else if(u==1){
    if(p<=0){
    p=0;
    lcd.printf("%d",p);
    }
     else{
        p--;
        lcd.printf("%d",p);
        }
}
else if(u==2){
    if(i<=0){
    i=0;
    lcd.printf("%d",i);
    }
     else{
        i--;
        lcd.printf("%d",i);
        }
 }
else if(d<=0){
    d=0;
    lcd.printf("%d",d);
    }
else   {
        d--;
        lcd.printf("%d",d);
       }
}

void incremento(int h){             //Funcion que incremente los valores 
if(h==0){
        s++;
        lcd.printf("%d",s);
      }
else if(h==1){
        p++;
        lcd.printf("%d",p);
      }
else if(h==2){
        i++;
        lcd.printf("%d",i);
      }
else{
        d++;
        lcd.printf("%d",d);
    }

}

void star_patch(void){  //funcion que imprime los caracteres que no van a variar en el display
lcd.printf("SP=");
lcd.locate(7,0);
lcd.printf("Kp=");
lcd.locate(0,1);
lcd.printf("Ki=");
lcd.locate(7,1);
lcd.printf("Kd=");
lcd.locate(3,0);
}

int main(){
star_patch();
while(1){
    if(k==3)k=0;
    if(salto.read()==0){    
    def_posicion(k);
    k++;
    }
    else if(mas.read()==0){
       incremento(k); 
    }
    else if(menos.read()==0){
        decremento(k);
    }
}
}