Tarea2, procesadores
Dependencies: Debounced TextLCDm mbed
main.cpp@0:62bc56579cdb, 2013-11-10 (annotated)
- Committer:
- mandres7
- Date:
- Sun Nov 10 20:28:47 2013 +0000
- Revision:
- 0:62bc56579cdb
Incremento ascendendente y descendente en un display 16x2, dividio en 4 subfunciones, Sp, Kp, Ki, Kd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mandres7 | 0:62bc56579cdb | 1 | #include "mbed.h" |
mandres7 | 0:62bc56579cdb | 2 | #include "TextLCD.h" |
mandres7 | 0:62bc56579cdb | 3 | #include "DebouncedIn.h" |
mandres7 | 0:62bc56579cdb | 4 | |
mandres7 | 0:62bc56579cdb | 5 | TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7.. Nota: No se quiere función de lectura, luego ese puerto a tierra. |
mandres7 | 0:62bc56579cdb | 6 | //lectura=1, escritura=0 |
mandres7 | 0:62bc56579cdb | 7 | |
mandres7 | 0:62bc56579cdb | 8 | //Aumento en rampa de Sp, Kp, Ki, Kd |
mandres7 | 0:62bc56579cdb | 9 | PwmOut rled(LED_RED); |
mandres7 | 0:62bc56579cdb | 10 | |
mandres7 | 0:62bc56579cdb | 11 | DebouncedIn next(PTE2); |
mandres7 | 0:62bc56579cdb | 12 | DebouncedIn up(PTE3); |
mandres7 | 0:62bc56579cdb | 13 | DebouncedIn down(PTE4); |
mandres7 | 0:62bc56579cdb | 14 | |
mandres7 | 0:62bc56579cdb | 15 | Timer timer1; |
mandres7 | 0:62bc56579cdb | 16 | |
mandres7 | 0:62bc56579cdb | 17 | int C1=0x0F; |
mandres7 | 0:62bc56579cdb | 18 | int i,j,k,l; |
mandres7 | 0:62bc56579cdb | 19 | |
mandres7 | 0:62bc56579cdb | 20 | int main() { |
mandres7 | 0:62bc56579cdb | 21 | |
mandres7 | 0:62bc56579cdb | 22 | int c; |
mandres7 | 0:62bc56579cdb | 23 | c=0; |
mandres7 | 0:62bc56579cdb | 24 | |
mandres7 | 0:62bc56579cdb | 25 | lcd.cls(); |
mandres7 | 0:62bc56579cdb | 26 | lcd.locate(0,0); |
mandres7 | 0:62bc56579cdb | 27 | lcd.printf("sp:%d",i); |
mandres7 | 0:62bc56579cdb | 28 | lcd.locate(8,0); |
mandres7 | 0:62bc56579cdb | 29 | lcd.printf("kp:%d",j); |
mandres7 | 0:62bc56579cdb | 30 | lcd.locate(0,1); |
mandres7 | 0:62bc56579cdb | 31 | lcd.printf("ki:%d",k); |
mandres7 | 0:62bc56579cdb | 32 | lcd.locate(8,1); |
mandres7 | 0:62bc56579cdb | 33 | lcd.printf("kd:%d",l); |
mandres7 | 0:62bc56579cdb | 34 | |
mandres7 | 0:62bc56579cdb | 35 | //SP |
mandres7 | 0:62bc56579cdb | 36 | |
mandres7 | 0:62bc56579cdb | 37 | while (1){ |
mandres7 | 0:62bc56579cdb | 38 | |
mandres7 | 0:62bc56579cdb | 39 | if (next.falling()){ |
mandres7 | 0:62bc56579cdb | 40 | c++; |
mandres7 | 0:62bc56579cdb | 41 | } |
mandres7 | 0:62bc56579cdb | 42 | |
mandres7 | 0:62bc56579cdb | 43 | //Salto a SP |
mandres7 | 0:62bc56579cdb | 44 | if (c==0){ |
mandres7 | 0:62bc56579cdb | 45 | |
mandres7 | 0:62bc56579cdb | 46 | lcd.locate(3,0); |
mandres7 | 0:62bc56579cdb | 47 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 48 | lcd.writeCommand(C1); |
mandres7 | 0:62bc56579cdb | 49 | lcd.locate(3,0); |
mandres7 | 0:62bc56579cdb | 50 | lcd.printf("%d",i); |
mandres7 | 0:62bc56579cdb | 51 | |
mandres7 | 0:62bc56579cdb | 52 | while(c==0){ |
mandres7 | 0:62bc56579cdb | 53 | |
mandres7 | 0:62bc56579cdb | 54 | //espacio de trabajo |
mandres7 | 0:62bc56579cdb | 55 | |
mandres7 | 0:62bc56579cdb | 56 | if(up.falling()||down.falling()){ |
mandres7 | 0:62bc56579cdb | 57 | timer1.start(); |
mandres7 | 0:62bc56579cdb | 58 | |
mandres7 | 0:62bc56579cdb | 59 | while(up==0||down==0){ |
mandres7 | 0:62bc56579cdb | 60 | if(up==1&&down==1){ |
mandres7 | 0:62bc56579cdb | 61 | timer1.stop(); |
mandres7 | 0:62bc56579cdb | 62 | timer1.reset(); |
mandres7 | 0:62bc56579cdb | 63 | } |
mandres7 | 0:62bc56579cdb | 64 | if (timer1.read()>0&&timer1.read()<=5&&up==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 65 | ++i; |
mandres7 | 0:62bc56579cdb | 66 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 67 | } |
mandres7 | 0:62bc56579cdb | 68 | if (timer1.read()>0&&timer1.read()<=5&&down==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 69 | --i; |
mandres7 | 0:62bc56579cdb | 70 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 71 | } |
mandres7 | 0:62bc56579cdb | 72 | |
mandres7 | 0:62bc56579cdb | 73 | if (timer1.read()>5&&timer1.read()<=10&&up==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 74 | i+=5; |
mandres7 | 0:62bc56579cdb | 75 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 76 | } |
mandres7 | 0:62bc56579cdb | 77 | |
mandres7 | 0:62bc56579cdb | 78 | if (timer1.read()>5&&timer1.read()<=10&&down==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 79 | i-=5; |
mandres7 | 0:62bc56579cdb | 80 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 81 | } |
mandres7 | 0:62bc56579cdb | 82 | |
mandres7 | 0:62bc56579cdb | 83 | |
mandres7 | 0:62bc56579cdb | 84 | if (timer1.read()>10&&timer1.read()<=100&&up==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 85 | i+=10; |
mandres7 | 0:62bc56579cdb | 86 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 87 | } |
mandres7 | 0:62bc56579cdb | 88 | |
mandres7 | 0:62bc56579cdb | 89 | if (timer1.read()>10&&timer1.read()<=100&&down==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 90 | i-=10; |
mandres7 | 0:62bc56579cdb | 91 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 92 | } |
mandres7 | 0:62bc56579cdb | 93 | if (timer1.read()>10&&timer1.read()<=1000&&up==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 94 | i+=100; |
mandres7 | 0:62bc56579cdb | 95 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 96 | } |
mandres7 | 0:62bc56579cdb | 97 | |
mandres7 | 0:62bc56579cdb | 98 | if (timer1.read()>10&&timer1.read()<=1000&&down==0&&i>=0&&i<=9999) { |
mandres7 | 0:62bc56579cdb | 99 | i-=100; |
mandres7 | 0:62bc56579cdb | 100 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 101 | } |
mandres7 | 0:62bc56579cdb | 102 | |
mandres7 | 0:62bc56579cdb | 103 | if(i<0){ |
mandres7 | 0:62bc56579cdb | 104 | i=0; |
mandres7 | 0:62bc56579cdb | 105 | } |
mandres7 | 0:62bc56579cdb | 106 | |
mandres7 | 0:62bc56579cdb | 107 | if(i>9999){ |
mandres7 | 0:62bc56579cdb | 108 | i=9999; |
mandres7 | 0:62bc56579cdb | 109 | } |
mandres7 | 0:62bc56579cdb | 110 | |
mandres7 | 0:62bc56579cdb | 111 | //NEW !! (not zeros in -- process) |
mandres7 | 0:62bc56579cdb | 112 | if(i<10){ |
mandres7 | 0:62bc56579cdb | 113 | lcd.locate(4,0); |
mandres7 | 0:62bc56579cdb | 114 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 115 | } |
mandres7 | 0:62bc56579cdb | 116 | |
mandres7 | 0:62bc56579cdb | 117 | if(i<100){ |
mandres7 | 0:62bc56579cdb | 118 | lcd.locate(5,0); |
mandres7 | 0:62bc56579cdb | 119 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 120 | } |
mandres7 | 0:62bc56579cdb | 121 | |
mandres7 | 0:62bc56579cdb | 122 | if(i<1000){ |
mandres7 | 0:62bc56579cdb | 123 | lcd.locate(6,0); |
mandres7 | 0:62bc56579cdb | 124 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 125 | } |
mandres7 | 0:62bc56579cdb | 126 | // |
mandres7 | 0:62bc56579cdb | 127 | |
mandres7 | 0:62bc56579cdb | 128 | i=i; |
mandres7 | 0:62bc56579cdb | 129 | //lcd.locate(3,0); |
mandres7 | 0:62bc56579cdb | 130 | //lcd.printf(" "); |
mandres7 | 0:62bc56579cdb | 131 | lcd.locate(3,0); |
mandres7 | 0:62bc56579cdb | 132 | lcd.printf("%d", i); |
mandres7 | 0:62bc56579cdb | 133 | wait(0.2); |
mandres7 | 0:62bc56579cdb | 134 | |
mandres7 | 0:62bc56579cdb | 135 | } |
mandres7 | 0:62bc56579cdb | 136 | } |
mandres7 | 0:62bc56579cdb | 137 | |
mandres7 | 0:62bc56579cdb | 138 | //fin espacio de trabajo |
mandres7 | 0:62bc56579cdb | 139 | |
mandres7 | 0:62bc56579cdb | 140 | if(next.falling()){ |
mandres7 | 0:62bc56579cdb | 141 | c++; |
mandres7 | 0:62bc56579cdb | 142 | } |
mandres7 | 0:62bc56579cdb | 143 | } |
mandres7 | 0:62bc56579cdb | 144 | } |
mandres7 | 0:62bc56579cdb | 145 | |
mandres7 | 0:62bc56579cdb | 146 | |
mandres7 | 0:62bc56579cdb | 147 | //Salto a Kp |
mandres7 | 0:62bc56579cdb | 148 | if (c==1){ |
mandres7 | 0:62bc56579cdb | 149 | |
mandres7 | 0:62bc56579cdb | 150 | lcd.locate(11,0); |
mandres7 | 0:62bc56579cdb | 151 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 152 | lcd.writeCommand(C1); |
mandres7 | 0:62bc56579cdb | 153 | lcd.locate(11,0); |
mandres7 | 0:62bc56579cdb | 154 | lcd.printf("%d",j); |
mandres7 | 0:62bc56579cdb | 155 | |
mandres7 | 0:62bc56579cdb | 156 | while(c==1){ |
mandres7 | 0:62bc56579cdb | 157 | |
mandres7 | 0:62bc56579cdb | 158 | //Work space |
mandres7 | 0:62bc56579cdb | 159 | |
mandres7 | 0:62bc56579cdb | 160 | if(up.falling()||down.falling()){ |
mandres7 | 0:62bc56579cdb | 161 | timer1.start(); |
mandres7 | 0:62bc56579cdb | 162 | |
mandres7 | 0:62bc56579cdb | 163 | while(up==0||down==0){ |
mandres7 | 0:62bc56579cdb | 164 | if(up==1&&down==1){ |
mandres7 | 0:62bc56579cdb | 165 | timer1.stop(); |
mandres7 | 0:62bc56579cdb | 166 | timer1.reset(); |
mandres7 | 0:62bc56579cdb | 167 | } |
mandres7 | 0:62bc56579cdb | 168 | if (timer1.read()>0&&timer1.read()<=5&&up==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 169 | ++j; |
mandres7 | 0:62bc56579cdb | 170 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 171 | } |
mandres7 | 0:62bc56579cdb | 172 | if (timer1.read()>0&&timer1.read()<=5&&down==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 173 | --j; |
mandres7 | 0:62bc56579cdb | 174 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 175 | } |
mandres7 | 0:62bc56579cdb | 176 | |
mandres7 | 0:62bc56579cdb | 177 | if (timer1.read()>5&&timer1.read()<=10&&up==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 178 | j+=5; |
mandres7 | 0:62bc56579cdb | 179 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 180 | } |
mandres7 | 0:62bc56579cdb | 181 | |
mandres7 | 0:62bc56579cdb | 182 | if (timer1.read()>5&&timer1.read()<=10&&down==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 183 | j-=5; |
mandres7 | 0:62bc56579cdb | 184 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 185 | } |
mandres7 | 0:62bc56579cdb | 186 | |
mandres7 | 0:62bc56579cdb | 187 | |
mandres7 | 0:62bc56579cdb | 188 | if (timer1.read()>10&&timer1.read()<=100&&up==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 189 | j+=10; |
mandres7 | 0:62bc56579cdb | 190 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 191 | } |
mandres7 | 0:62bc56579cdb | 192 | |
mandres7 | 0:62bc56579cdb | 193 | if (timer1.read()>10&&timer1.read()<=100&&down==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 194 | j-=10; |
mandres7 | 0:62bc56579cdb | 195 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 196 | } |
mandres7 | 0:62bc56579cdb | 197 | if (timer1.read()>10&&timer1.read()<=1000&&up==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 198 | j+=100; |
mandres7 | 0:62bc56579cdb | 199 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 200 | } |
mandres7 | 0:62bc56579cdb | 201 | |
mandres7 | 0:62bc56579cdb | 202 | if (timer1.read()>10&&timer1.read()<=1000&&down==0&&j>=0&&j<=9999) { |
mandres7 | 0:62bc56579cdb | 203 | j-=100; |
mandres7 | 0:62bc56579cdb | 204 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 205 | } |
mandres7 | 0:62bc56579cdb | 206 | |
mandres7 | 0:62bc56579cdb | 207 | if(j<0){ |
mandres7 | 0:62bc56579cdb | 208 | j=0; |
mandres7 | 0:62bc56579cdb | 209 | } |
mandres7 | 0:62bc56579cdb | 210 | |
mandres7 | 0:62bc56579cdb | 211 | if(j>9999){ |
mandres7 | 0:62bc56579cdb | 212 | j=9999; |
mandres7 | 0:62bc56579cdb | 213 | } |
mandres7 | 0:62bc56579cdb | 214 | |
mandres7 | 0:62bc56579cdb | 215 | //NEW !! (not zeros in -- process) |
mandres7 | 0:62bc56579cdb | 216 | if(j<10){ |
mandres7 | 0:62bc56579cdb | 217 | lcd.locate(12,0); |
mandres7 | 0:62bc56579cdb | 218 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 219 | } |
mandres7 | 0:62bc56579cdb | 220 | |
mandres7 | 0:62bc56579cdb | 221 | if(j<100){ |
mandres7 | 0:62bc56579cdb | 222 | lcd.locate(13,0); |
mandres7 | 0:62bc56579cdb | 223 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 224 | } |
mandres7 | 0:62bc56579cdb | 225 | |
mandres7 | 0:62bc56579cdb | 226 | if(j<1000){ |
mandres7 | 0:62bc56579cdb | 227 | lcd.locate(14,0); |
mandres7 | 0:62bc56579cdb | 228 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 229 | } |
mandres7 | 0:62bc56579cdb | 230 | // |
mandres7 | 0:62bc56579cdb | 231 | |
mandres7 | 0:62bc56579cdb | 232 | j=j; |
mandres7 | 0:62bc56579cdb | 233 | //lcd.locate(11,0); |
mandres7 | 0:62bc56579cdb | 234 | //lcd.printf(" "); |
mandres7 | 0:62bc56579cdb | 235 | lcd.locate(11,0); //before lcd.locate(12,0); |
mandres7 | 0:62bc56579cdb | 236 | lcd.printf("%d", j); |
mandres7 | 0:62bc56579cdb | 237 | wait(0.2); |
mandres7 | 0:62bc56579cdb | 238 | |
mandres7 | 0:62bc56579cdb | 239 | } |
mandres7 | 0:62bc56579cdb | 240 | } |
mandres7 | 0:62bc56579cdb | 241 | |
mandres7 | 0:62bc56579cdb | 242 | //End work space |
mandres7 | 0:62bc56579cdb | 243 | |
mandres7 | 0:62bc56579cdb | 244 | if(next.falling()){ |
mandres7 | 0:62bc56579cdb | 245 | c++; |
mandres7 | 0:62bc56579cdb | 246 | } |
mandres7 | 0:62bc56579cdb | 247 | } |
mandres7 | 0:62bc56579cdb | 248 | } |
mandres7 | 0:62bc56579cdb | 249 | |
mandres7 | 0:62bc56579cdb | 250 | //Salto a Kp |
mandres7 | 0:62bc56579cdb | 251 | if (c==2){ |
mandres7 | 0:62bc56579cdb | 252 | |
mandres7 | 0:62bc56579cdb | 253 | lcd.locate(3,1); |
mandres7 | 0:62bc56579cdb | 254 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 255 | lcd.writeCommand(C1); |
mandres7 | 0:62bc56579cdb | 256 | lcd.locate(3,1); |
mandres7 | 0:62bc56579cdb | 257 | lcd.printf("%d",k); |
mandres7 | 0:62bc56579cdb | 258 | |
mandres7 | 0:62bc56579cdb | 259 | while(c==2){ |
mandres7 | 0:62bc56579cdb | 260 | |
mandres7 | 0:62bc56579cdb | 261 | //Work space |
mandres7 | 0:62bc56579cdb | 262 | |
mandres7 | 0:62bc56579cdb | 263 | if(up.falling()||down.falling()){ |
mandres7 | 0:62bc56579cdb | 264 | timer1.start(); |
mandres7 | 0:62bc56579cdb | 265 | |
mandres7 | 0:62bc56579cdb | 266 | while(up==0||down==0){ |
mandres7 | 0:62bc56579cdb | 267 | if(up==1&&down==1){ |
mandres7 | 0:62bc56579cdb | 268 | timer1.stop(); |
mandres7 | 0:62bc56579cdb | 269 | timer1.reset(); |
mandres7 | 0:62bc56579cdb | 270 | } |
mandres7 | 0:62bc56579cdb | 271 | if (timer1.read()>0&&timer1.read()<=5&&up==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 272 | ++k; |
mandres7 | 0:62bc56579cdb | 273 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 274 | } |
mandres7 | 0:62bc56579cdb | 275 | if (timer1.read()>0&&timer1.read()<=5&&down==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 276 | --k; |
mandres7 | 0:62bc56579cdb | 277 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 278 | } |
mandres7 | 0:62bc56579cdb | 279 | |
mandres7 | 0:62bc56579cdb | 280 | if (timer1.read()>5&&timer1.read()<=10&&up==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 281 | k+=5; |
mandres7 | 0:62bc56579cdb | 282 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 283 | } |
mandres7 | 0:62bc56579cdb | 284 | |
mandres7 | 0:62bc56579cdb | 285 | if (timer1.read()>5&&timer1.read()<=10&&down==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 286 | k-=5; |
mandres7 | 0:62bc56579cdb | 287 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 288 | } |
mandres7 | 0:62bc56579cdb | 289 | |
mandres7 | 0:62bc56579cdb | 290 | |
mandres7 | 0:62bc56579cdb | 291 | if (timer1.read()>10&&timer1.read()<=100&&up==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 292 | k+=10; |
mandres7 | 0:62bc56579cdb | 293 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 294 | } |
mandres7 | 0:62bc56579cdb | 295 | |
mandres7 | 0:62bc56579cdb | 296 | if (timer1.read()>10&&timer1.read()<=100&&down==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 297 | k-=10; |
mandres7 | 0:62bc56579cdb | 298 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 299 | } |
mandres7 | 0:62bc56579cdb | 300 | if (timer1.read()>10&&timer1.read()<=1000&&up==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 301 | k+=100; |
mandres7 | 0:62bc56579cdb | 302 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 303 | } |
mandres7 | 0:62bc56579cdb | 304 | |
mandres7 | 0:62bc56579cdb | 305 | if (timer1.read()>10&&timer1.read()<=1000&&down==0&&k>=0&&k<=9999) { |
mandres7 | 0:62bc56579cdb | 306 | k-=100; |
mandres7 | 0:62bc56579cdb | 307 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 308 | } |
mandres7 | 0:62bc56579cdb | 309 | |
mandres7 | 0:62bc56579cdb | 310 | if(k<0){ |
mandres7 | 0:62bc56579cdb | 311 | k=0; |
mandres7 | 0:62bc56579cdb | 312 | } |
mandres7 | 0:62bc56579cdb | 313 | |
mandres7 | 0:62bc56579cdb | 314 | if(k>9999){ |
mandres7 | 0:62bc56579cdb | 315 | k=9999; |
mandres7 | 0:62bc56579cdb | 316 | } |
mandres7 | 0:62bc56579cdb | 317 | |
mandres7 | 0:62bc56579cdb | 318 | //NEW !! (not zeros in -- process) |
mandres7 | 0:62bc56579cdb | 319 | if(k<10){ |
mandres7 | 0:62bc56579cdb | 320 | lcd.locate(4,1); |
mandres7 | 0:62bc56579cdb | 321 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 322 | } |
mandres7 | 0:62bc56579cdb | 323 | |
mandres7 | 0:62bc56579cdb | 324 | if(k<100){ |
mandres7 | 0:62bc56579cdb | 325 | lcd.locate(5,1); |
mandres7 | 0:62bc56579cdb | 326 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 327 | } |
mandres7 | 0:62bc56579cdb | 328 | |
mandres7 | 0:62bc56579cdb | 329 | if(k<1000){ |
mandres7 | 0:62bc56579cdb | 330 | lcd.locate(6,1); |
mandres7 | 0:62bc56579cdb | 331 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 332 | } |
mandres7 | 0:62bc56579cdb | 333 | // |
mandres7 | 0:62bc56579cdb | 334 | |
mandres7 | 0:62bc56579cdb | 335 | k=k; |
mandres7 | 0:62bc56579cdb | 336 | //lcd.locate(3,1); |
mandres7 | 0:62bc56579cdb | 337 | //lcd.printf(" "); |
mandres7 | 0:62bc56579cdb | 338 | lcd.locate(3,1); //before lcd.locate(4,1); |
mandres7 | 0:62bc56579cdb | 339 | lcd.printf("%d", k); |
mandres7 | 0:62bc56579cdb | 340 | wait(0.2); |
mandres7 | 0:62bc56579cdb | 341 | |
mandres7 | 0:62bc56579cdb | 342 | } |
mandres7 | 0:62bc56579cdb | 343 | } |
mandres7 | 0:62bc56579cdb | 344 | |
mandres7 | 0:62bc56579cdb | 345 | //End work space |
mandres7 | 0:62bc56579cdb | 346 | |
mandres7 | 0:62bc56579cdb | 347 | if(next.falling()){ |
mandres7 | 0:62bc56579cdb | 348 | c++; |
mandres7 | 0:62bc56579cdb | 349 | } |
mandres7 | 0:62bc56579cdb | 350 | } |
mandres7 | 0:62bc56579cdb | 351 | } |
mandres7 | 0:62bc56579cdb | 352 | |
mandres7 | 0:62bc56579cdb | 353 | //Salto a Kp |
mandres7 | 0:62bc56579cdb | 354 | if (c==3){ |
mandres7 | 0:62bc56579cdb | 355 | |
mandres7 | 0:62bc56579cdb | 356 | lcd.locate(11,1); |
mandres7 | 0:62bc56579cdb | 357 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 358 | lcd.writeCommand(C1); |
mandres7 | 0:62bc56579cdb | 359 | lcd.locate(11,1); |
mandres7 | 0:62bc56579cdb | 360 | lcd.printf("%d",l); |
mandres7 | 0:62bc56579cdb | 361 | |
mandres7 | 0:62bc56579cdb | 362 | while(c==3){ |
mandres7 | 0:62bc56579cdb | 363 | |
mandres7 | 0:62bc56579cdb | 364 | //Work space |
mandres7 | 0:62bc56579cdb | 365 | |
mandres7 | 0:62bc56579cdb | 366 | if(up.falling()||down.falling()){ |
mandres7 | 0:62bc56579cdb | 367 | timer1.start(); |
mandres7 | 0:62bc56579cdb | 368 | |
mandres7 | 0:62bc56579cdb | 369 | while(up==0||down==0){ |
mandres7 | 0:62bc56579cdb | 370 | if(up==1&&down==1){ |
mandres7 | 0:62bc56579cdb | 371 | timer1.stop(); |
mandres7 | 0:62bc56579cdb | 372 | timer1.reset(); |
mandres7 | 0:62bc56579cdb | 373 | } |
mandres7 | 0:62bc56579cdb | 374 | if (timer1.read()>0&&timer1.read()<=5&&up==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 375 | ++l; |
mandres7 | 0:62bc56579cdb | 376 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 377 | } |
mandres7 | 0:62bc56579cdb | 378 | if (timer1.read()>0&&timer1.read()<=5&&down==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 379 | --l; |
mandres7 | 0:62bc56579cdb | 380 | wait(0.1); |
mandres7 | 0:62bc56579cdb | 381 | } |
mandres7 | 0:62bc56579cdb | 382 | |
mandres7 | 0:62bc56579cdb | 383 | if (timer1.read()>5&&timer1.read()<=10&&up==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 384 | l+=5; |
mandres7 | 0:62bc56579cdb | 385 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 386 | } |
mandres7 | 0:62bc56579cdb | 387 | |
mandres7 | 0:62bc56579cdb | 388 | if (timer1.read()>5&&timer1.read()<=10&&down==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 389 | l-=5; |
mandres7 | 0:62bc56579cdb | 390 | wait(0.1/5); |
mandres7 | 0:62bc56579cdb | 391 | } |
mandres7 | 0:62bc56579cdb | 392 | |
mandres7 | 0:62bc56579cdb | 393 | |
mandres7 | 0:62bc56579cdb | 394 | if (timer1.read()>10&&timer1.read()<=100&&up==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 395 | l+=10; |
mandres7 | 0:62bc56579cdb | 396 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 397 | } |
mandres7 | 0:62bc56579cdb | 398 | |
mandres7 | 0:62bc56579cdb | 399 | if (timer1.read()>10&&timer1.read()<=100&&down==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 400 | l-=10; |
mandres7 | 0:62bc56579cdb | 401 | wait(0.03); |
mandres7 | 0:62bc56579cdb | 402 | } |
mandres7 | 0:62bc56579cdb | 403 | if (timer1.read()>10&&timer1.read()<=1000&&up==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 404 | l+=100; |
mandres7 | 0:62bc56579cdb | 405 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 406 | } |
mandres7 | 0:62bc56579cdb | 407 | |
mandres7 | 0:62bc56579cdb | 408 | if (timer1.read()>10&&timer1.read()<=1000&&down==0&&l>=0&&l<=9999) { |
mandres7 | 0:62bc56579cdb | 409 | l-=100; |
mandres7 | 0:62bc56579cdb | 410 | wait(0.003); |
mandres7 | 0:62bc56579cdb | 411 | } |
mandres7 | 0:62bc56579cdb | 412 | |
mandres7 | 0:62bc56579cdb | 413 | if(l<0){ |
mandres7 | 0:62bc56579cdb | 414 | l=0; |
mandres7 | 0:62bc56579cdb | 415 | } |
mandres7 | 0:62bc56579cdb | 416 | |
mandres7 | 0:62bc56579cdb | 417 | if(l>9999){ |
mandres7 | 0:62bc56579cdb | 418 | l=9999; |
mandres7 | 0:62bc56579cdb | 419 | } |
mandres7 | 0:62bc56579cdb | 420 | |
mandres7 | 0:62bc56579cdb | 421 | //NEW !! (not zeros in -- process) |
mandres7 | 0:62bc56579cdb | 422 | if(l<10){ |
mandres7 | 0:62bc56579cdb | 423 | lcd.locate(12,1); |
mandres7 | 0:62bc56579cdb | 424 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 425 | } |
mandres7 | 0:62bc56579cdb | 426 | |
mandres7 | 0:62bc56579cdb | 427 | if(l<100){ |
mandres7 | 0:62bc56579cdb | 428 | lcd.locate(13,1); |
mandres7 | 0:62bc56579cdb | 429 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 430 | } |
mandres7 | 0:62bc56579cdb | 431 | |
mandres7 | 0:62bc56579cdb | 432 | if(l<1000){ |
mandres7 | 0:62bc56579cdb | 433 | lcd.locate(14,1); |
mandres7 | 0:62bc56579cdb | 434 | lcd.putc(0xFE); |
mandres7 | 0:62bc56579cdb | 435 | } |
mandres7 | 0:62bc56579cdb | 436 | // |
mandres7 | 0:62bc56579cdb | 437 | |
mandres7 | 0:62bc56579cdb | 438 | l=l; |
mandres7 | 0:62bc56579cdb | 439 | //lcd.locate(11,1); |
mandres7 | 0:62bc56579cdb | 440 | //lcd.printf(" "); |
mandres7 | 0:62bc56579cdb | 441 | lcd.locate(11,1); //before lcd.locate(12,1); |
mandres7 | 0:62bc56579cdb | 442 | lcd.printf("%d", l); |
mandres7 | 0:62bc56579cdb | 443 | wait(0.2); |
mandres7 | 0:62bc56579cdb | 444 | |
mandres7 | 0:62bc56579cdb | 445 | } |
mandres7 | 0:62bc56579cdb | 446 | } |
mandres7 | 0:62bc56579cdb | 447 | |
mandres7 | 0:62bc56579cdb | 448 | //End work space |
mandres7 | 0:62bc56579cdb | 449 | |
mandres7 | 0:62bc56579cdb | 450 | if(next.falling()){ |
mandres7 | 0:62bc56579cdb | 451 | c++; |
mandres7 | 0:62bc56579cdb | 452 | } |
mandres7 | 0:62bc56579cdb | 453 | } |
mandres7 | 0:62bc56579cdb | 454 | } |
mandres7 | 0:62bc56579cdb | 455 | |
mandres7 | 0:62bc56579cdb | 456 | // |
mandres7 | 0:62bc56579cdb | 457 | if(c==4 || c>4){ |
mandres7 | 0:62bc56579cdb | 458 | c=0; |
mandres7 | 0:62bc56579cdb | 459 | } |
mandres7 | 0:62bc56579cdb | 460 | |
mandres7 | 0:62bc56579cdb | 461 | } |
mandres7 | 0:62bc56579cdb | 462 | } |