Tarea 2 Procesadores Botones pulsadores con sonido

Dependencies:   Debounced TextLCD mbed

Committer:
Jesse
Date:
Wed Apr 02 15:24:36 2014 +0000
Revision:
0:ad772c4ebc42
Tarea 2 Procesadores

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jesse 0:ad772c4ebc42 1 #include "mbed.h"
Jesse 0:ad772c4ebc42 2 #include "DebouncedIn.h"
Jesse 0:ad772c4ebc42 3 #include "TextLCD.h"
Jesse 0:ad772c4ebc42 4
Jesse 0:ad772c4ebc42 5 AnalogIn Vin(PTC2);
Jesse 0:ad772c4ebc42 6 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
Jesse 0:ad772c4ebc42 7
Jesse 0:ad772c4ebc42 8
Jesse 0:ad772c4ebc42 9 DigitalOut led1(LED1);
Jesse 0:ad772c4ebc42 10 DigitalOut led2(LED2);
Jesse 0:ad772c4ebc42 11 DigitalOut led3(LED3);
Jesse 0:ad772c4ebc42 12
Jesse 0:ad772c4ebc42 13 PwmOut Pwm(PTA5);
Jesse 0:ad772c4ebc42 14
Jesse 0:ad772c4ebc42 15 DebouncedIn button1(PTC10);
Jesse 0:ad772c4ebc42 16 DebouncedIn button2(PTC11);
Jesse 0:ad772c4ebc42 17 DebouncedIn button3(PTC6);
Jesse 0:ad772c4ebc42 18
Jesse 0:ad772c4ebc42 19 float Du;
Jesse 0:ad772c4ebc42 20 float Du1;
Jesse 0:ad772c4ebc42 21 float pp;
Jesse 0:ad772c4ebc42 22 float Fi;
Jesse 0:ad772c4ebc42 23 int C1=0x0F;
Jesse 0:ad772c4ebc42 24 int sp=0,kp=0,kd=0,ki=0,p=1,Pp=0,Dd=1;
Jesse 0:ad772c4ebc42 25 int main()
Jesse 0:ad772c4ebc42 26 {
Jesse 0:ad772c4ebc42 27 //Fi=(Dd)*100;
Jesse 0:ad772c4ebc42 28 //pp=(1/Fi);
Jesse 0:ad772c4ebc42 29 //Pwm.period(pp);
Jesse 0:ad772c4ebc42 30 //Du=(Pp/100);
Jesse 0:ad772c4ebc42 31 //Du1=(1-Du);
Jesse 0:ad772c4ebc42 32
Jesse 0:ad772c4ebc42 33 lcd.cls();
Jesse 0:ad772c4ebc42 34 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
Jesse 0:ad772c4ebc42 35 lcd.locate(6,0);
Jesse 0:ad772c4ebc42 36 lcd.printf("kp=%d", kp);
Jesse 0:ad772c4ebc42 37 lcd.locate(0,1);
Jesse 0:ad772c4ebc42 38 lcd.printf("Ki=%d", ki);
Jesse 0:ad772c4ebc42 39 lcd.locate(6,1);
Jesse 0:ad772c4ebc42 40 lcd.printf("Kd=%d", kd);
Jesse 0:ad772c4ebc42 41 lcd.locate(0,0);
Jesse 0:ad772c4ebc42 42 lcd.printf("Sp=%d", sp);
Jesse 0:ad772c4ebc42 43 lcd.locate(12,0);
Jesse 0:ad772c4ebc42 44 lcd.printf("F=%d",Dd);
Jesse 0:ad772c4ebc42 45 lcd.locate(12,1);
Jesse 0:ad772c4ebc42 46 lcd.printf("D=%d",Pp);
Jesse 0:ad772c4ebc42 47
Jesse 0:ad772c4ebc42 48 while(1)
Jesse 0:ad772c4ebc42 49 {
Jesse 0:ad772c4ebc42 50 Fi=(Dd)*100;
Jesse 0:ad772c4ebc42 51 pp=(1/Fi);
Jesse 0:ad772c4ebc42 52 Pwm.period(pp);
Jesse 0:ad772c4ebc42 53 Du=(Pp/10);
Jesse 0:ad772c4ebc42 54 Du1=(1-Du);
Jesse 0:ad772c4ebc42 55
Jesse 0:ad772c4ebc42 56 if (button1.falling())
Jesse 0:ad772c4ebc42 57 {
Jesse 0:ad772c4ebc42 58 //Pwm.period);
Jesse 0:ad772c4ebc42 59 Pwm.write(0.1);
Jesse 0:ad772c4ebc42 60 wait(0.1);
Jesse 0:ad772c4ebc42 61 Pwm.write(0);
Jesse 0:ad772c4ebc42 62 wait(0.1);
Jesse 0:ad772c4ebc42 63 led1 =!led1;
Jesse 0:ad772c4ebc42 64 if (p==1)
Jesse 0:ad772c4ebc42 65 {
Jesse 0:ad772c4ebc42 66 ++sp;
Jesse 0:ad772c4ebc42 67 lcd.locate(3,0);
Jesse 0:ad772c4ebc42 68 lcd.printf(" ");
Jesse 0:ad772c4ebc42 69 lcd.locate(3,0);
Jesse 0:ad772c4ebc42 70 lcd.printf("%d", sp);
Jesse 0:ad772c4ebc42 71 //lcd.locate(15,0);
Jesse 0:ad772c4ebc42 72 //.printf(" ");
Jesse 0:ad772c4ebc42 73 }
Jesse 0:ad772c4ebc42 74 else if (p==2)
Jesse 0:ad772c4ebc42 75 {
Jesse 0:ad772c4ebc42 76 ++kp;
Jesse 0:ad772c4ebc42 77 lcd.locate(9,0);
Jesse 0:ad772c4ebc42 78 lcd.printf(" ");
Jesse 0:ad772c4ebc42 79 lcd.locate(9,0);
Jesse 0:ad772c4ebc42 80 lcd.printf("%d", kp);
Jesse 0:ad772c4ebc42 81 }
Jesse 0:ad772c4ebc42 82 else if (p==3)
Jesse 0:ad772c4ebc42 83 {
Jesse 0:ad772c4ebc42 84 ++ki;
Jesse 0:ad772c4ebc42 85 lcd.locate(3,1);
Jesse 0:ad772c4ebc42 86 lcd.printf(" ");
Jesse 0:ad772c4ebc42 87 lcd.locate(3,1);
Jesse 0:ad772c4ebc42 88 lcd.printf("%d", ki);
Jesse 0:ad772c4ebc42 89 }
Jesse 0:ad772c4ebc42 90 else if (p==4)
Jesse 0:ad772c4ebc42 91 {
Jesse 0:ad772c4ebc42 92 ++kd;
Jesse 0:ad772c4ebc42 93 lcd.locate(9,1);
Jesse 0:ad772c4ebc42 94 lcd.printf(" ");
Jesse 0:ad772c4ebc42 95 lcd.locate(9,1);
Jesse 0:ad772c4ebc42 96 lcd.printf("%d", kd);
Jesse 0:ad772c4ebc42 97 }
Jesse 0:ad772c4ebc42 98 else if (p==5)
Jesse 0:ad772c4ebc42 99 {
Jesse 0:ad772c4ebc42 100 ++Dd;
Jesse 0:ad772c4ebc42 101 lcd.locate(14,0);
Jesse 0:ad772c4ebc42 102 lcd.printf(" ");
Jesse 0:ad772c4ebc42 103 lcd.locate(14,0);
Jesse 0:ad772c4ebc42 104 lcd.printf("%d", Dd);
Jesse 0:ad772c4ebc42 105 }
Jesse 0:ad772c4ebc42 106 else if (p==6)
Jesse 0:ad772c4ebc42 107 {
Jesse 0:ad772c4ebc42 108 ++Pp;
Jesse 0:ad772c4ebc42 109 lcd.locate(14,1);
Jesse 0:ad772c4ebc42 110 lcd.printf(" ");
Jesse 0:ad772c4ebc42 111 lcd.locate(14,1);
Jesse 0:ad772c4ebc42 112 lcd.printf("%d", Pp);
Jesse 0:ad772c4ebc42 113 }
Jesse 0:ad772c4ebc42 114 }
Jesse 0:ad772c4ebc42 115 if (button2.falling())
Jesse 0:ad772c4ebc42 116 {
Jesse 0:ad772c4ebc42 117
Jesse 0:ad772c4ebc42 118 Pwm.write(0.1);
Jesse 0:ad772c4ebc42 119 wait(0.1);
Jesse 0:ad772c4ebc42 120 Pwm.write(0);
Jesse 0:ad772c4ebc42 121 wait(0.1);
Jesse 0:ad772c4ebc42 122 //Pwm.period_us(2000);
Jesse 0:ad772c4ebc42 123 //Pwm.write(0.5);
Jesse 0:ad772c4ebc42 124 //wait(0.025);
Jesse 0:ad772c4ebc42 125 led2 =!led2;
Jesse 0:ad772c4ebc42 126 if (p==1)
Jesse 0:ad772c4ebc42 127 {
Jesse 0:ad772c4ebc42 128 if (sp==0) // no mostrar nada
Jesse 0:ad772c4ebc42 129 {
Jesse 0:ad772c4ebc42 130 }
Jesse 0:ad772c4ebc42 131 else
Jesse 0:ad772c4ebc42 132 {
Jesse 0:ad772c4ebc42 133 --sp;
Jesse 0:ad772c4ebc42 134 lcd.locate(3,0);
Jesse 0:ad772c4ebc42 135 lcd.printf(" ");
Jesse 0:ad772c4ebc42 136 lcd.locate(3,0);
Jesse 0:ad772c4ebc42 137 lcd.printf("%d", sp);
Jesse 0:ad772c4ebc42 138 }
Jesse 0:ad772c4ebc42 139 }
Jesse 0:ad772c4ebc42 140 if (p==2)
Jesse 0:ad772c4ebc42 141 {
Jesse 0:ad772c4ebc42 142 if (kp==0) // no mostrar nada
Jesse 0:ad772c4ebc42 143 {
Jesse 0:ad772c4ebc42 144 }
Jesse 0:ad772c4ebc42 145 else
Jesse 0:ad772c4ebc42 146 {
Jesse 0:ad772c4ebc42 147 --kp;
Jesse 0:ad772c4ebc42 148 lcd.locate(9,0);
Jesse 0:ad772c4ebc42 149 lcd.printf(" ");
Jesse 0:ad772c4ebc42 150 lcd.locate(9,0);
Jesse 0:ad772c4ebc42 151 lcd.printf("%d", kp);
Jesse 0:ad772c4ebc42 152 }
Jesse 0:ad772c4ebc42 153 }
Jesse 0:ad772c4ebc42 154 if (p==3)
Jesse 0:ad772c4ebc42 155 {
Jesse 0:ad772c4ebc42 156 if (ki==0) // no mostrar nada
Jesse 0:ad772c4ebc42 157 {
Jesse 0:ad772c4ebc42 158 }
Jesse 0:ad772c4ebc42 159 else
Jesse 0:ad772c4ebc42 160 {
Jesse 0:ad772c4ebc42 161 --ki;
Jesse 0:ad772c4ebc42 162 lcd.locate(3,1);
Jesse 0:ad772c4ebc42 163 lcd.printf(" ");
Jesse 0:ad772c4ebc42 164 lcd.locate(3,1);
Jesse 0:ad772c4ebc42 165 lcd.printf("%d", ki);
Jesse 0:ad772c4ebc42 166 }
Jesse 0:ad772c4ebc42 167 }
Jesse 0:ad772c4ebc42 168 if (p==4)
Jesse 0:ad772c4ebc42 169 {
Jesse 0:ad772c4ebc42 170 if (kd==0) // no mostrar nada
Jesse 0:ad772c4ebc42 171 {
Jesse 0:ad772c4ebc42 172 }
Jesse 0:ad772c4ebc42 173 else
Jesse 0:ad772c4ebc42 174 {
Jesse 0:ad772c4ebc42 175 --kd;
Jesse 0:ad772c4ebc42 176 lcd.locate(9,1);
Jesse 0:ad772c4ebc42 177 lcd.printf(" ");
Jesse 0:ad772c4ebc42 178 lcd.locate(9,1);
Jesse 0:ad772c4ebc42 179 lcd.printf("%d", kd);
Jesse 0:ad772c4ebc42 180 }
Jesse 0:ad772c4ebc42 181 }
Jesse 0:ad772c4ebc42 182 if (p==5)
Jesse 0:ad772c4ebc42 183 {
Jesse 0:ad772c4ebc42 184 if (Dd==1) // no mostrar nada
Jesse 0:ad772c4ebc42 185 {
Jesse 0:ad772c4ebc42 186 }
Jesse 0:ad772c4ebc42 187 else
Jesse 0:ad772c4ebc42 188 {
Jesse 0:ad772c4ebc42 189 --Dd;
Jesse 0:ad772c4ebc42 190 lcd.locate(14,0);
Jesse 0:ad772c4ebc42 191 lcd.printf(" ");
Jesse 0:ad772c4ebc42 192 lcd.locate(14,0);
Jesse 0:ad772c4ebc42 193 lcd.printf("%d", Dd);
Jesse 0:ad772c4ebc42 194 }
Jesse 0:ad772c4ebc42 195 }
Jesse 0:ad772c4ebc42 196 if (p==6)
Jesse 0:ad772c4ebc42 197 {
Jesse 0:ad772c4ebc42 198 if (Pp==0) // no mostrar nada
Jesse 0:ad772c4ebc42 199 {
Jesse 0:ad772c4ebc42 200 }
Jesse 0:ad772c4ebc42 201 else
Jesse 0:ad772c4ebc42 202 {
Jesse 0:ad772c4ebc42 203 --Pp;
Jesse 0:ad772c4ebc42 204 lcd.locate(14,1);
Jesse 0:ad772c4ebc42 205 lcd.printf(" ");
Jesse 0:ad772c4ebc42 206 lcd.locate(14,1);
Jesse 0:ad772c4ebc42 207 lcd.printf("%d", Pp);
Jesse 0:ad772c4ebc42 208 }
Jesse 0:ad772c4ebc42 209 }
Jesse 0:ad772c4ebc42 210 }
Jesse 0:ad772c4ebc42 211 if (button3.falling())
Jesse 0:ad772c4ebc42 212 {
Jesse 0:ad772c4ebc42 213
Jesse 0:ad772c4ebc42 214 Pwm.write(0.1);
Jesse 0:ad772c4ebc42 215 wait(0.1);
Jesse 0:ad772c4ebc42 216 Pwm.write(0);
Jesse 0:ad772c4ebc42 217 wait(0.1);
Jesse 0:ad772c4ebc42 218 led3 =!led3;
Jesse 0:ad772c4ebc42 219 if (p==1)
Jesse 0:ad772c4ebc42 220 {
Jesse 0:ad772c4ebc42 221 ++p;
Jesse 0:ad772c4ebc42 222 lcd.locate(9,0);
Jesse 0:ad772c4ebc42 223 lcd.printf("%d", kp);
Jesse 0:ad772c4ebc42 224
Jesse 0:ad772c4ebc42 225
Jesse 0:ad772c4ebc42 226
Jesse 0:ad772c4ebc42 227 }
Jesse 0:ad772c4ebc42 228 else if (p==2)
Jesse 0:ad772c4ebc42 229 {
Jesse 0:ad772c4ebc42 230 ++p;
Jesse 0:ad772c4ebc42 231 lcd.locate(3,1);
Jesse 0:ad772c4ebc42 232 lcd.printf("%d", ki);
Jesse 0:ad772c4ebc42 233 lcd.locate(3,1);
Jesse 0:ad772c4ebc42 234
Jesse 0:ad772c4ebc42 235 }
Jesse 0:ad772c4ebc42 236 else if (p==3)
Jesse 0:ad772c4ebc42 237 {
Jesse 0:ad772c4ebc42 238 ++p;
Jesse 0:ad772c4ebc42 239 lcd.locate(9,1);
Jesse 0:ad772c4ebc42 240 lcd.printf("%d", kd);
Jesse 0:ad772c4ebc42 241
Jesse 0:ad772c4ebc42 242
Jesse 0:ad772c4ebc42 243 }
Jesse 0:ad772c4ebc42 244 else if (p==4)
Jesse 0:ad772c4ebc42 245 {
Jesse 0:ad772c4ebc42 246 ++p;
Jesse 0:ad772c4ebc42 247 lcd.locate(3,0);
Jesse 0:ad772c4ebc42 248 lcd.printf("%d", sp);
Jesse 0:ad772c4ebc42 249
Jesse 0:ad772c4ebc42 250
Jesse 0:ad772c4ebc42 251 }
Jesse 0:ad772c4ebc42 252 else if (p==5)
Jesse 0:ad772c4ebc42 253 {
Jesse 0:ad772c4ebc42 254 ++p;
Jesse 0:ad772c4ebc42 255 lcd.locate(14,0);
Jesse 0:ad772c4ebc42 256 lcd.printf("%d", Dd);
Jesse 0:ad772c4ebc42 257
Jesse 0:ad772c4ebc42 258
Jesse 0:ad772c4ebc42 259 }
Jesse 0:ad772c4ebc42 260 else if (p==6)
Jesse 0:ad772c4ebc42 261 {
Jesse 0:ad772c4ebc42 262 p=1;
Jesse 0:ad772c4ebc42 263 lcd.locate(14,1);
Jesse 0:ad772c4ebc42 264 lcd.printf("%d", Pp);
Jesse 0:ad772c4ebc42 265 //p=1;
Jesse 0:ad772c4ebc42 266
Jesse 0:ad772c4ebc42 267
Jesse 0:ad772c4ebc42 268 }
Jesse 0:ad772c4ebc42 269 }
Jesse 0:ad772c4ebc42 270 }
Jesse 0:ad772c4ebc42 271 }