JOSE RUIZ ORTEGA, SEBASTIAN PELAEZ LENTEJA// Programa que permite seleccionar y aumentar o disminuir valores por medio de tres pulsadores, ademas el hecho de presionar cada pulsador genera un sonido diferente

Dependencies:   DebouncedIn TextLCD mbed

Fork of Teclado_Tres_Pulsadores by GrupoProcesadores

Committer:
lenteja2206
Date:
Fri Mar 28 03:22:48 2014 +0000
Revision:
0:cfae0be51e6b
Jo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lenteja2206 0:cfae0be51e6b 1 #include "mbed.h"
lenteja2206 0:cfae0be51e6b 2 #include "DebouncedIn.h"
lenteja2206 0:cfae0be51e6b 3 #include "TextLCD.h"
lenteja2206 0:cfae0be51e6b 4
lenteja2206 0:cfae0be51e6b 5 AnalogIn Vin(PTC2);
lenteja2206 0:cfae0be51e6b 6 AnalogOut Vout(PTC3);
lenteja2206 0:cfae0be51e6b 7 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
lenteja2206 0:cfae0be51e6b 8
lenteja2206 0:cfae0be51e6b 9 DigitalOut led1(LED1);
lenteja2206 0:cfae0be51e6b 10 DigitalOut led2(LED2);
lenteja2206 0:cfae0be51e6b 11 DigitalOut led3(LED3);
lenteja2206 0:cfae0be51e6b 12 DebouncedIn button1(PTC12);
lenteja2206 0:cfae0be51e6b 13 DebouncedIn button2(PTC13);
lenteja2206 0:cfae0be51e6b 14 DebouncedIn button3(PTC16);
lenteja2206 0:cfae0be51e6b 15
lenteja2206 0:cfae0be51e6b 16 int C1=0x0F;
lenteja2206 0:cfae0be51e6b 17 int sp=0,kp=0,kd=0,ki=0,p=1;
lenteja2206 0:cfae0be51e6b 18 int main()
lenteja2206 0:cfae0be51e6b 19 {
lenteja2206 0:cfae0be51e6b 20 lcd.cls();
lenteja2206 0:cfae0be51e6b 21 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
lenteja2206 0:cfae0be51e6b 22 lcd.locate(8,0);
lenteja2206 0:cfae0be51e6b 23 lcd.printf("kp=%d", kp);
lenteja2206 0:cfae0be51e6b 24 lcd.locate(0,1);
lenteja2206 0:cfae0be51e6b 25 lcd.printf("Ki=%d", ki);
lenteja2206 0:cfae0be51e6b 26 lcd.locate(8,1);
lenteja2206 0:cfae0be51e6b 27 lcd.printf("Kd=%d", kd);
lenteja2206 0:cfae0be51e6b 28 lcd.locate(0,0);
lenteja2206 0:cfae0be51e6b 29 lcd.printf("Sp=%d", sp);
lenteja2206 0:cfae0be51e6b 30
lenteja2206 0:cfae0be51e6b 31 while(1)
lenteja2206 0:cfae0be51e6b 32 {
lenteja2206 0:cfae0be51e6b 33 if (button1.falling())
lenteja2206 0:cfae0be51e6b 34 {
lenteja2206 0:cfae0be51e6b 35
lenteja2206 0:cfae0be51e6b 36 led1 =!led1;
lenteja2206 0:cfae0be51e6b 37 if (p==1)
lenteja2206 0:cfae0be51e6b 38 {
lenteja2206 0:cfae0be51e6b 39 ++sp;
lenteja2206 0:cfae0be51e6b 40 lcd.locate(3,0);
lenteja2206 0:cfae0be51e6b 41 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 42 lcd.locate(3,0);
lenteja2206 0:cfae0be51e6b 43 lcd.printf("%d", sp);
lenteja2206 0:cfae0be51e6b 44 } //Cierra sp
lenteja2206 0:cfae0be51e6b 45 else if (p==2)
lenteja2206 0:cfae0be51e6b 46 {
lenteja2206 0:cfae0be51e6b 47 ++kp;
lenteja2206 0:cfae0be51e6b 48 lcd.locate(11,0);
lenteja2206 0:cfae0be51e6b 49 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 50 lcd.locate(11,0);
lenteja2206 0:cfae0be51e6b 51 lcd.printf("%d", kp);
lenteja2206 0:cfae0be51e6b 52 } //Cierra kp
lenteja2206 0:cfae0be51e6b 53 else if (p==3)
lenteja2206 0:cfae0be51e6b 54 {
lenteja2206 0:cfae0be51e6b 55 ++ki;
lenteja2206 0:cfae0be51e6b 56 lcd.locate(3,1);
lenteja2206 0:cfae0be51e6b 57 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 58 lcd.locate(3,1);
lenteja2206 0:cfae0be51e6b 59 lcd.printf("%d", ki);
lenteja2206 0:cfae0be51e6b 60 } //Cierra ki
lenteja2206 0:cfae0be51e6b 61 else if (p==4)
lenteja2206 0:cfae0be51e6b 62 {
lenteja2206 0:cfae0be51e6b 63 ++kd;
lenteja2206 0:cfae0be51e6b 64 lcd.locate(11,1);
lenteja2206 0:cfae0be51e6b 65 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 66 lcd.locate(11,1);
lenteja2206 0:cfae0be51e6b 67 lcd.printf("%d", kd);
lenteja2206 0:cfae0be51e6b 68 } //Cierra kd
lenteja2206 0:cfae0be51e6b 69 } //Cierra button1.falling
lenteja2206 0:cfae0be51e6b 70 if (button2.falling())
lenteja2206 0:cfae0be51e6b 71 {
lenteja2206 0:cfae0be51e6b 72 led2 =!led2;
lenteja2206 0:cfae0be51e6b 73 if (p==1)
lenteja2206 0:cfae0be51e6b 74 {
lenteja2206 0:cfae0be51e6b 75 if (sp==0) // no mostrar nada
lenteja2206 0:cfae0be51e6b 76 {
lenteja2206 0:cfae0be51e6b 77 }
lenteja2206 0:cfae0be51e6b 78 else
lenteja2206 0:cfae0be51e6b 79 {
lenteja2206 0:cfae0be51e6b 80 --sp;
lenteja2206 0:cfae0be51e6b 81 lcd.locate(3,0);
lenteja2206 0:cfae0be51e6b 82 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 83 lcd.locate(3,0);
lenteja2206 0:cfae0be51e6b 84 lcd.printf("%d", sp);
lenteja2206 0:cfae0be51e6b 85 } //Cierra sp
lenteja2206 0:cfae0be51e6b 86 } //Cierra if p==1
lenteja2206 0:cfae0be51e6b 87 if (p==2)
lenteja2206 0:cfae0be51e6b 88 {
lenteja2206 0:cfae0be51e6b 89 if (kp==0) // no mostrar nada
lenteja2206 0:cfae0be51e6b 90 {
lenteja2206 0:cfae0be51e6b 91 }
lenteja2206 0:cfae0be51e6b 92 else
lenteja2206 0:cfae0be51e6b 93 {
lenteja2206 0:cfae0be51e6b 94 --kp;
lenteja2206 0:cfae0be51e6b 95 lcd.locate(11,0);
lenteja2206 0:cfae0be51e6b 96 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 97 lcd.locate(11,0);
lenteja2206 0:cfae0be51e6b 98 lcd.printf("%d", kp);
lenteja2206 0:cfae0be51e6b 99 } //Cierra kp
lenteja2206 0:cfae0be51e6b 100 } //Cierra if p==2
lenteja2206 0:cfae0be51e6b 101 if (p==3)
lenteja2206 0:cfae0be51e6b 102 {
lenteja2206 0:cfae0be51e6b 103 if (ki==0) // no mostrar nada
lenteja2206 0:cfae0be51e6b 104 {
lenteja2206 0:cfae0be51e6b 105 }
lenteja2206 0:cfae0be51e6b 106 else
lenteja2206 0:cfae0be51e6b 107 {
lenteja2206 0:cfae0be51e6b 108 --ki;
lenteja2206 0:cfae0be51e6b 109 lcd.locate(3,1);
lenteja2206 0:cfae0be51e6b 110 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 111 lcd.locate(3,1);
lenteja2206 0:cfae0be51e6b 112 lcd.printf("%d", ki);
lenteja2206 0:cfae0be51e6b 113 } //Cierra ki
lenteja2206 0:cfae0be51e6b 114 } //Cierra if p==3
lenteja2206 0:cfae0be51e6b 115 if (p==4)
lenteja2206 0:cfae0be51e6b 116 {
lenteja2206 0:cfae0be51e6b 117 if (kd==0) // no mostrar nada
lenteja2206 0:cfae0be51e6b 118 {
lenteja2206 0:cfae0be51e6b 119 }
lenteja2206 0:cfae0be51e6b 120 else
lenteja2206 0:cfae0be51e6b 121 {
lenteja2206 0:cfae0be51e6b 122 --kd;
lenteja2206 0:cfae0be51e6b 123 lcd.locate(11,1);
lenteja2206 0:cfae0be51e6b 124 lcd.printf(" ");
lenteja2206 0:cfae0be51e6b 125 lcd.locate(11,1);
lenteja2206 0:cfae0be51e6b 126 lcd.printf("%d", kd);
lenteja2206 0:cfae0be51e6b 127 } //Cierra kd
lenteja2206 0:cfae0be51e6b 128 } //Cierra if p==4
lenteja2206 0:cfae0be51e6b 129 } //Cierra button2.falling
lenteja2206 0:cfae0be51e6b 130 if (button3.falling())
lenteja2206 0:cfae0be51e6b 131 {
lenteja2206 0:cfae0be51e6b 132 led3 =!led3;
lenteja2206 0:cfae0be51e6b 133 if (p==1)
lenteja2206 0:cfae0be51e6b 134 {
lenteja2206 0:cfae0be51e6b 135 ++p;
lenteja2206 0:cfae0be51e6b 136 lcd.locate(11,0);
lenteja2206 0:cfae0be51e6b 137 lcd.printf("%d", kp);
lenteja2206 0:cfae0be51e6b 138
lenteja2206 0:cfae0be51e6b 139
lenteja2206 0:cfae0be51e6b 140 }
lenteja2206 0:cfae0be51e6b 141 else if (p==2)
lenteja2206 0:cfae0be51e6b 142 {
lenteja2206 0:cfae0be51e6b 143 ++p;
lenteja2206 0:cfae0be51e6b 144 lcd.locate(3,1);
lenteja2206 0:cfae0be51e6b 145 lcd.printf("%d", ki);
lenteja2206 0:cfae0be51e6b 146 lcd.locate(3,1);
lenteja2206 0:cfae0be51e6b 147
lenteja2206 0:cfae0be51e6b 148 }
lenteja2206 0:cfae0be51e6b 149 else if (p==3)
lenteja2206 0:cfae0be51e6b 150 {
lenteja2206 0:cfae0be51e6b 151 ++p;
lenteja2206 0:cfae0be51e6b 152 lcd.locate(11,1);
lenteja2206 0:cfae0be51e6b 153 lcd.printf("%d", kd);
lenteja2206 0:cfae0be51e6b 154 }
lenteja2206 0:cfae0be51e6b 155 else if (p==4)
lenteja2206 0:cfae0be51e6b 156 {
lenteja2206 0:cfae0be51e6b 157 p=1;
lenteja2206 0:cfae0be51e6b 158 lcd.locate(3,0);
lenteja2206 0:cfae0be51e6b 159 lcd.printf("%d", sp);
lenteja2206 0:cfae0be51e6b 160
lenteja2206 0:cfae0be51e6b 161
lenteja2206 0:cfae0be51e6b 162 }
lenteja2206 0:cfae0be51e6b 163 }
lenteja2206 0:cfae0be51e6b 164 }
lenteja2206 0:cfae0be51e6b 165 }