Václav Lízner
/
2048
school project
main.cpp@7:29f6c0e0b427, 2016-01-13 (annotated)
- Committer:
- xlizne01
- Date:
- Wed Jan 13 22:26:31 2016 +0000
- Revision:
- 7:29f6c0e0b427
- Parent:
- 6:5711a5b57d17
- Child:
- 8:5f485026374d
komplet funkcni krome kontrolz pokud se pohne smerem, kterym se nic nezmeni
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xlizne01 | 0:ae588eb31707 | 1 | #include "mbed.h" |
xlizne01 | 1:b23831b703fe | 2 | #include "MMA8451Q.h" |
xlizne01 | 1:b23831b703fe | 3 | |
xlizne01 | 1:b23831b703fe | 4 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
xlizne01 | 5:d6738e1238d8 | 5 | #define MOVE_ANGLE 35 // > degrees for move |
xlizne01 | 2:3278e4fd8fc2 | 6 | |
xlizne01 | 7:29f6c0e0b427 | 7 | //Ticker tick; |
xlizne01 | 7:29f6c0e0b427 | 8 | |
xlizne01 | 2:3278e4fd8fc2 | 9 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
xlizne01 | 2:3278e4fd8fc2 | 10 | |
xlizne01 | 2:3278e4fd8fc2 | 11 | void accelerometer(void); |
xlizne01 | 3:94bfc4de4ab1 | 12 | void zobrazeni(void); |
xlizne01 | 3:94bfc4de4ab1 | 13 | void barva(int,int); |
xlizne01 | 4:4930b1cb20bd | 14 | void pohyb(void); |
xlizne01 | 6:5711a5b57d17 | 15 | void proved(int); |
xlizne01 | 7:29f6c0e0b427 | 16 | void pridej(void); |
xlizne01 | 2:3278e4fd8fc2 | 17 | |
xlizne01 | 6:5711a5b57d17 | 18 | int i,j,k; |
xlizne01 | 6:5711a5b57d17 | 19 | int p=1; |
xlizne01 | 2:3278e4fd8fc2 | 20 | int RED, GREEN, BLUE; |
xlizne01 | 2:3278e4fd8fc2 | 21 | int RledA, RledB, GledA, GledB, BledA, BledB; |
xlizne01 | 4:4930b1cb20bd | 22 | float xAngle, yAngle; |
xlizne01 | 3:94bfc4de4ab1 | 23 | |
xlizne01 | 2:3278e4fd8fc2 | 24 | char acc_dir; |
xlizne01 | 3:94bfc4de4ab1 | 25 | |
xlizne01 | 7:29f6c0e0b427 | 26 | int pole[4][4]={{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}}; |
xlizne01 | 7:29f6c0e0b427 | 27 | int pole2[4][4]; |
xlizne01 | 1:b23831b703fe | 28 | |
xlizne01 | 0:ae588eb31707 | 29 | DigitalOut prvni(PTE5); |
xlizne01 | 0:ae588eb31707 | 30 | DigitalOut druhy(PTE4); |
xlizne01 | 0:ae588eb31707 | 31 | DigitalOut treti(PTE3); |
xlizne01 | 0:ae588eb31707 | 32 | DigitalOut ctvrty(PTE2); |
xlizne01 | 0:ae588eb31707 | 33 | DigitalOut paty(PTB11); |
xlizne01 | 0:ae588eb31707 | 34 | DigitalOut sesty(PTB10); |
xlizne01 | 0:ae588eb31707 | 35 | DigitalOut sedmy(PTB9); |
xlizne01 | 0:ae588eb31707 | 36 | DigitalOut osmy(PTB8); |
xlizne01 | 0:ae588eb31707 | 37 | |
xlizne01 | 0:ae588eb31707 | 38 | DigitalOut Rled1(PTC9); |
xlizne01 | 0:ae588eb31707 | 39 | DigitalOut Rled2(PTC8); |
xlizne01 | 0:ae588eb31707 | 40 | DigitalOut Rled3(PTA5); |
xlizne01 | 0:ae588eb31707 | 41 | DigitalOut Rled4(PTA4); |
xlizne01 | 0:ae588eb31707 | 42 | DigitalOut Rled5(PTA12); |
xlizne01 | 0:ae588eb31707 | 43 | DigitalOut Rled6(PTD4); |
xlizne01 | 0:ae588eb31707 | 44 | DigitalOut Rled7(PTA1); |
xlizne01 | 0:ae588eb31707 | 45 | DigitalOut Rled8(PTA2); |
xlizne01 | 0:ae588eb31707 | 46 | |
xlizne01 | 0:ae588eb31707 | 47 | DigitalOut Gled1(PTA13); |
xlizne01 | 0:ae588eb31707 | 48 | DigitalOut Gled2(PTD5); |
xlizne01 | 0:ae588eb31707 | 49 | DigitalOut Gled3(PTD0); |
xlizne01 | 0:ae588eb31707 | 50 | DigitalOut Gled4(PTD2); |
xlizne01 | 0:ae588eb31707 | 51 | DigitalOut Gled5(PTD3); |
xlizne01 | 0:ae588eb31707 | 52 | DigitalOut Gled6(PTD1); |
xlizne01 | 0:ae588eb31707 | 53 | DigitalOut Gled7(PTE31); |
xlizne01 | 0:ae588eb31707 | 54 | DigitalOut Gled8(PTB0); |
xlizne01 | 0:ae588eb31707 | 55 | |
xlizne01 | 0:ae588eb31707 | 56 | DigitalOut Bled1(PTC1); |
xlizne01 | 0:ae588eb31707 | 57 | DigitalOut Bled2(PTE29); |
xlizne01 | 0:ae588eb31707 | 58 | DigitalOut Bled3(PTC2); |
xlizne01 | 0:ae588eb31707 | 59 | DigitalOut Bled4(PTB3); |
xlizne01 | 0:ae588eb31707 | 60 | DigitalOut Bled5(PTB2); |
xlizne01 | 0:ae588eb31707 | 61 | DigitalOut Bled6(PTE21); |
xlizne01 | 0:ae588eb31707 | 62 | DigitalOut Bled7(PTE20); |
xlizne01 | 0:ae588eb31707 | 63 | DigitalOut Bled8(PTB1); |
xlizne01 | 0:ae588eb31707 | 64 | |
xlizne01 | 0:ae588eb31707 | 65 | |
xlizne01 | 0:ae588eb31707 | 66 | int main() |
xlizne01 | 0:ae588eb31707 | 67 | { |
xlizne01 | 7:29f6c0e0b427 | 68 | //tick.attach(&zobrazeni, 0.01); // setup ticker to call zobrazeni |
xlizne01 | 7:29f6c0e0b427 | 69 | pridej(); |
xlizne01 | 7:29f6c0e0b427 | 70 | pridej(); |
xlizne01 | 7:29f6c0e0b427 | 71 | |
xlizne01 | 3:94bfc4de4ab1 | 72 | while(1) |
xlizne01 | 3:94bfc4de4ab1 | 73 | { |
xlizne01 | 4:4930b1cb20bd | 74 | accelerometer(); |
xlizne01 | 7:29f6c0e0b427 | 75 | pohyb(); |
xlizne01 | 4:4930b1cb20bd | 76 | zobrazeni(); |
xlizne01 | 0:ae588eb31707 | 77 | } |
xlizne01 | 3:94bfc4de4ab1 | 78 | } |
xlizne01 | 7:29f6c0e0b427 | 79 | |
xlizne01 | 7:29f6c0e0b427 | 80 | void pridej() |
xlizne01 | 7:29f6c0e0b427 | 81 | { |
xlizne01 | 7:29f6c0e0b427 | 82 | int f; |
xlizne01 | 7:29f6c0e0b427 | 83 | int g=1; |
xlizne01 | 7:29f6c0e0b427 | 84 | int suma=0; |
xlizne01 | 7:29f6c0e0b427 | 85 | |
xlizne01 | 7:29f6c0e0b427 | 86 | for(int a=0;a<4;a++) |
xlizne01 | 7:29f6c0e0b427 | 87 | { |
xlizne01 | 7:29f6c0e0b427 | 88 | for(int b=0;b<4;b++) |
xlizne01 | 7:29f6c0e0b427 | 89 | { |
xlizne01 | 7:29f6c0e0b427 | 90 | if(pole[a][b]==0) |
xlizne01 | 7:29f6c0e0b427 | 91 | suma=1; |
xlizne01 | 7:29f6c0e0b427 | 92 | } |
xlizne01 | 7:29f6c0e0b427 | 93 | } |
xlizne01 | 7:29f6c0e0b427 | 94 | if(suma==1) // pridani cisla |
xlizne01 | 7:29f6c0e0b427 | 95 | { |
xlizne01 | 7:29f6c0e0b427 | 96 | accelerometer(); |
xlizne01 | 7:29f6c0e0b427 | 97 | xAngle=(xAngle*yAngle*100); |
xlizne01 | 7:29f6c0e0b427 | 98 | f=int(xAngle)%16; |
xlizne01 | 7:29f6c0e0b427 | 99 | |
xlizne01 | 7:29f6c0e0b427 | 100 | while(g==1) |
xlizne01 | 7:29f6c0e0b427 | 101 | { |
xlizne01 | 7:29f6c0e0b427 | 102 | f++; |
xlizne01 | 7:29f6c0e0b427 | 103 | if(f==16) |
xlizne01 | 7:29f6c0e0b427 | 104 | { |
xlizne01 | 7:29f6c0e0b427 | 105 | f=0; |
xlizne01 | 7:29f6c0e0b427 | 106 | } |
xlizne01 | 7:29f6c0e0b427 | 107 | |
xlizne01 | 7:29f6c0e0b427 | 108 | if(pole[f/4][f%4]==0) |
xlizne01 | 7:29f6c0e0b427 | 109 | { |
xlizne01 | 7:29f6c0e0b427 | 110 | pole[f/4][f%4]=2; |
xlizne01 | 7:29f6c0e0b427 | 111 | g=0; |
xlizne01 | 7:29f6c0e0b427 | 112 | } |
xlizne01 | 7:29f6c0e0b427 | 113 | } |
xlizne01 | 7:29f6c0e0b427 | 114 | } |
xlizne01 | 7:29f6c0e0b427 | 115 | } |
xlizne01 | 7:29f6c0e0b427 | 116 | |
xlizne01 | 7:29f6c0e0b427 | 117 | |
xlizne01 | 7:29f6c0e0b427 | 118 | |
xlizne01 | 4:4930b1cb20bd | 119 | |
xlizne01 | 4:4930b1cb20bd | 120 | void pohyb() |
xlizne01 | 4:4930b1cb20bd | 121 | { |
xlizne01 | 4:4930b1cb20bd | 122 | switch(acc_dir) |
xlizne01 | 4:4930b1cb20bd | 123 | { |
xlizne01 | 7:29f6c0e0b427 | 124 | case 'D': //pohyb smerem dolu |
xlizne01 | 7:29f6c0e0b427 | 125 | if(p==0) |
xlizne01 | 7:29f6c0e0b427 | 126 | { |
xlizne01 | 7:29f6c0e0b427 | 127 | proved(1); |
xlizne01 | 7:29f6c0e0b427 | 128 | p=1; |
xlizne01 | 7:29f6c0e0b427 | 129 | } |
xlizne01 | 7:29f6c0e0b427 | 130 | break; |
xlizne01 | 7:29f6c0e0b427 | 131 | |
xlizne01 | 7:29f6c0e0b427 | 132 | case 'R': // pohyb smerem vpravo |
xlizne01 | 7:29f6c0e0b427 | 133 | if(p==0) |
xlizne01 | 7:29f6c0e0b427 | 134 | { |
xlizne01 | 7:29f6c0e0b427 | 135 | proved(2); |
xlizne01 | 7:29f6c0e0b427 | 136 | p=1; |
xlizne01 | 7:29f6c0e0b427 | 137 | } |
xlizne01 | 7:29f6c0e0b427 | 138 | break; |
xlizne01 | 7:29f6c0e0b427 | 139 | |
xlizne01 | 7:29f6c0e0b427 | 140 | case 'U': // pohyb smerem nahoru |
xlizne01 | 7:29f6c0e0b427 | 141 | if(p==0) |
xlizne01 | 7:29f6c0e0b427 | 142 | { |
xlizne01 | 7:29f6c0e0b427 | 143 | proved(3); |
xlizne01 | 7:29f6c0e0b427 | 144 | p=1; |
xlizne01 | 7:29f6c0e0b427 | 145 | } |
xlizne01 | 7:29f6c0e0b427 | 146 | break; |
xlizne01 | 7:29f6c0e0b427 | 147 | |
xlizne01 | 7:29f6c0e0b427 | 148 | case 'L': // pohyb smerem vlevo |
xlizne01 | 7:29f6c0e0b427 | 149 | if(p==0) |
xlizne01 | 7:29f6c0e0b427 | 150 | { |
xlizne01 | 7:29f6c0e0b427 | 151 | proved(4); |
xlizne01 | 7:29f6c0e0b427 | 152 | p=1; |
xlizne01 | 7:29f6c0e0b427 | 153 | } |
xlizne01 | 7:29f6c0e0b427 | 154 | break; |
xlizne01 | 7:29f6c0e0b427 | 155 | |
xlizne01 | 7:29f6c0e0b427 | 156 | case '0': // detekovana nulova pozice |
xlizne01 | 7:29f6c0e0b427 | 157 | p=0; |
xlizne01 | 7:29f6c0e0b427 | 158 | break; |
xlizne01 | 7:29f6c0e0b427 | 159 | |
xlizne01 | 7:29f6c0e0b427 | 160 | default: |
xlizne01 | 7:29f6c0e0b427 | 161 | break; |
xlizne01 | 4:4930b1cb20bd | 162 | } |
xlizne01 | 4:4930b1cb20bd | 163 | } |
xlizne01 | 4:4930b1cb20bd | 164 | |
xlizne01 | 6:5711a5b57d17 | 165 | void proved(int x) |
xlizne01 | 6:5711a5b57d17 | 166 | { |
xlizne01 | 6:5711a5b57d17 | 167 | int a,b,c,d,n; |
xlizne01 | 6:5711a5b57d17 | 168 | |
xlizne01 | 6:5711a5b57d17 | 169 | for(n=0;n<4;n++) |
xlizne01 | 6:5711a5b57d17 | 170 | { |
xlizne01 | 7:29f6c0e0b427 | 171 | for(int k=0;k<4;k++) |
xlizne01 | 7:29f6c0e0b427 | 172 | { |
xlizne01 | 7:29f6c0e0b427 | 173 | for(int l=0;l<4;l++) |
xlizne01 | 7:29f6c0e0b427 | 174 | { |
xlizne01 | 7:29f6c0e0b427 | 175 | pole2[k][l]=pole[k][l]; |
xlizne01 | 7:29f6c0e0b427 | 176 | } |
xlizne01 | 7:29f6c0e0b427 | 177 | } |
xlizne01 | 6:5711a5b57d17 | 178 | |
xlizne01 | 6:5711a5b57d17 | 179 | if(x==1) // dolu |
xlizne01 | 6:5711a5b57d17 | 180 | { |
xlizne01 | 6:5711a5b57d17 | 181 | a=pole[n][0]; |
xlizne01 | 6:5711a5b57d17 | 182 | b=pole[n][1]; |
xlizne01 | 6:5711a5b57d17 | 183 | c=pole[n][2]; |
xlizne01 | 6:5711a5b57d17 | 184 | d=pole[n][3]; |
xlizne01 | 6:5711a5b57d17 | 185 | } |
xlizne01 | 6:5711a5b57d17 | 186 | |
xlizne01 | 6:5711a5b57d17 | 187 | if(x==2) // vpravo |
xlizne01 | 6:5711a5b57d17 | 188 | { |
xlizne01 | 6:5711a5b57d17 | 189 | a=pole[3][n]; |
xlizne01 | 6:5711a5b57d17 | 190 | b=pole[2][n]; |
xlizne01 | 6:5711a5b57d17 | 191 | c=pole[1][n]; |
xlizne01 | 6:5711a5b57d17 | 192 | d=pole[0][n]; |
xlizne01 | 6:5711a5b57d17 | 193 | } |
xlizne01 | 6:5711a5b57d17 | 194 | |
xlizne01 | 6:5711a5b57d17 | 195 | if(x==3) // nahoru |
xlizne01 | 6:5711a5b57d17 | 196 | { |
xlizne01 | 6:5711a5b57d17 | 197 | a=pole[n][3]; |
xlizne01 | 6:5711a5b57d17 | 198 | b=pole[n][2]; |
xlizne01 | 6:5711a5b57d17 | 199 | c=pole[n][1]; |
xlizne01 | 6:5711a5b57d17 | 200 | d=pole[n][0]; |
xlizne01 | 6:5711a5b57d17 | 201 | } |
xlizne01 | 6:5711a5b57d17 | 202 | |
xlizne01 | 6:5711a5b57d17 | 203 | if(x==4) // vlevo |
xlizne01 | 6:5711a5b57d17 | 204 | { |
xlizne01 | 6:5711a5b57d17 | 205 | a=pole[0][n]; |
xlizne01 | 6:5711a5b57d17 | 206 | b=pole[1][n]; |
xlizne01 | 6:5711a5b57d17 | 207 | c=pole[2][n]; |
xlizne01 | 6:5711a5b57d17 | 208 | d=pole[3][n]; |
xlizne01 | 6:5711a5b57d17 | 209 | } |
xlizne01 | 6:5711a5b57d17 | 210 | |
xlizne01 | 6:5711a5b57d17 | 211 | //sesypani |
xlizne01 | 6:5711a5b57d17 | 212 | if(a==0) |
xlizne01 | 6:5711a5b57d17 | 213 | {a=b; b=c; c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 214 | if(a==0) |
xlizne01 | 6:5711a5b57d17 | 215 | {a=b; b=c; c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 216 | if(a==0) |
xlizne01 | 6:5711a5b57d17 | 217 | {a=b; b=c; c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 218 | if(b==0) |
xlizne01 | 6:5711a5b57d17 | 219 | {b=c; c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 220 | if(b==0) |
xlizne01 | 6:5711a5b57d17 | 221 | {b=c; c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 222 | if(c==0) |
xlizne01 | 6:5711a5b57d17 | 223 | {c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 224 | |
xlizne01 | 6:5711a5b57d17 | 225 | //spojeni |
xlizne01 | 6:5711a5b57d17 | 226 | if(a==b) |
xlizne01 | 6:5711a5b57d17 | 227 | {a=2*a; b=c; c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 228 | if(b==c) |
xlizne01 | 6:5711a5b57d17 | 229 | {b=2*b; c=d; d=0;} |
xlizne01 | 6:5711a5b57d17 | 230 | if(c==d) |
xlizne01 | 6:5711a5b57d17 | 231 | {c=2*c; d=0;} |
xlizne01 | 6:5711a5b57d17 | 232 | |
xlizne01 | 6:5711a5b57d17 | 233 | if(x==1) // dolu |
xlizne01 | 6:5711a5b57d17 | 234 | { |
xlizne01 | 6:5711a5b57d17 | 235 | pole[n][0]=a; |
xlizne01 | 6:5711a5b57d17 | 236 | pole[n][1]=b; |
xlizne01 | 6:5711a5b57d17 | 237 | pole[n][2]=c; |
xlizne01 | 6:5711a5b57d17 | 238 | pole[n][3]=d; |
xlizne01 | 6:5711a5b57d17 | 239 | } |
xlizne01 | 6:5711a5b57d17 | 240 | if(x==2) // vpravo |
xlizne01 | 6:5711a5b57d17 | 241 | { |
xlizne01 | 6:5711a5b57d17 | 242 | pole[3][n]=a; |
xlizne01 | 6:5711a5b57d17 | 243 | pole[2][n]=b; |
xlizne01 | 6:5711a5b57d17 | 244 | pole[1][n]=c; |
xlizne01 | 6:5711a5b57d17 | 245 | pole[0][n]=d; |
xlizne01 | 6:5711a5b57d17 | 246 | } |
xlizne01 | 6:5711a5b57d17 | 247 | |
xlizne01 | 6:5711a5b57d17 | 248 | if(x==3) // nahoru |
xlizne01 | 6:5711a5b57d17 | 249 | { |
xlizne01 | 6:5711a5b57d17 | 250 | pole[n][3]=a; |
xlizne01 | 6:5711a5b57d17 | 251 | pole[n][2]=b; |
xlizne01 | 6:5711a5b57d17 | 252 | pole[n][1]=c; |
xlizne01 | 6:5711a5b57d17 | 253 | pole[n][0]=d; |
xlizne01 | 6:5711a5b57d17 | 254 | } |
xlizne01 | 6:5711a5b57d17 | 255 | |
xlizne01 | 6:5711a5b57d17 | 256 | if(x==4) // vlevo |
xlizne01 | 6:5711a5b57d17 | 257 | { |
xlizne01 | 6:5711a5b57d17 | 258 | pole[0][n]=a; |
xlizne01 | 6:5711a5b57d17 | 259 | pole[1][n]=b; |
xlizne01 | 6:5711a5b57d17 | 260 | pole[2][n]=c; |
xlizne01 | 6:5711a5b57d17 | 261 | pole[3][n]=d; |
xlizne01 | 7:29f6c0e0b427 | 262 | } |
xlizne01 | 7:29f6c0e0b427 | 263 | } |
xlizne01 | 7:29f6c0e0b427 | 264 | pridej(); |
xlizne01 | 6:5711a5b57d17 | 265 | } |
xlizne01 | 3:94bfc4de4ab1 | 266 | |
xlizne01 | 3:94bfc4de4ab1 | 267 | void zobrazeni() |
xlizne01 | 3:94bfc4de4ab1 | 268 | { |
xlizne01 | 3:94bfc4de4ab1 | 269 | for(k=0;k<4;k++) |
xlizne01 | 3:94bfc4de4ab1 | 270 | { |
xlizne01 | 3:94bfc4de4ab1 | 271 | prvni=0; |
xlizne01 | 3:94bfc4de4ab1 | 272 | druhy=0; |
xlizne01 | 3:94bfc4de4ab1 | 273 | treti=0; |
xlizne01 | 3:94bfc4de4ab1 | 274 | ctvrty=0; |
xlizne01 | 3:94bfc4de4ab1 | 275 | paty=0; |
xlizne01 | 3:94bfc4de4ab1 | 276 | sesty=0; |
xlizne01 | 3:94bfc4de4ab1 | 277 | sedmy=0; |
xlizne01 | 3:94bfc4de4ab1 | 278 | osmy=0; |
xlizne01 | 3:94bfc4de4ab1 | 279 | |
xlizne01 | 7:29f6c0e0b427 | 280 | wait(0.00005); //proti tzv. duchum |
xlizne01 | 7:29f6c0e0b427 | 281 | |
xlizne01 | 3:94bfc4de4ab1 | 282 | if(k==0) |
xlizne01 | 0:ae588eb31707 | 283 | { |
xlizne01 | 3:94bfc4de4ab1 | 284 | prvni=1; |
xlizne01 | 3:94bfc4de4ab1 | 285 | druhy=1; |
xlizne01 | 0:ae588eb31707 | 286 | } |
xlizne01 | 3:94bfc4de4ab1 | 287 | |
xlizne01 | 3:94bfc4de4ab1 | 288 | if(k==1) |
xlizne01 | 0:ae588eb31707 | 289 | { |
xlizne01 | 3:94bfc4de4ab1 | 290 | treti=1; |
xlizne01 | 3:94bfc4de4ab1 | 291 | ctvrty=1; |
xlizne01 | 0:ae588eb31707 | 292 | } |
xlizne01 | 3:94bfc4de4ab1 | 293 | |
xlizne01 | 3:94bfc4de4ab1 | 294 | if(k==2) |
xlizne01 | 0:ae588eb31707 | 295 | { |
xlizne01 | 3:94bfc4de4ab1 | 296 | paty=1; |
xlizne01 | 3:94bfc4de4ab1 | 297 | sesty=1; |
xlizne01 | 0:ae588eb31707 | 298 | } |
xlizne01 | 3:94bfc4de4ab1 | 299 | |
xlizne01 | 3:94bfc4de4ab1 | 300 | if(k==3) |
xlizne01 | 0:ae588eb31707 | 301 | { |
xlizne01 | 3:94bfc4de4ab1 | 302 | sedmy=1; |
xlizne01 | 3:94bfc4de4ab1 | 303 | osmy=1; |
xlizne01 | 0:ae588eb31707 | 304 | } |
xlizne01 | 0:ae588eb31707 | 305 | |
xlizne01 | 3:94bfc4de4ab1 | 306 | for(j=0;j<4;j++) |
xlizne01 | 3:94bfc4de4ab1 | 307 | { |
xlizne01 | 3:94bfc4de4ab1 | 308 | |
xlizne01 | 3:94bfc4de4ab1 | 309 | barva(j,k); |
xlizne01 | 3:94bfc4de4ab1 | 310 | |
xlizne01 | 7:29f6c0e0b427 | 311 | for(i=11;i>0;i--) |
xlizne01 | 3:94bfc4de4ab1 | 312 | { |
xlizne01 | 3:94bfc4de4ab1 | 313 | if(RED>0) |
xlizne01 | 3:94bfc4de4ab1 | 314 | { |
xlizne01 | 3:94bfc4de4ab1 | 315 | RledA=1; |
xlizne01 | 3:94bfc4de4ab1 | 316 | RledB=1; |
xlizne01 | 3:94bfc4de4ab1 | 317 | } |
xlizne01 | 3:94bfc4de4ab1 | 318 | else |
xlizne01 | 3:94bfc4de4ab1 | 319 | { |
xlizne01 | 3:94bfc4de4ab1 | 320 | RledA=0; |
xlizne01 | 3:94bfc4de4ab1 | 321 | RledB=0; |
xlizne01 | 3:94bfc4de4ab1 | 322 | } |
xlizne01 | 0:ae588eb31707 | 323 | |
xlizne01 | 3:94bfc4de4ab1 | 324 | if(GREEN>0) |
xlizne01 | 3:94bfc4de4ab1 | 325 | { |
xlizne01 | 3:94bfc4de4ab1 | 326 | GledA=1; |
xlizne01 | 3:94bfc4de4ab1 | 327 | GledB=1; |
xlizne01 | 3:94bfc4de4ab1 | 328 | } |
xlizne01 | 3:94bfc4de4ab1 | 329 | else |
xlizne01 | 3:94bfc4de4ab1 | 330 | { |
xlizne01 | 3:94bfc4de4ab1 | 331 | GledA=0; |
xlizne01 | 3:94bfc4de4ab1 | 332 | GledB=0; |
xlizne01 | 3:94bfc4de4ab1 | 333 | } |
xlizne01 | 3:94bfc4de4ab1 | 334 | |
xlizne01 | 3:94bfc4de4ab1 | 335 | if(BLUE>0) |
xlizne01 | 3:94bfc4de4ab1 | 336 | { |
xlizne01 | 3:94bfc4de4ab1 | 337 | BledA=1; |
xlizne01 | 3:94bfc4de4ab1 | 338 | BledB=1; |
xlizne01 | 3:94bfc4de4ab1 | 339 | } |
xlizne01 | 3:94bfc4de4ab1 | 340 | else |
xlizne01 | 3:94bfc4de4ab1 | 341 | { |
xlizne01 | 3:94bfc4de4ab1 | 342 | BledA=0; |
xlizne01 | 3:94bfc4de4ab1 | 343 | BledB=0; |
xlizne01 | 3:94bfc4de4ab1 | 344 | } |
xlizne01 | 0:ae588eb31707 | 345 | |
xlizne01 | 3:94bfc4de4ab1 | 346 | if(j==0) |
xlizne01 | 3:94bfc4de4ab1 | 347 | { |
xlizne01 | 3:94bfc4de4ab1 | 348 | Rled1=RledA; |
xlizne01 | 3:94bfc4de4ab1 | 349 | Rled2=RledB; |
xlizne01 | 3:94bfc4de4ab1 | 350 | Gled1=GledA; |
xlizne01 | 3:94bfc4de4ab1 | 351 | Gled2=GledB; |
xlizne01 | 3:94bfc4de4ab1 | 352 | Bled1=BledA; |
xlizne01 | 3:94bfc4de4ab1 | 353 | Bled2=BledB; |
xlizne01 | 3:94bfc4de4ab1 | 354 | } |
xlizne01 | 3:94bfc4de4ab1 | 355 | |
xlizne01 | 3:94bfc4de4ab1 | 356 | if(j==1) |
xlizne01 | 3:94bfc4de4ab1 | 357 | { |
xlizne01 | 3:94bfc4de4ab1 | 358 | Rled3=RledA; |
xlizne01 | 3:94bfc4de4ab1 | 359 | Rled4=RledB; |
xlizne01 | 3:94bfc4de4ab1 | 360 | Gled3=GledA; |
xlizne01 | 3:94bfc4de4ab1 | 361 | Gled4=GledB; |
xlizne01 | 3:94bfc4de4ab1 | 362 | Bled3=BledA; |
xlizne01 | 3:94bfc4de4ab1 | 363 | Bled4=BledB; |
xlizne01 | 3:94bfc4de4ab1 | 364 | } |
xlizne01 | 3:94bfc4de4ab1 | 365 | |
xlizne01 | 3:94bfc4de4ab1 | 366 | if(j==2) |
xlizne01 | 3:94bfc4de4ab1 | 367 | { |
xlizne01 | 3:94bfc4de4ab1 | 368 | Rled5=RledA; |
xlizne01 | 3:94bfc4de4ab1 | 369 | Rled6=RledB; |
xlizne01 | 3:94bfc4de4ab1 | 370 | Gled5=GledA; |
xlizne01 | 3:94bfc4de4ab1 | 371 | Gled6=GledB; |
xlizne01 | 3:94bfc4de4ab1 | 372 | Bled5=BledA; |
xlizne01 | 3:94bfc4de4ab1 | 373 | Bled6=BledB; |
xlizne01 | 3:94bfc4de4ab1 | 374 | } |
xlizne01 | 3:94bfc4de4ab1 | 375 | |
xlizne01 | 3:94bfc4de4ab1 | 376 | if(j==3) |
xlizne01 | 3:94bfc4de4ab1 | 377 | { |
xlizne01 | 3:94bfc4de4ab1 | 378 | Rled7=RledA; |
xlizne01 | 3:94bfc4de4ab1 | 379 | Rled8=RledB; |
xlizne01 | 3:94bfc4de4ab1 | 380 | Gled7=GledA; |
xlizne01 | 3:94bfc4de4ab1 | 381 | Gled8=GledB; |
xlizne01 | 3:94bfc4de4ab1 | 382 | Bled7=BledA; |
xlizne01 | 3:94bfc4de4ab1 | 383 | Bled8=BledB; |
xlizne01 | 3:94bfc4de4ab1 | 384 | } |
xlizne01 | 7:29f6c0e0b427 | 385 | |
xlizne01 | 7:29f6c0e0b427 | 386 | wait(0.00001); |
xlizne01 | 3:94bfc4de4ab1 | 387 | RED--; |
xlizne01 | 3:94bfc4de4ab1 | 388 | BLUE--; |
xlizne01 | 7:29f6c0e0b427 | 389 | GREEN--; |
xlizne01 | 3:94bfc4de4ab1 | 390 | } |
xlizne01 | 3:94bfc4de4ab1 | 391 | } |
xlizne01 | 7:29f6c0e0b427 | 392 | } |
xlizne01 | 3:94bfc4de4ab1 | 393 | } |
xlizne01 | 3:94bfc4de4ab1 | 394 | |
xlizne01 | 3:94bfc4de4ab1 | 395 | void barva(int j , int k) |
xlizne01 | 3:94bfc4de4ab1 | 396 | { |
xlizne01 | 7:29f6c0e0b427 | 397 | if(pole[j][k]==0) |
xlizne01 | 7:29f6c0e0b427 | 398 | { |
xlizne01 | 7:29f6c0e0b427 | 399 | RED=0; |
xlizne01 | 7:29f6c0e0b427 | 400 | GREEN=0; |
xlizne01 | 7:29f6c0e0b427 | 401 | BLUE=0; |
xlizne01 | 7:29f6c0e0b427 | 402 | } |
xlizne01 | 7:29f6c0e0b427 | 403 | if(pole[j][k]==2) |
xlizne01 | 7:29f6c0e0b427 | 404 | { |
xlizne01 | 7:29f6c0e0b427 | 405 | RED=2; |
xlizne01 | 7:29f6c0e0b427 | 406 | GREEN=0; |
xlizne01 | 7:29f6c0e0b427 | 407 | BLUE=0; |
xlizne01 | 7:29f6c0e0b427 | 408 | } |
xlizne01 | 7:29f6c0e0b427 | 409 | if(pole[j][k]==4) |
xlizne01 | 7:29f6c0e0b427 | 410 | { |
xlizne01 | 7:29f6c0e0b427 | 411 | RED=10; |
xlizne01 | 7:29f6c0e0b427 | 412 | GREEN=0; |
xlizne01 | 7:29f6c0e0b427 | 413 | BLUE=0; |
xlizne01 | 7:29f6c0e0b427 | 414 | } |
xlizne01 | 7:29f6c0e0b427 | 415 | if(pole[j][k]==8) |
xlizne01 | 7:29f6c0e0b427 | 416 | { |
xlizne01 | 7:29f6c0e0b427 | 417 | RED=0; |
xlizne01 | 7:29f6c0e0b427 | 418 | GREEN=0; |
xlizne01 | 7:29f6c0e0b427 | 419 | BLUE=2; |
xlizne01 | 7:29f6c0e0b427 | 420 | } |
xlizne01 | 7:29f6c0e0b427 | 421 | if(pole[j][k]==16) |
xlizne01 | 7:29f6c0e0b427 | 422 | { |
xlizne01 | 7:29f6c0e0b427 | 423 | RED=0; |
xlizne01 | 7:29f6c0e0b427 | 424 | GREEN=0; |
xlizne01 | 7:29f6c0e0b427 | 425 | BLUE=10; |
xlizne01 | 7:29f6c0e0b427 | 426 | } |
xlizne01 | 7:29f6c0e0b427 | 427 | if(pole[j][k]==32) |
xlizne01 | 7:29f6c0e0b427 | 428 | { |
xlizne01 | 7:29f6c0e0b427 | 429 | RED=0; |
xlizne01 | 7:29f6c0e0b427 | 430 | GREEN=2; |
xlizne01 | 7:29f6c0e0b427 | 431 | BLUE=0; |
xlizne01 | 7:29f6c0e0b427 | 432 | } |
xlizne01 | 7:29f6c0e0b427 | 433 | if(pole[j][k]==64) |
xlizne01 | 7:29f6c0e0b427 | 434 | { |
xlizne01 | 7:29f6c0e0b427 | 435 | RED=0; |
xlizne01 | 7:29f6c0e0b427 | 436 | GREEN=10; |
xlizne01 | 7:29f6c0e0b427 | 437 | BLUE=0; |
xlizne01 | 7:29f6c0e0b427 | 438 | } |
xlizne01 | 7:29f6c0e0b427 | 439 | if(pole[j][k]==128) |
xlizne01 | 7:29f6c0e0b427 | 440 | { |
xlizne01 | 7:29f6c0e0b427 | 441 | RED=0; |
xlizne01 | 7:29f6c0e0b427 | 442 | GREEN=10; |
xlizne01 | 7:29f6c0e0b427 | 443 | BLUE=10; |
xlizne01 | 7:29f6c0e0b427 | 444 | } |
xlizne01 | 7:29f6c0e0b427 | 445 | if(pole[j][k]==256) |
xlizne01 | 7:29f6c0e0b427 | 446 | { |
xlizne01 | 7:29f6c0e0b427 | 447 | RED=10; |
xlizne01 | 7:29f6c0e0b427 | 448 | GREEN=0; |
xlizne01 | 7:29f6c0e0b427 | 449 | BLUE=10; |
xlizne01 | 7:29f6c0e0b427 | 450 | } |
xlizne01 | 7:29f6c0e0b427 | 451 | if(pole[j][k]==512) |
xlizne01 | 7:29f6c0e0b427 | 452 | { |
xlizne01 | 7:29f6c0e0b427 | 453 | RED=10; |
xlizne01 | 7:29f6c0e0b427 | 454 | GREEN=10; |
xlizne01 | 7:29f6c0e0b427 | 455 | BLUE=0; |
xlizne01 | 7:29f6c0e0b427 | 456 | } |
xlizne01 | 7:29f6c0e0b427 | 457 | if(pole[j][k]==1024) |
xlizne01 | 7:29f6c0e0b427 | 458 | { |
xlizne01 | 7:29f6c0e0b427 | 459 | RED=2; |
xlizne01 | 7:29f6c0e0b427 | 460 | GREEN=2; |
xlizne01 | 7:29f6c0e0b427 | 461 | BLUE=2; |
xlizne01 | 7:29f6c0e0b427 | 462 | } |
xlizne01 | 7:29f6c0e0b427 | 463 | if(pole[j][k]==2048) |
xlizne01 | 7:29f6c0e0b427 | 464 | { |
xlizne01 | 7:29f6c0e0b427 | 465 | RED=10; |
xlizne01 | 7:29f6c0e0b427 | 466 | GREEN=10; |
xlizne01 | 7:29f6c0e0b427 | 467 | BLUE=10; |
xlizne01 | 7:29f6c0e0b427 | 468 | } |
xlizne01 | 0:ae588eb31707 | 469 | } |
xlizne01 | 3:94bfc4de4ab1 | 470 | |
xlizne01 | 2:3278e4fd8fc2 | 471 | |
xlizne01 | 2:3278e4fd8fc2 | 472 | void accelerometer() |
xlizne01 | 2:3278e4fd8fc2 | 473 | { |
xlizne01 | 7:29f6c0e0b427 | 474 | float ax, ay, az; |
xlizne01 | 4:4930b1cb20bd | 475 | |
xlizne01 | 7:29f6c0e0b427 | 476 | ax = acc.getAccX(); |
xlizne01 | 7:29f6c0e0b427 | 477 | ay = acc.getAccY(); |
xlizne01 | 7:29f6c0e0b427 | 478 | az = acc.getAccZ(); |
xlizne01 | 2:3278e4fd8fc2 | 479 | |
xlizne01 | 7:29f6c0e0b427 | 480 | xAngle = atan( ax / (sqrt((ay)*(ay) + (az)*(az)))) * 60; |
xlizne01 | 7:29f6c0e0b427 | 481 | yAngle = atan( ay / (sqrt((ax)*(ax) + (az)*(az)))) * 60; |
xlizne01 | 2:3278e4fd8fc2 | 482 | |
xlizne01 | 2:3278e4fd8fc2 | 483 | |
xlizne01 | 7:29f6c0e0b427 | 484 | if((abs(xAngle)+abs(yAngle))<15) |
xlizne01 | 7:29f6c0e0b427 | 485 | { |
xlizne01 | 7:29f6c0e0b427 | 486 | acc_dir = '0'; // nula |
xlizne01 | 7:29f6c0e0b427 | 487 | } |
xlizne01 | 4:4930b1cb20bd | 488 | |
xlizne01 | 4:4930b1cb20bd | 489 | |
xlizne01 | 7:29f6c0e0b427 | 490 | if(abs(xAngle) >= abs(yAngle)) |
xlizne01 | 7:29f6c0e0b427 | 491 | { |
xlizne01 | 7:29f6c0e0b427 | 492 | if(xAngle >= MOVE_ANGLE) |
xlizne01 | 7:29f6c0e0b427 | 493 | { |
xlizne01 | 7:29f6c0e0b427 | 494 | acc_dir = 'U'; // +X |
xlizne01 | 2:3278e4fd8fc2 | 495 | } |
xlizne01 | 7:29f6c0e0b427 | 496 | |
xlizne01 | 7:29f6c0e0b427 | 497 | if(xAngle <= -MOVE_ANGLE) |
xlizne01 | 7:29f6c0e0b427 | 498 | { |
xlizne01 | 7:29f6c0e0b427 | 499 | acc_dir = 'D'; // -X |
xlizne01 | 7:29f6c0e0b427 | 500 | } |
xlizne01 | 7:29f6c0e0b427 | 501 | } |
xlizne01 | 7:29f6c0e0b427 | 502 | else |
xlizne01 | 7:29f6c0e0b427 | 503 | { |
xlizne01 | 7:29f6c0e0b427 | 504 | if(yAngle >= MOVE_ANGLE) |
xlizne01 | 7:29f6c0e0b427 | 505 | { |
xlizne01 | 7:29f6c0e0b427 | 506 | acc_dir = 'L'; // +Y |
xlizne01 | 7:29f6c0e0b427 | 507 | } |
xlizne01 | 2:3278e4fd8fc2 | 508 | |
xlizne01 | 7:29f6c0e0b427 | 509 | if(yAngle <= -MOVE_ANGLE) |
xlizne01 | 7:29f6c0e0b427 | 510 | { |
xlizne01 | 7:29f6c0e0b427 | 511 | acc_dir = 'R'; // -Y |
xlizne01 | 7:29f6c0e0b427 | 512 | } |
xlizne01 | 7:29f6c0e0b427 | 513 | } |
xlizne01 | 3:94bfc4de4ab1 | 514 | } |