![](/media/cache/profiles/53015ad3b6bbbf80a4d107e6ef603b1e.jpg.50x50_q85.jpg)
En este programa se agrego la funcionalidad de incremento y decremento por gradiente a los botones también se creo una rutina para el anti-rebote de los botones sin usar librería
main.cpp@0:c476b1e3e7a3, 2013-10-16 (annotated)
- Committer:
- amarincan
- Date:
- Wed Oct 16 16:52:40 2013 +0000
- Revision:
- 0:c476b1e3e7a3
En este programa se agrego la funcionalidad de incremento y decremento con gradiente y se utilizo una t?cnica para eliminar el anti-rebote de los botones sin usar librer?as
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
amarincan | 0:c476b1e3e7a3 | 1 | #include "mbed.h" |
amarincan | 0:c476b1e3e7a3 | 2 | #include "TextLCD.h" |
amarincan | 0:c476b1e3e7a3 | 3 | |
amarincan | 0:c476b1e3e7a3 | 4 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 |
amarincan | 0:c476b1e3e7a3 | 5 | int i,Sp=0,Kp,Ki,Kd,j; |
amarincan | 0:c476b1e3e7a3 | 6 | DigitalOut l1(LED1); |
amarincan | 0:c476b1e3e7a3 | 7 | DigitalOut l2(LED2); |
amarincan | 0:c476b1e3e7a3 | 8 | int main() |
amarincan | 0:c476b1e3e7a3 | 9 | { |
amarincan | 0:c476b1e3e7a3 | 10 | |
amarincan | 0:c476b1e3e7a3 | 11 | DigitalIn button1(PTC12); |
amarincan | 0:c476b1e3e7a3 | 12 | DigitalIn button2(PTC13); |
amarincan | 0:c476b1e3e7a3 | 13 | DigitalIn button3(PTC16); |
amarincan | 0:c476b1e3e7a3 | 14 | lcd.writeCommand(0x0E); |
amarincan | 0:c476b1e3e7a3 | 15 | lcd.printf("Sp= Kp="); |
amarincan | 0:c476b1e3e7a3 | 16 | lcd.locate(0,1); |
amarincan | 0:c476b1e3e7a3 | 17 | lcd.printf("Ki= Kd="); |
amarincan | 0:c476b1e3e7a3 | 18 | lcd.locate(2,0); |
amarincan | 0:c476b1e3e7a3 | 19 | lcd.printf("="); |
amarincan | 0:c476b1e3e7a3 | 20 | |
amarincan | 0:c476b1e3e7a3 | 21 | while(1) { |
amarincan | 0:c476b1e3e7a3 | 22 | |
amarincan | 0:c476b1e3e7a3 | 23 | if (!button1) { |
amarincan | 0:c476b1e3e7a3 | 24 | switch(i) { |
amarincan | 0:c476b1e3e7a3 | 25 | case 0: |
amarincan | 0:c476b1e3e7a3 | 26 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 27 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 28 | while(!button1) { |
amarincan | 0:c476b1e3e7a3 | 29 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 30 | j++; |
amarincan | 0:c476b1e3e7a3 | 31 | Sp+=1; |
amarincan | 0:c476b1e3e7a3 | 32 | } |
amarincan | 0:c476b1e3e7a3 | 33 | if((j>=6)&&(j<11)&&(Sp<9999)) { |
amarincan | 0:c476b1e3e7a3 | 34 | j++; |
amarincan | 0:c476b1e3e7a3 | 35 | Sp+=10; |
amarincan | 0:c476b1e3e7a3 | 36 | } |
amarincan | 0:c476b1e3e7a3 | 37 | if((j>=11)&&(j<16)&&(Sp<9999)) { |
amarincan | 0:c476b1e3e7a3 | 38 | j++; |
amarincan | 0:c476b1e3e7a3 | 39 | Sp+=100; |
amarincan | 0:c476b1e3e7a3 | 40 | } |
amarincan | 0:c476b1e3e7a3 | 41 | if((j>=16)&&(Sp<9999)) { |
amarincan | 0:c476b1e3e7a3 | 42 | j++; |
amarincan | 0:c476b1e3e7a3 | 43 | Sp+=500; |
amarincan | 0:c476b1e3e7a3 | 44 | } |
amarincan | 0:c476b1e3e7a3 | 45 | if(Sp>9999) |
amarincan | 0:c476b1e3e7a3 | 46 | Sp=9999; |
amarincan | 0:c476b1e3e7a3 | 47 | lcd.locate(2,0); |
amarincan | 0:c476b1e3e7a3 | 48 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 49 | lcd.locate(3,0); |
amarincan | 0:c476b1e3e7a3 | 50 | lcd.printf("%d",Sp); |
amarincan | 0:c476b1e3e7a3 | 51 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 52 | } |
amarincan | 0:c476b1e3e7a3 | 53 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 54 | ++Sp; |
amarincan | 0:c476b1e3e7a3 | 55 | if(Sp>9999) |
amarincan | 0:c476b1e3e7a3 | 56 | Sp=9999; |
amarincan | 0:c476b1e3e7a3 | 57 | lcd.locate(2,0); |
amarincan | 0:c476b1e3e7a3 | 58 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 59 | lcd.locate(3,0); |
amarincan | 0:c476b1e3e7a3 | 60 | lcd.printf("%d",Sp); |
amarincan | 0:c476b1e3e7a3 | 61 | break; |
amarincan | 0:c476b1e3e7a3 | 62 | case 1: |
amarincan | 0:c476b1e3e7a3 | 63 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 64 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 65 | while(!button1) { |
amarincan | 0:c476b1e3e7a3 | 66 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 67 | j++; |
amarincan | 0:c476b1e3e7a3 | 68 | Kp+=1; |
amarincan | 0:c476b1e3e7a3 | 69 | } |
amarincan | 0:c476b1e3e7a3 | 70 | if((j>=6)&&(j<11)&&(Kp<9999)) { |
amarincan | 0:c476b1e3e7a3 | 71 | j++; |
amarincan | 0:c476b1e3e7a3 | 72 | Kp+=10; |
amarincan | 0:c476b1e3e7a3 | 73 | } |
amarincan | 0:c476b1e3e7a3 | 74 | if((j>=11)&&(j<16)&&(Kp<9999)) { |
amarincan | 0:c476b1e3e7a3 | 75 | j++; |
amarincan | 0:c476b1e3e7a3 | 76 | Kp+=100; |
amarincan | 0:c476b1e3e7a3 | 77 | } |
amarincan | 0:c476b1e3e7a3 | 78 | if((j>=16)&&(Kp<9999)) { |
amarincan | 0:c476b1e3e7a3 | 79 | j++; |
amarincan | 0:c476b1e3e7a3 | 80 | Kp+=500; |
amarincan | 0:c476b1e3e7a3 | 81 | } |
amarincan | 0:c476b1e3e7a3 | 82 | if(Kp>9999) |
amarincan | 0:c476b1e3e7a3 | 83 | Kp=9999; |
amarincan | 0:c476b1e3e7a3 | 84 | lcd.locate(10,0); |
amarincan | 0:c476b1e3e7a3 | 85 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 86 | lcd.locate(11,0); |
amarincan | 0:c476b1e3e7a3 | 87 | lcd.printf("%d",Kp); |
amarincan | 0:c476b1e3e7a3 | 88 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 89 | } |
amarincan | 0:c476b1e3e7a3 | 90 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 91 | ++Kp; |
amarincan | 0:c476b1e3e7a3 | 92 | if(Kp>9999) |
amarincan | 0:c476b1e3e7a3 | 93 | Kp=9999; |
amarincan | 0:c476b1e3e7a3 | 94 | lcd.locate(10,0); |
amarincan | 0:c476b1e3e7a3 | 95 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 96 | lcd.locate(11,0); |
amarincan | 0:c476b1e3e7a3 | 97 | lcd.printf("%d",Kp); |
amarincan | 0:c476b1e3e7a3 | 98 | break; |
amarincan | 0:c476b1e3e7a3 | 99 | case 2: |
amarincan | 0:c476b1e3e7a3 | 100 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 101 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 102 | while(!button1) { |
amarincan | 0:c476b1e3e7a3 | 103 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 104 | j++; |
amarincan | 0:c476b1e3e7a3 | 105 | Ki+=1; |
amarincan | 0:c476b1e3e7a3 | 106 | } |
amarincan | 0:c476b1e3e7a3 | 107 | if((j>=6)&&(j<11)&&(Ki<9999)) { |
amarincan | 0:c476b1e3e7a3 | 108 | j++; |
amarincan | 0:c476b1e3e7a3 | 109 | Ki+=10; |
amarincan | 0:c476b1e3e7a3 | 110 | } |
amarincan | 0:c476b1e3e7a3 | 111 | if((j>=11)&&(j<16)&&(Ki<9999)) { |
amarincan | 0:c476b1e3e7a3 | 112 | j++; |
amarincan | 0:c476b1e3e7a3 | 113 | Ki+=100; |
amarincan | 0:c476b1e3e7a3 | 114 | } |
amarincan | 0:c476b1e3e7a3 | 115 | if((j>=16)&&(Ki<9999)) { |
amarincan | 0:c476b1e3e7a3 | 116 | j++; |
amarincan | 0:c476b1e3e7a3 | 117 | Ki+=500; |
amarincan | 0:c476b1e3e7a3 | 118 | } |
amarincan | 0:c476b1e3e7a3 | 119 | if(Ki>9999) |
amarincan | 0:c476b1e3e7a3 | 120 | Ki=9999; |
amarincan | 0:c476b1e3e7a3 | 121 | lcd.locate(2,1); |
amarincan | 0:c476b1e3e7a3 | 122 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 123 | lcd.locate(3,1); |
amarincan | 0:c476b1e3e7a3 | 124 | lcd.printf("%d",Ki); |
amarincan | 0:c476b1e3e7a3 | 125 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 126 | } |
amarincan | 0:c476b1e3e7a3 | 127 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 128 | ++Ki; |
amarincan | 0:c476b1e3e7a3 | 129 | if(Ki>9999) |
amarincan | 0:c476b1e3e7a3 | 130 | Ki=9999; |
amarincan | 0:c476b1e3e7a3 | 131 | lcd.locate(2,1); |
amarincan | 0:c476b1e3e7a3 | 132 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 133 | lcd.locate(3,1); |
amarincan | 0:c476b1e3e7a3 | 134 | lcd.printf("%d",Ki); |
amarincan | 0:c476b1e3e7a3 | 135 | break; |
amarincan | 0:c476b1e3e7a3 | 136 | case 3: |
amarincan | 0:c476b1e3e7a3 | 137 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 138 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 139 | while(!button1) { |
amarincan | 0:c476b1e3e7a3 | 140 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 141 | j++; |
amarincan | 0:c476b1e3e7a3 | 142 | Kd+=1; |
amarincan | 0:c476b1e3e7a3 | 143 | } |
amarincan | 0:c476b1e3e7a3 | 144 | if((j>=6)&&(j<11)&&(Kd<9999)) { |
amarincan | 0:c476b1e3e7a3 | 145 | j++; |
amarincan | 0:c476b1e3e7a3 | 146 | Kd+=10; |
amarincan | 0:c476b1e3e7a3 | 147 | } |
amarincan | 0:c476b1e3e7a3 | 148 | if((j>=11)&&(j<16)&&(Kd<9999)) { |
amarincan | 0:c476b1e3e7a3 | 149 | j++; |
amarincan | 0:c476b1e3e7a3 | 150 | Kd+=100; |
amarincan | 0:c476b1e3e7a3 | 151 | } |
amarincan | 0:c476b1e3e7a3 | 152 | if((j>=16)&&(Kd<9999)) { |
amarincan | 0:c476b1e3e7a3 | 153 | j++; |
amarincan | 0:c476b1e3e7a3 | 154 | Kd+=500; |
amarincan | 0:c476b1e3e7a3 | 155 | } |
amarincan | 0:c476b1e3e7a3 | 156 | if(Kd>9999) |
amarincan | 0:c476b1e3e7a3 | 157 | Kd=9999; |
amarincan | 0:c476b1e3e7a3 | 158 | lcd.locate(10,1); |
amarincan | 0:c476b1e3e7a3 | 159 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 160 | lcd.locate(11,1); |
amarincan | 0:c476b1e3e7a3 | 161 | lcd.printf("%d",Kd); |
amarincan | 0:c476b1e3e7a3 | 162 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 163 | } |
amarincan | 0:c476b1e3e7a3 | 164 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 165 | ++Kd; |
amarincan | 0:c476b1e3e7a3 | 166 | if(Kd>9999) |
amarincan | 0:c476b1e3e7a3 | 167 | Kd=9999; |
amarincan | 0:c476b1e3e7a3 | 168 | lcd.locate(10,1); |
amarincan | 0:c476b1e3e7a3 | 169 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 170 | lcd.locate(11,1); |
amarincan | 0:c476b1e3e7a3 | 171 | lcd.printf("%d",Kd); |
amarincan | 0:c476b1e3e7a3 | 172 | break; |
amarincan | 0:c476b1e3e7a3 | 173 | } |
amarincan | 0:c476b1e3e7a3 | 174 | } |
amarincan | 0:c476b1e3e7a3 | 175 | j=0; |
amarincan | 0:c476b1e3e7a3 | 176 | if (!button2) { |
amarincan | 0:c476b1e3e7a3 | 177 | switch(i) { |
amarincan | 0:c476b1e3e7a3 | 178 | case 0: |
amarincan | 0:c476b1e3e7a3 | 179 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 180 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 181 | while(!button2) { |
amarincan | 0:c476b1e3e7a3 | 182 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 183 | j++; |
amarincan | 0:c476b1e3e7a3 | 184 | Sp-=1; |
amarincan | 0:c476b1e3e7a3 | 185 | } |
amarincan | 0:c476b1e3e7a3 | 186 | if((j>=6)&&(j<11)&&(Sp>0)) { |
amarincan | 0:c476b1e3e7a3 | 187 | j++; |
amarincan | 0:c476b1e3e7a3 | 188 | Sp-=10; |
amarincan | 0:c476b1e3e7a3 | 189 | } |
amarincan | 0:c476b1e3e7a3 | 190 | if((j>=11)&&(j<16)&&(Sp>0)) { |
amarincan | 0:c476b1e3e7a3 | 191 | j++; |
amarincan | 0:c476b1e3e7a3 | 192 | Sp-=100; |
amarincan | 0:c476b1e3e7a3 | 193 | } |
amarincan | 0:c476b1e3e7a3 | 194 | if((j>=16)&&(Sp>0)) { |
amarincan | 0:c476b1e3e7a3 | 195 | j++; |
amarincan | 0:c476b1e3e7a3 | 196 | Sp-=500; |
amarincan | 0:c476b1e3e7a3 | 197 | } |
amarincan | 0:c476b1e3e7a3 | 198 | if(Sp<0) |
amarincan | 0:c476b1e3e7a3 | 199 | Sp=0; |
amarincan | 0:c476b1e3e7a3 | 200 | lcd.locate(2,0); |
amarincan | 0:c476b1e3e7a3 | 201 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 202 | lcd.locate(3,0); |
amarincan | 0:c476b1e3e7a3 | 203 | lcd.printf("%d",Sp); |
amarincan | 0:c476b1e3e7a3 | 204 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 205 | } |
amarincan | 0:c476b1e3e7a3 | 206 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 207 | --Sp; |
amarincan | 0:c476b1e3e7a3 | 208 | if(Sp<0) |
amarincan | 0:c476b1e3e7a3 | 209 | Sp=0; |
amarincan | 0:c476b1e3e7a3 | 210 | lcd.locate(2,0); |
amarincan | 0:c476b1e3e7a3 | 211 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 212 | lcd.locate(3,0); |
amarincan | 0:c476b1e3e7a3 | 213 | lcd.printf("%d",Sp); |
amarincan | 0:c476b1e3e7a3 | 214 | break; |
amarincan | 0:c476b1e3e7a3 | 215 | case 1: |
amarincan | 0:c476b1e3e7a3 | 216 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 217 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 218 | while(!button2) { |
amarincan | 0:c476b1e3e7a3 | 219 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 220 | j++; |
amarincan | 0:c476b1e3e7a3 | 221 | Kp-=1; |
amarincan | 0:c476b1e3e7a3 | 222 | } |
amarincan | 0:c476b1e3e7a3 | 223 | if((j>=6)&&(j<11)&&(Kp>0)) { |
amarincan | 0:c476b1e3e7a3 | 224 | j++; |
amarincan | 0:c476b1e3e7a3 | 225 | Kp-=10; |
amarincan | 0:c476b1e3e7a3 | 226 | } |
amarincan | 0:c476b1e3e7a3 | 227 | if((j>=11)&&(j<16)&&(Kp>0)) { |
amarincan | 0:c476b1e3e7a3 | 228 | j++; |
amarincan | 0:c476b1e3e7a3 | 229 | Kp-=100; |
amarincan | 0:c476b1e3e7a3 | 230 | } |
amarincan | 0:c476b1e3e7a3 | 231 | if((j>=16)&&(Kp>0)) { |
amarincan | 0:c476b1e3e7a3 | 232 | j++; |
amarincan | 0:c476b1e3e7a3 | 233 | Kp-=500; |
amarincan | 0:c476b1e3e7a3 | 234 | } |
amarincan | 0:c476b1e3e7a3 | 235 | if(Kp<0) |
amarincan | 0:c476b1e3e7a3 | 236 | Kp=0; |
amarincan | 0:c476b1e3e7a3 | 237 | lcd.locate(10,0); |
amarincan | 0:c476b1e3e7a3 | 238 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 239 | lcd.locate(11,0); |
amarincan | 0:c476b1e3e7a3 | 240 | lcd.printf("%d",Kp); |
amarincan | 0:c476b1e3e7a3 | 241 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 242 | } |
amarincan | 0:c476b1e3e7a3 | 243 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 244 | --Kp; |
amarincan | 0:c476b1e3e7a3 | 245 | if(Kp<0) |
amarincan | 0:c476b1e3e7a3 | 246 | Kp=0; |
amarincan | 0:c476b1e3e7a3 | 247 | lcd.locate(10,0); |
amarincan | 0:c476b1e3e7a3 | 248 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 249 | lcd.locate(11,0); |
amarincan | 0:c476b1e3e7a3 | 250 | lcd.printf("%d",Kp); |
amarincan | 0:c476b1e3e7a3 | 251 | break; |
amarincan | 0:c476b1e3e7a3 | 252 | case 2: |
amarincan | 0:c476b1e3e7a3 | 253 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 254 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 255 | while(!button2) { |
amarincan | 0:c476b1e3e7a3 | 256 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 257 | j++; |
amarincan | 0:c476b1e3e7a3 | 258 | Ki-=1; |
amarincan | 0:c476b1e3e7a3 | 259 | } |
amarincan | 0:c476b1e3e7a3 | 260 | if((j>=6)&&(j<11)&&(Ki>0)) { |
amarincan | 0:c476b1e3e7a3 | 261 | j++; |
amarincan | 0:c476b1e3e7a3 | 262 | Ki-=10; |
amarincan | 0:c476b1e3e7a3 | 263 | } |
amarincan | 0:c476b1e3e7a3 | 264 | if((j>=11)&&(j<16)&&(Ki>0)) { |
amarincan | 0:c476b1e3e7a3 | 265 | j++; |
amarincan | 0:c476b1e3e7a3 | 266 | Ki-=100; |
amarincan | 0:c476b1e3e7a3 | 267 | } |
amarincan | 0:c476b1e3e7a3 | 268 | if((j>=16)&&(Ki>0)) { |
amarincan | 0:c476b1e3e7a3 | 269 | j++; |
amarincan | 0:c476b1e3e7a3 | 270 | Ki-=500; |
amarincan | 0:c476b1e3e7a3 | 271 | } |
amarincan | 0:c476b1e3e7a3 | 272 | if(Ki<0) |
amarincan | 0:c476b1e3e7a3 | 273 | Ki=0; |
amarincan | 0:c476b1e3e7a3 | 274 | lcd.locate(2,1); |
amarincan | 0:c476b1e3e7a3 | 275 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 276 | lcd.locate(3,1); |
amarincan | 0:c476b1e3e7a3 | 277 | lcd.printf("%d",Ki); |
amarincan | 0:c476b1e3e7a3 | 278 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 279 | } |
amarincan | 0:c476b1e3e7a3 | 280 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 281 | --Ki; |
amarincan | 0:c476b1e3e7a3 | 282 | if(Ki<0) |
amarincan | 0:c476b1e3e7a3 | 283 | Ki=0; |
amarincan | 0:c476b1e3e7a3 | 284 | lcd.locate(2,1); |
amarincan | 0:c476b1e3e7a3 | 285 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 286 | lcd.locate(3,1); |
amarincan | 0:c476b1e3e7a3 | 287 | lcd.printf("%d",Ki); |
amarincan | 0:c476b1e3e7a3 | 288 | break; |
amarincan | 0:c476b1e3e7a3 | 289 | case 3: |
amarincan | 0:c476b1e3e7a3 | 290 | wait(0.5); |
amarincan | 0:c476b1e3e7a3 | 291 | j++; // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 292 | while(!button1) { |
amarincan | 0:c476b1e3e7a3 | 293 | if((j>=1) &&(j<6)) { |
amarincan | 0:c476b1e3e7a3 | 294 | j++; |
amarincan | 0:c476b1e3e7a3 | 295 | Kd-=1; |
amarincan | 0:c476b1e3e7a3 | 296 | } |
amarincan | 0:c476b1e3e7a3 | 297 | if((j>=6)&&(j<11)&&(Kd>0)) { |
amarincan | 0:c476b1e3e7a3 | 298 | j++; |
amarincan | 0:c476b1e3e7a3 | 299 | Kd-=10; |
amarincan | 0:c476b1e3e7a3 | 300 | } |
amarincan | 0:c476b1e3e7a3 | 301 | if((j>=11)&&(j<16)&&(Kd>0)) { |
amarincan | 0:c476b1e3e7a3 | 302 | j++; |
amarincan | 0:c476b1e3e7a3 | 303 | Kd-=100; |
amarincan | 0:c476b1e3e7a3 | 304 | } |
amarincan | 0:c476b1e3e7a3 | 305 | if((j>=16)&&(Kd>0)) { |
amarincan | 0:c476b1e3e7a3 | 306 | j++; |
amarincan | 0:c476b1e3e7a3 | 307 | Kd-=500; |
amarincan | 0:c476b1e3e7a3 | 308 | } |
amarincan | 0:c476b1e3e7a3 | 309 | if(Kd>0) |
amarincan | 0:c476b1e3e7a3 | 310 | Kd=0; |
amarincan | 0:c476b1e3e7a3 | 311 | lcd.locate(10,1); |
amarincan | 0:c476b1e3e7a3 | 312 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 313 | lcd.locate(11,1); |
amarincan | 0:c476b1e3e7a3 | 314 | lcd.printf("%d",Kd); |
amarincan | 0:c476b1e3e7a3 | 315 | wait(1); |
amarincan | 0:c476b1e3e7a3 | 316 | } |
amarincan | 0:c476b1e3e7a3 | 317 | if(j==1) |
amarincan | 0:c476b1e3e7a3 | 318 | ++Kd; |
amarincan | 0:c476b1e3e7a3 | 319 | if(Kd>0) |
amarincan | 0:c476b1e3e7a3 | 320 | Kd=0; |
amarincan | 0:c476b1e3e7a3 | 321 | lcd.locate(10,1); |
amarincan | 0:c476b1e3e7a3 | 322 | lcd.printf("= "); |
amarincan | 0:c476b1e3e7a3 | 323 | lcd.locate(11,1); |
amarincan | 0:c476b1e3e7a3 | 324 | lcd.printf("%d",Kd); |
amarincan | 0:c476b1e3e7a3 | 325 | break; |
amarincan | 0:c476b1e3e7a3 | 326 | } |
amarincan | 0:c476b1e3e7a3 | 327 | } |
amarincan | 0:c476b1e3e7a3 | 328 | j=0; |
amarincan | 0:c476b1e3e7a3 | 329 | if(!button3) { |
amarincan | 0:c476b1e3e7a3 | 330 | wait(0.5); // <-----ANTIREBOTE AQUI!!! |
amarincan | 0:c476b1e3e7a3 | 331 | while(!button1); |
amarincan | 0:c476b1e3e7a3 | 332 | i++; |
amarincan | 0:c476b1e3e7a3 | 333 | if(i>3) |
amarincan | 0:c476b1e3e7a3 | 334 | i=0; |
amarincan | 0:c476b1e3e7a3 | 335 | switch (i) { |
amarincan | 0:c476b1e3e7a3 | 336 | case 0: |
amarincan | 0:c476b1e3e7a3 | 337 | lcd.locate(2,0); |
amarincan | 0:c476b1e3e7a3 | 338 | lcd.printf("="); |
amarincan | 0:c476b1e3e7a3 | 339 | break; |
amarincan | 0:c476b1e3e7a3 | 340 | case 1: |
amarincan | 0:c476b1e3e7a3 | 341 | lcd.locate(10,0); |
amarincan | 0:c476b1e3e7a3 | 342 | lcd.printf("="); |
amarincan | 0:c476b1e3e7a3 | 343 | break; |
amarincan | 0:c476b1e3e7a3 | 344 | case 2: |
amarincan | 0:c476b1e3e7a3 | 345 | lcd.locate(2,1); |
amarincan | 0:c476b1e3e7a3 | 346 | lcd.printf("="); |
amarincan | 0:c476b1e3e7a3 | 347 | break; |
amarincan | 0:c476b1e3e7a3 | 348 | case 3: |
amarincan | 0:c476b1e3e7a3 | 349 | lcd.locate(10,1); |
amarincan | 0:c476b1e3e7a3 | 350 | lcd.printf("="); |
amarincan | 0:c476b1e3e7a3 | 351 | break; |
amarincan | 0:c476b1e3e7a3 | 352 | } |
amarincan | 0:c476b1e3e7a3 | 353 | } |
amarincan | 0:c476b1e3e7a3 | 354 | } |
amarincan | 0:c476b1e3e7a3 | 355 | } |