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