school project

Dependencies:   MMA8451Q mbed

Committer:
xlizne01
Date:
Fri Jan 15 00:52:31 2016 +0000
Revision:
8:5f485026374d
Parent:
7:29f6c0e0b427
Child:
9:8a738bd758de
opraveno nahodne generovani; ; plne funkcni

Who changed what in which revision?

UserRevisionLine numberNew 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 8:5f485026374d 5 #define MOVE_ANGLE 35 // minimalni uhel pro pohyb
xlizne01 8:5f485026374d 6 #define NULL_ANGLE 15 // minimalni uhel pro nulovou pozici
xlizne01 2:3278e4fd8fc2 7
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 8:5f485026374d 18 int RED, GREEN, BLUE;
xlizne01 8:5f485026374d 19 float xAngle, yAngle; //aktualni uhel v ose x a y
xlizne01 6:5711a5b57d17 20 int p=1;
xlizne01 8:5f485026374d 21
xlizne01 8:5f485026374d 22 char acc_dir; //směr pohybu
xlizne01 3:94bfc4de4ab1 23
xlizne01 8:5f485026374d 24 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 25 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 26
xlizne01 8:5f485026374d 27
xlizne01 8:5f485026374d 28 //Definice výstupních pinů pro jednotlivé řádky (anody LED)
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 8:5f485026374d 38 //Definice výstupních pinů pro jednotlivé sloupce (katody LED)
xlizne01 0:ae588eb31707 39 DigitalOut Rled1(PTC9);
xlizne01 0:ae588eb31707 40 DigitalOut Rled2(PTC8);
xlizne01 0:ae588eb31707 41 DigitalOut Rled3(PTA5);
xlizne01 0:ae588eb31707 42 DigitalOut Rled4(PTA4);
xlizne01 0:ae588eb31707 43 DigitalOut Rled5(PTA12);
xlizne01 0:ae588eb31707 44 DigitalOut Rled6(PTD4);
xlizne01 0:ae588eb31707 45 DigitalOut Rled7(PTA1);
xlizne01 0:ae588eb31707 46 DigitalOut Rled8(PTA2);
xlizne01 0:ae588eb31707 47
xlizne01 0:ae588eb31707 48 DigitalOut Gled1(PTA13);
xlizne01 0:ae588eb31707 49 DigitalOut Gled2(PTD5);
xlizne01 0:ae588eb31707 50 DigitalOut Gled3(PTD0);
xlizne01 0:ae588eb31707 51 DigitalOut Gled4(PTD2);
xlizne01 0:ae588eb31707 52 DigitalOut Gled5(PTD3);
xlizne01 0:ae588eb31707 53 DigitalOut Gled6(PTD1);
xlizne01 0:ae588eb31707 54 DigitalOut Gled7(PTE31);
xlizne01 0:ae588eb31707 55 DigitalOut Gled8(PTB0);
xlizne01 0:ae588eb31707 56
xlizne01 0:ae588eb31707 57 DigitalOut Bled1(PTC1);
xlizne01 0:ae588eb31707 58 DigitalOut Bled2(PTE29);
xlizne01 0:ae588eb31707 59 DigitalOut Bled3(PTC2);
xlizne01 0:ae588eb31707 60 DigitalOut Bled4(PTB3);
xlizne01 0:ae588eb31707 61 DigitalOut Bled5(PTB2);
xlizne01 0:ae588eb31707 62 DigitalOut Bled6(PTE21);
xlizne01 0:ae588eb31707 63 DigitalOut Bled7(PTE20);
xlizne01 0:ae588eb31707 64 DigitalOut Bled8(PTB1);
xlizne01 0:ae588eb31707 65
xlizne01 0:ae588eb31707 66
xlizne01 8:5f485026374d 67 int main()
xlizne01 0:ae588eb31707 68 {
xlizne01 8:5f485026374d 69 accelerometer();
xlizne01 8:5f485026374d 70 pridej();
xlizne01 8:5f485026374d 71 pridej(); //přidání prvních dvou kostek
xlizne01 7:29f6c0e0b427 72
xlizne01 3:94bfc4de4ab1 73 while(1)
xlizne01 3:94bfc4de4ab1 74 {
xlizne01 8:5f485026374d 75 accelerometer();
xlizne01 8:5f485026374d 76 pohyb();
xlizne01 8:5f485026374d 77 zobrazeni();
xlizne01 0:ae588eb31707 78 }
xlizne01 3:94bfc4de4ab1 79 }
xlizne01 7:29f6c0e0b427 80
xlizne01 8:5f485026374d 81 ////////////////////////////////////////////////////////////////////////////////
xlizne01 7:29f6c0e0b427 82
xlizne01 4:4930b1cb20bd 83 void pohyb()
xlizne01 8:5f485026374d 84 {
xlizne01 4:4930b1cb20bd 85 switch(acc_dir)
xlizne01 4:4930b1cb20bd 86 {
xlizne01 7:29f6c0e0b427 87 case 'D': //pohyb smerem dolu
xlizne01 7:29f6c0e0b427 88 if(p==0)
xlizne01 7:29f6c0e0b427 89 {
xlizne01 7:29f6c0e0b427 90 proved(1);
xlizne01 7:29f6c0e0b427 91 p=1;
xlizne01 7:29f6c0e0b427 92 }
xlizne01 7:29f6c0e0b427 93 break;
xlizne01 7:29f6c0e0b427 94
xlizne01 7:29f6c0e0b427 95 case 'R': // pohyb smerem vpravo
xlizne01 7:29f6c0e0b427 96 if(p==0)
xlizne01 7:29f6c0e0b427 97 {
xlizne01 7:29f6c0e0b427 98 proved(2);
xlizne01 7:29f6c0e0b427 99 p=1;
xlizne01 7:29f6c0e0b427 100 }
xlizne01 7:29f6c0e0b427 101 break;
xlizne01 7:29f6c0e0b427 102
xlizne01 7:29f6c0e0b427 103 case 'U': // pohyb smerem nahoru
xlizne01 7:29f6c0e0b427 104 if(p==0)
xlizne01 7:29f6c0e0b427 105 {
xlizne01 7:29f6c0e0b427 106 proved(3);
xlizne01 7:29f6c0e0b427 107 p=1;
xlizne01 7:29f6c0e0b427 108 }
xlizne01 7:29f6c0e0b427 109 break;
xlizne01 7:29f6c0e0b427 110
xlizne01 7:29f6c0e0b427 111 case 'L': // pohyb smerem vlevo
xlizne01 7:29f6c0e0b427 112 if(p==0)
xlizne01 7:29f6c0e0b427 113 {
xlizne01 7:29f6c0e0b427 114 proved(4);
xlizne01 7:29f6c0e0b427 115 p=1;
xlizne01 7:29f6c0e0b427 116 }
xlizne01 7:29f6c0e0b427 117 break;
xlizne01 7:29f6c0e0b427 118
xlizne01 7:29f6c0e0b427 119 case '0': // detekovana nulova pozice
xlizne01 7:29f6c0e0b427 120 p=0;
xlizne01 7:29f6c0e0b427 121 break;
xlizne01 7:29f6c0e0b427 122
xlizne01 7:29f6c0e0b427 123 default:
xlizne01 7:29f6c0e0b427 124 break;
xlizne01 4:4930b1cb20bd 125 }
xlizne01 4:4930b1cb20bd 126 }
xlizne01 4:4930b1cb20bd 127
xlizne01 8:5f485026374d 128 ///////////////////////////////////////////////////////////////////////////////
xlizne01 8:5f485026374d 129
xlizne01 6:5711a5b57d17 130 void proved(int x)
xlizne01 6:5711a5b57d17 131 {
xlizne01 8:5f485026374d 132 int a,b,c,d; //pomocné proměnné pro uložení řádků/sloupců při sesypání
xlizne01 8:5f485026374d 133 int same=0; // pomocná proměnná
xlizne01 6:5711a5b57d17 134
xlizne01 8:5f485026374d 135 for(int k=0;k<4;k++)
xlizne01 6:5711a5b57d17 136 {
xlizne01 8:5f485026374d 137 for(int l=0;l<4;l++)
xlizne01 7:29f6c0e0b427 138 {
xlizne01 8:5f485026374d 139 pole2[k][l]=pole[k][l]; //uložení původní matice do pomocné matice
xlizne01 8:5f485026374d 140 }
xlizne01 8:5f485026374d 141 }
xlizne01 8:5f485026374d 142
xlizne01 8:5f485026374d 143 for(int n=0;n<4;n++)
xlizne01 8:5f485026374d 144 {
xlizne01 6:5711a5b57d17 145 if(x==1) // dolu
xlizne01 6:5711a5b57d17 146 {
xlizne01 6:5711a5b57d17 147 a=pole[n][0];
xlizne01 6:5711a5b57d17 148 b=pole[n][1];
xlizne01 6:5711a5b57d17 149 c=pole[n][2];
xlizne01 6:5711a5b57d17 150 d=pole[n][3];
xlizne01 6:5711a5b57d17 151 }
xlizne01 6:5711a5b57d17 152
xlizne01 6:5711a5b57d17 153 if(x==2) // vpravo
xlizne01 6:5711a5b57d17 154 {
xlizne01 6:5711a5b57d17 155 a=pole[3][n];
xlizne01 6:5711a5b57d17 156 b=pole[2][n];
xlizne01 6:5711a5b57d17 157 c=pole[1][n];
xlizne01 6:5711a5b57d17 158 d=pole[0][n];
xlizne01 6:5711a5b57d17 159 }
xlizne01 6:5711a5b57d17 160
xlizne01 6:5711a5b57d17 161 if(x==3) // nahoru
xlizne01 6:5711a5b57d17 162 {
xlizne01 6:5711a5b57d17 163 a=pole[n][3];
xlizne01 6:5711a5b57d17 164 b=pole[n][2];
xlizne01 6:5711a5b57d17 165 c=pole[n][1];
xlizne01 6:5711a5b57d17 166 d=pole[n][0];
xlizne01 6:5711a5b57d17 167 }
xlizne01 6:5711a5b57d17 168
xlizne01 6:5711a5b57d17 169 if(x==4) // vlevo
xlizne01 6:5711a5b57d17 170 {
xlizne01 6:5711a5b57d17 171 a=pole[0][n];
xlizne01 6:5711a5b57d17 172 b=pole[1][n];
xlizne01 6:5711a5b57d17 173 c=pole[2][n];
xlizne01 6:5711a5b57d17 174 d=pole[3][n];
xlizne01 6:5711a5b57d17 175 }
xlizne01 6:5711a5b57d17 176
xlizne01 8:5f485026374d 177 //sesypani
xlizne01 6:5711a5b57d17 178 if(a==0)
xlizne01 6:5711a5b57d17 179 {a=b; b=c; c=d; d=0;}
xlizne01 6:5711a5b57d17 180 if(a==0)
xlizne01 6:5711a5b57d17 181 {a=b; b=c; c=d; d=0;}
xlizne01 6:5711a5b57d17 182 if(a==0)
xlizne01 6:5711a5b57d17 183 {a=b; b=c; c=d; d=0;}
xlizne01 6:5711a5b57d17 184 if(b==0)
xlizne01 6:5711a5b57d17 185 {b=c; c=d; d=0;}
xlizne01 6:5711a5b57d17 186 if(b==0)
xlizne01 6:5711a5b57d17 187 {b=c; c=d; d=0;}
xlizne01 6:5711a5b57d17 188 if(c==0)
xlizne01 6:5711a5b57d17 189 {c=d; d=0;}
xlizne01 6:5711a5b57d17 190
xlizne01 6:5711a5b57d17 191 //spojeni
xlizne01 6:5711a5b57d17 192 if(a==b)
xlizne01 6:5711a5b57d17 193 {a=2*a; b=c; c=d; d=0;}
xlizne01 6:5711a5b57d17 194 if(b==c)
xlizne01 6:5711a5b57d17 195 {b=2*b; c=d; d=0;}
xlizne01 6:5711a5b57d17 196 if(c==d)
xlizne01 6:5711a5b57d17 197 {c=2*c; d=0;}
xlizne01 6:5711a5b57d17 198
xlizne01 6:5711a5b57d17 199 if(x==1) // dolu
xlizne01 6:5711a5b57d17 200 {
xlizne01 6:5711a5b57d17 201 pole[n][0]=a;
xlizne01 6:5711a5b57d17 202 pole[n][1]=b;
xlizne01 6:5711a5b57d17 203 pole[n][2]=c;
xlizne01 6:5711a5b57d17 204 pole[n][3]=d;
xlizne01 6:5711a5b57d17 205 }
xlizne01 8:5f485026374d 206
xlizne01 6:5711a5b57d17 207 if(x==2) // vpravo
xlizne01 6:5711a5b57d17 208 {
xlizne01 6:5711a5b57d17 209 pole[3][n]=a;
xlizne01 6:5711a5b57d17 210 pole[2][n]=b;
xlizne01 6:5711a5b57d17 211 pole[1][n]=c;
xlizne01 6:5711a5b57d17 212 pole[0][n]=d;
xlizne01 6:5711a5b57d17 213 }
xlizne01 6:5711a5b57d17 214
xlizne01 6:5711a5b57d17 215 if(x==3) // nahoru
xlizne01 6:5711a5b57d17 216 {
xlizne01 6:5711a5b57d17 217 pole[n][3]=a;
xlizne01 6:5711a5b57d17 218 pole[n][2]=b;
xlizne01 6:5711a5b57d17 219 pole[n][1]=c;
xlizne01 6:5711a5b57d17 220 pole[n][0]=d;
xlizne01 6:5711a5b57d17 221 }
xlizne01 6:5711a5b57d17 222
xlizne01 6:5711a5b57d17 223 if(x==4) // vlevo
xlizne01 6:5711a5b57d17 224 {
xlizne01 6:5711a5b57d17 225 pole[0][n]=a;
xlizne01 6:5711a5b57d17 226 pole[1][n]=b;
xlizne01 6:5711a5b57d17 227 pole[2][n]=c;
xlizne01 6:5711a5b57d17 228 pole[3][n]=d;
xlizne01 7:29f6c0e0b427 229 }
xlizne01 7:29f6c0e0b427 230 }
xlizne01 8:5f485026374d 231
xlizne01 8:5f485026374d 232 for(int q=0;q<4;q++)
xlizne01 8:5f485026374d 233 {
xlizne01 8:5f485026374d 234 for(int w=0;w<4;w++)
xlizne01 8:5f485026374d 235 {
xlizne01 8:5f485026374d 236 if (pole2[q][w]!=pole[q][w]) //kontrola, že došlo k nějaké změně v matici
xlizne01 8:5f485026374d 237 {
xlizne01 8:5f485026374d 238 same=1;
xlizne01 8:5f485026374d 239 }
xlizne01 8:5f485026374d 240 }
xlizne01 8:5f485026374d 241 }
xlizne01 8:5f485026374d 242
xlizne01 8:5f485026374d 243 if(same==1)
xlizne01 8:5f485026374d 244 {
xlizne01 8:5f485026374d 245 pridej();
xlizne01 8:5f485026374d 246 }
xlizne01 8:5f485026374d 247
xlizne01 6:5711a5b57d17 248 }
xlizne01 8:5f485026374d 249
xlizne01 8:5f485026374d 250 ///////////////////////////////////////////////////////////////////////////////
xlizne01 8:5f485026374d 251
xlizne01 8:5f485026374d 252 void pridej()
xlizne01 8:5f485026374d 253 {
xlizne01 8:5f485026374d 254 int g=1;
xlizne01 8:5f485026374d 255 int f; // nahodne cislo v rozmezi 0-15 sloužící ke generování náhodnách souřadnic
xlizne01 8:5f485026374d 256
xlizne01 8:5f485026374d 257 while(g==1)
xlizne01 8:5f485026374d 258 {
xlizne01 8:5f485026374d 259 f =(rand()+int(xAngle)+int(yAngle))%16;
xlizne01 8:5f485026374d 260 if(pole[f/4][f%4]==0)
xlizne01 8:5f485026374d 261 {
xlizne01 8:5f485026374d 262 if((rand()+int(xAngle)+int(yAngle))%10==0) // reprezentuje 10% šanci, že se oběví 4
xlizne01 8:5f485026374d 263 {
xlizne01 8:5f485026374d 264 pole[f/4][f%4]=4;
xlizne01 8:5f485026374d 265 g=0;
xlizne01 8:5f485026374d 266 }
xlizne01 8:5f485026374d 267 else // přidání čísla 2
xlizne01 8:5f485026374d 268 {
xlizne01 8:5f485026374d 269 pole[f/4][f%4]=2;
xlizne01 8:5f485026374d 270 g=0;
xlizne01 8:5f485026374d 271 }
xlizne01 8:5f485026374d 272 }
xlizne01 8:5f485026374d 273 }
xlizne01 8:5f485026374d 274 }
xlizne01 8:5f485026374d 275
xlizne01 8:5f485026374d 276 //////////////////////////////////////////////////////////////////////////////
xlizne01 3:94bfc4de4ab1 277
xlizne01 3:94bfc4de4ab1 278 void zobrazeni()
xlizne01 3:94bfc4de4ab1 279 {
xlizne01 8:5f485026374d 280 int RledA, RledB, GledA, GledB, BledA, BledB;
xlizne01 8:5f485026374d 281
xlizne01 8:5f485026374d 282 for(int k=0;k<4;k++)
xlizne01 3:94bfc4de4ab1 283 {
xlizne01 3:94bfc4de4ab1 284 prvni=0;
xlizne01 3:94bfc4de4ab1 285 druhy=0;
xlizne01 3:94bfc4de4ab1 286 treti=0;
xlizne01 3:94bfc4de4ab1 287 ctvrty=0;
xlizne01 3:94bfc4de4ab1 288 paty=0;
xlizne01 3:94bfc4de4ab1 289 sesty=0;
xlizne01 3:94bfc4de4ab1 290 sedmy=0;
xlizne01 3:94bfc4de4ab1 291 osmy=0;
xlizne01 3:94bfc4de4ab1 292
xlizne01 7:29f6c0e0b427 293 wait(0.00005); //proti tzv. duchum
xlizne01 7:29f6c0e0b427 294
xlizne01 3:94bfc4de4ab1 295 if(k==0)
xlizne01 0:ae588eb31707 296 {
xlizne01 8:5f485026374d 297 prvni=1;
xlizne01 8:5f485026374d 298 druhy=1;
xlizne01 0:ae588eb31707 299 }
xlizne01 3:94bfc4de4ab1 300
xlizne01 3:94bfc4de4ab1 301 if(k==1)
xlizne01 0:ae588eb31707 302 {
xlizne01 8:5f485026374d 303 treti=1;
xlizne01 8:5f485026374d 304 ctvrty=1;
xlizne01 0:ae588eb31707 305 }
xlizne01 3:94bfc4de4ab1 306
xlizne01 3:94bfc4de4ab1 307 if(k==2)
xlizne01 0:ae588eb31707 308 {
xlizne01 8:5f485026374d 309 paty=1;
xlizne01 8:5f485026374d 310 sesty=1;
xlizne01 0:ae588eb31707 311 }
xlizne01 3:94bfc4de4ab1 312
xlizne01 3:94bfc4de4ab1 313 if(k==3)
xlizne01 0:ae588eb31707 314 {
xlizne01 8:5f485026374d 315 sedmy=1;
xlizne01 8:5f485026374d 316 osmy=1;
xlizne01 0:ae588eb31707 317 }
xlizne01 0:ae588eb31707 318
xlizne01 8:5f485026374d 319 for(int j=0;j<4;j++)
xlizne01 3:94bfc4de4ab1 320 {
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 7:29f6c0e0b427 494 }
xlizne01 0:ae588eb31707 495 }
xlizne01 3:94bfc4de4ab1 496
xlizne01 8:5f485026374d 497 //////////////////////////////////////////////////////////////////////////////////////
xlizne01 2:3278e4fd8fc2 498
xlizne01 2:3278e4fd8fc2 499 void accelerometer()
xlizne01 2:3278e4fd8fc2 500 {
xlizne01 7:29f6c0e0b427 501 float ax, ay, az;
xlizne01 4:4930b1cb20bd 502
xlizne01 7:29f6c0e0b427 503 ax = acc.getAccX();
xlizne01 7:29f6c0e0b427 504 ay = acc.getAccY();
xlizne01 7:29f6c0e0b427 505 az = acc.getAccZ();
xlizne01 2:3278e4fd8fc2 506
xlizne01 7:29f6c0e0b427 507 xAngle = atan( ax / (sqrt((ay)*(ay) + (az)*(az)))) * 60;
xlizne01 7:29f6c0e0b427 508 yAngle = atan( ay / (sqrt((ax)*(ax) + (az)*(az)))) * 60;
xlizne01 2:3278e4fd8fc2 509
xlizne01 2:3278e4fd8fc2 510
xlizne01 8:5f485026374d 511 if((abs(xAngle)+abs(yAngle))<NULL_ANGLE)
xlizne01 7:29f6c0e0b427 512 {
xlizne01 8:5f485026374d 513 acc_dir = '0'; // 0 nula
xlizne01 7:29f6c0e0b427 514 }
xlizne01 4:4930b1cb20bd 515
xlizne01 4:4930b1cb20bd 516
xlizne01 7:29f6c0e0b427 517 if(abs(xAngle) >= abs(yAngle))
xlizne01 7:29f6c0e0b427 518 {
xlizne01 7:29f6c0e0b427 519 if(xAngle >= MOVE_ANGLE)
xlizne01 7:29f6c0e0b427 520 {
xlizne01 8:5f485026374d 521 acc_dir = 'U'; // +X up
xlizne01 2:3278e4fd8fc2 522 }
xlizne01 7:29f6c0e0b427 523
xlizne01 7:29f6c0e0b427 524 if(xAngle <= -MOVE_ANGLE)
xlizne01 7:29f6c0e0b427 525 {
xlizne01 8:5f485026374d 526 acc_dir = 'D'; // -X down
xlizne01 7:29f6c0e0b427 527 }
xlizne01 7:29f6c0e0b427 528 }
xlizne01 8:5f485026374d 529
xlizne01 7:29f6c0e0b427 530 else
xlizne01 7:29f6c0e0b427 531 {
xlizne01 7:29f6c0e0b427 532 if(yAngle >= MOVE_ANGLE)
xlizne01 7:29f6c0e0b427 533 {
xlizne01 8:5f485026374d 534 acc_dir = 'L'; // +Y left
xlizne01 7:29f6c0e0b427 535 }
xlizne01 2:3278e4fd8fc2 536
xlizne01 7:29f6c0e0b427 537 if(yAngle <= -MOVE_ANGLE)
xlizne01 7:29f6c0e0b427 538 {
xlizne01 8:5f485026374d 539 acc_dir = 'R'; // -Y right
xlizne01 7:29f6c0e0b427 540 }
xlizne01 8:5f485026374d 541 }
xlizne01 3:94bfc4de4ab1 542 }