algo

Dependencies:   Debounced TextLCD2 mbed

Fork of tarea2 by Laura Corrales

Committer:
lcorralesc1
Date:
Wed Oct 30 15:49:35 2013 +0000
Revision:
0:3883458d6df5
Child:
1:bf54a30a2b14
Incremental

Who changed what in which revision?

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