operacion con botones incrementando y decrementando 1 en 1

Dependencies:   Debounced TextLCD mbed

Fork of pid_1 by Santiago Alvarez

Committer:
salvarear
Date:
Tue Dec 03 20:00:17 2013 +0000
Revision:
0:d5303d5b0cda
d

Who changed what in which revision?

UserRevisionLine numberNew contents of line
salvarear 0:d5303d5b0cda 1 #include "mbed.h"
salvarear 0:d5303d5b0cda 2 #include "DebouncedIn.h"
salvarear 0:d5303d5b0cda 3 #include "TextLCD.h"
salvarear 0:d5303d5b0cda 4 AnalogIn Vin(PTC2);
salvarear 0:d5303d5b0cda 5 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 //documentacion de las librerias y disposicion de pines
salvarear 0:d5303d5b0cda 6
salvarear 0:d5303d5b0cda 7 DigitalOut led1(LED1);
salvarear 0:d5303d5b0cda 8 DigitalOut led2(LED2);
salvarear 0:d5303d5b0cda 9 DebouncedIn b1(PTC12);
salvarear 0:d5303d5b0cda 10 DebouncedIn b2(PTC13);
salvarear 0:d5303d5b0cda 11 DebouncedIn b3(PTC16);
salvarear 0:d5303d5b0cda 12 DebouncedIn b4(PTC17);
salvarear 0:d5303d5b0cda 13
salvarear 0:d5303d5b0cda 14
salvarear 0:d5303d5b0cda 15 int C1=0x0E; // solo muestra el cursor
salvarear 0:d5303d5b0cda 16 int C2=0x18; // desplaza el cursor a la izquierda
salvarear 0:d5303d5b0cda 17 int C3=0x1A; // desplaza el cursor derecha
salvarear 0:d5303d5b0cda 18 int C4=0x1C; // quita el cursor bajo
salvarear 0:d5303d5b0cda 19 int a;
salvarear 0:d5303d5b0cda 20 int b;
salvarear 0:d5303d5b0cda 21 int kp, ki, kd, sp, err, med, yr, pid, ap, ai, ad, err_v, cycle; //revisar antes de la primera tarear(PID)
salvarear 0:d5303d5b0cda 22
salvarear 0:d5303d5b0cda 23 int main() {
salvarear 0:d5303d5b0cda 24 lcd.cls();
salvarear 0:d5303d5b0cda 25 lcd.printf("Sp%d",sp); //ubicacion de las variables en la pantalla
salvarear 0:d5303d5b0cda 26 lcd.locate(8,0);
salvarear 0:d5303d5b0cda 27 lcd.printf("Kp%d",kp);
salvarear 0:d5303d5b0cda 28 lcd.locate(0,1);
salvarear 0:d5303d5b0cda 29 lcd.printf("Ki%d",ki);
salvarear 0:d5303d5b0cda 30 lcd.locate(8,1);
salvarear 0:d5303d5b0cda 31 lcd.printf("Kd%d",kd);
salvarear 0:d5303d5b0cda 32 lcd.writeCommand(C1);
salvarear 0:d5303d5b0cda 33 lcd.locate(0,0);
salvarear 0:d5303d5b0cda 34 lcd.printf("Sp%d",sp);
salvarear 0:d5303d5b0cda 35
salvarear 0:d5303d5b0cda 36
salvarear 0:d5303d5b0cda 37 while(1) { //inicio cliclos del pid
salvarear 0:d5303d5b0cda 38 if (b1.falling()) { // incrementa
salvarear 0:d5303d5b0cda 39 led1 =!led1;
salvarear 0:d5303d5b0cda 40 ++a;
salvarear 0:d5303d5b0cda 41 lcd.locate(7,0);
salvarear 0:d5303d5b0cda 42 lcd.printf("%d", a);
salvarear 0:d5303d5b0cda 43 }
salvarear 0:d5303d5b0cda 44 if (b2.falling()) { //decrementa
salvarear 0:d5303d5b0cda 45 led2 =!led2;
salvarear 0:d5303d5b0cda 46 --a;
salvarear 0:d5303d5b0cda 47 lcd.locate(7,0); lcd.printf(" ");
salvarear 0:d5303d5b0cda 48 lcd.locate(7,0);
salvarear 0:d5303d5b0cda 49 lcd.printf("%d", a);
salvarear 0:d5303d5b0cda 50
salvarear 0:d5303d5b0cda 51 if (b3.falling()) {
salvarear 0:d5303d5b0cda 52
salvarear 0:d5303d5b0cda 53 ++b;
salvarear 0:d5303d5b0cda 54 //cambia la posicion del menu
salvarear 0:d5303d5b0cda 55 if (b==0){
salvarear 0:d5303d5b0cda 56 lcd.locate(2,0);
salvarear 0:d5303d5b0cda 57 lcd.printf("%d",sp);
salvarear 0:d5303d5b0cda 58 if (b1.falling()) {
salvarear 0:d5303d5b0cda 59 ++sp; //incrementa el sp
salvarear 0:d5303d5b0cda 60 }
salvarear 0:d5303d5b0cda 61 if (b2.falling()) {
salvarear 0:d5303d5b0cda 62 --sp; //decrementa el sp
salvarear 0:d5303d5b0cda 63 }
salvarear 0:d5303d5b0cda 64 }
salvarear 0:d5303d5b0cda 65 if (b==1) { //posiciones de los botones
salvarear 0:d5303d5b0cda 66 lcd.locate(10,0);
salvarear 0:d5303d5b0cda 67 lcd.printf("%d",kp);
salvarear 0:d5303d5b0cda 68 if (b1.falling()) {
salvarear 0:d5303d5b0cda 69 ++kp;
salvarear 0:d5303d5b0cda 70 }
salvarear 0:d5303d5b0cda 71 if (b2.falling()) {
salvarear 0:d5303d5b0cda 72 --kp;
salvarear 0:d5303d5b0cda 73 }
salvarear 0:d5303d5b0cda 74 }
salvarear 0:d5303d5b0cda 75 if (b==2) {
salvarear 0:d5303d5b0cda 76 lcd.locate(2,1);
salvarear 0:d5303d5b0cda 77 lcd.printf("%d",ki);
salvarear 0:d5303d5b0cda 78 if (b1.falling()){
salvarear 0:d5303d5b0cda 79 ++ki;
salvarear 0:d5303d5b0cda 80 }
salvarear 0:d5303d5b0cda 81 if (b2.falling()){
salvarear 0:d5303d5b0cda 82 --ki;
salvarear 0:d5303d5b0cda 83 }
salvarear 0:d5303d5b0cda 84 }
salvarear 0:d5303d5b0cda 85 if (b==3) {
salvarear 0:d5303d5b0cda 86 lcd.locate(10,1);
salvarear 0:d5303d5b0cda 87 lcd.printf("%d",kd);
salvarear 0:d5303d5b0cda 88 if (b1.falling()){
salvarear 0:d5303d5b0cda 89 ++kd;
salvarear 0:d5303d5b0cda 90 }
salvarear 0:d5303d5b0cda 91 if (b2.falling()){
salvarear 0:d5303d5b0cda 92 --kd;
salvarear 0:d5303d5b0cda 93 }
salvarear 0:d5303d5b0cda 94 }
salvarear 0:d5303d5b0cda 95 }
salvarear 0:d5303d5b0cda 96 if (b==4) {
salvarear 0:d5303d5b0cda 97 b=0;
salvarear 0:d5303d5b0cda 98 }
salvarear 0:d5303d5b0cda 99
salvarear 0:d5303d5b0cda 100 if (b4.falling()){
salvarear 0:d5303d5b0cda 101 break; //sale del menu de trabajo
salvarear 0:d5303d5b0cda 102 }
salvarear 0:d5303d5b0cda 103 }
salvarear 0:d5303d5b0cda 104 }
salvarear 0:d5303d5b0cda 105 }