juego 2 presentación

Dependencies:   mbed MPU6050

Committer:
oggonei
Date:
Thu Nov 22 14:18:44 2018 +0000
Revision:
9:70db7947a48c
Parent:
8:9c2dff610de9
juego 2 presentaci?n

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jiuk 0:2dabb9782f24 1 // Read from I2C slave at address 0x62
jiuk 0:2dabb9782f24 2
jiuk 0:2dabb9782f24 3 #include "mbed.h"
jiuk 5:f8ca9f670abe 4 #include "Ticker.h"
jiuk 0:2dabb9782f24 5 #include "MPU6050.h"
jiuk 0:2dabb9782f24 6
jiuk 8:9c2dff610de9 7 //Serial command(USBTX,USBRX); //habilitar la comunicacion serial a traves del puerto usb.
jiuk 0:2dabb9782f24 8 MPU6050 Wire(PB_9 , PB_8 );
jiuk 0:2dabb9782f24 9
jiuk 0:2dabb9782f24 10 SPI deviceM(PB_15, PB_14, PB_13);
jiuk 0:2dabb9782f24 11 DigitalOut ssel (PB_12);
jiuk 0:2dabb9782f24 12 //SPI deviceM(PB_5, PB_4, PB_3); //define el Clock, Dato salida (miso) y Dato de entrada (mosi).
jiuk 0:2dabb9782f24 13 //DigitalOut ssel (PB_9); //Chip Select para el controlador.
jiuk 0:2dabb9782f24 14 //Serial command(USBTX,USBRX); //habilitar la comunicacion serial a traves del puerto usb.
oggonei 9:70db7947a48c 15 //Serial com_tar(PC_10,PC_11); //master f446R
oggonei 9:70db7947a48c 16 Serial com_tar(PA_15,PB_7); //slave f411R //habilitar la comunicacion serial a traves del puerto usb.
jiuk 2:484928b9a5b5 17 Ticker timer;
jiuk 4:3426b2472f99 18 DigitalIn pulsador(PH_1);
jiuk 4:3426b2472f99 19 AnalogIn in1(PC_2);
jiuk 4:3426b2472f99 20 AnalogIn in2(PC_3);
jiuk 0:2dabb9782f24 21
jiuk 0:2dabb9782f24 22 #define VEL 200 //Velocidad de actualizacion de dato en el controlador.
jiuk 0:2dabb9782f24 23 #define MIN 1
jiuk 0:2dabb9782f24 24 #define MAX 8
jiuk 0:2dabb9782f24 25 #define MINC 128
jiuk 0:2dabb9782f24 26 #define MAXC 1
jiuk 0:2dabb9782f24 27 #define DEL 0.1
jiuk 3:81dc55b0a8d7 28 #define GIRO 2
jiuk 3:81dc55b0a8d7 29 #define G_DIAG 2
jiuk 0:2dabb9782f24 30
jiuk 2:484928b9a5b5 31 int columna=1,manzanas=0;
jiuk 0:2dabb9782f24 32 int fila=1, fil=1, colum=1;
jiuk 4:3426b2472f99 33 bool _boton=0;
jiuk 2:484928b9a5b5 34 void blink();
jiuk 4:3426b2472f99 35 void boton();
jiuk 7:5f1c8385cf8e 36 void sendSPI(uint8_t,uint8_t);
jiuk 8:9c2dff610de9 37 void borrar();
jiuk 7:5f1c8385cf8e 38
jiuk 7:5f1c8385cf8e 39
jiuk 7:5f1c8385cf8e 40 //--------------------------------------------------
jiuk 7:5f1c8385cf8e 41 //-------------------CARA_FELIZ------------------------
jiuk 7:5f1c8385cf8e 42 //--------------------------------------------------
jiuk 7:5f1c8385cf8e 43 void cara_feliz()
jiuk 7:5f1c8385cf8e 44 {
jiuk 8:9c2dff610de9 45 borrar();
jiuk 7:5f1c8385cf8e 46 sendSPI(0x02,0b01100110);
jiuk 7:5f1c8385cf8e 47 wait(0.2);
jiuk 7:5f1c8385cf8e 48 sendSPI(0x03,0b01100110);
jiuk 7:5f1c8385cf8e 49 wait(0.2);
jiuk 7:5f1c8385cf8e 50 sendSPI(0x06,0b01000010);
jiuk 7:5f1c8385cf8e 51 wait(0.2);
jiuk 7:5f1c8385cf8e 52 sendSPI(0x07,0b00111100);
jiuk 7:5f1c8385cf8e 53 wait(0.2);
jiuk 7:5f1c8385cf8e 54 for(int i=0;i<4;i++)
jiuk 7:5f1c8385cf8e 55 {
jiuk 7:5f1c8385cf8e 56 sendSPI(0x06,0x00);
jiuk 7:5f1c8385cf8e 57 sendSPI(0x07,0b00111100);
jiuk 7:5f1c8385cf8e 58 wait(0.2);
jiuk 7:5f1c8385cf8e 59 sendSPI(0x07,0b00111100);
jiuk 7:5f1c8385cf8e 60 wait(0.2);
jiuk 7:5f1c8385cf8e 61 sendSPI(0x06,0b01000010);
jiuk 7:5f1c8385cf8e 62 wait(0.2);
jiuk 7:5f1c8385cf8e 63 }
jiuk 7:5f1c8385cf8e 64 }
jiuk 7:5f1c8385cf8e 65
jiuk 7:5f1c8385cf8e 66 //--------------------------------------------------
jiuk 7:5f1c8385cf8e 67 //-------------------CARA_TRISTE------------------------
jiuk 7:5f1c8385cf8e 68 //--------------------------------------------------
jiuk 7:5f1c8385cf8e 69 void cara_triste()
jiuk 7:5f1c8385cf8e 70 {
jiuk 8:9c2dff610de9 71 borrar();
jiuk 7:5f1c8385cf8e 72 sendSPI(0x02,0b01100110);
jiuk 7:5f1c8385cf8e 73 wait(0.2);
jiuk 7:5f1c8385cf8e 74 sendSPI(0x03,0b01100110);
jiuk 7:5f1c8385cf8e 75 wait(0.2);
jiuk 7:5f1c8385cf8e 76 sendSPI(0x06,0b00111100);
jiuk 7:5f1c8385cf8e 77 wait(0.2);
jiuk 7:5f1c8385cf8e 78 sendSPI(0x07,0b01000010);
jiuk 7:5f1c8385cf8e 79 wait(0.2);
jiuk 7:5f1c8385cf8e 80 for(int i=0;i<4;i++)
jiuk 7:5f1c8385cf8e 81 {
jiuk 7:5f1c8385cf8e 82 sendSPI(0x07,0x00);
jiuk 7:5f1c8385cf8e 83 sendSPI(0x06,0b00111100);
jiuk 7:5f1c8385cf8e 84 wait(0.2);
jiuk 7:5f1c8385cf8e 85 sendSPI(0x06,0b00111100);
jiuk 7:5f1c8385cf8e 86 wait(0.2);
jiuk 7:5f1c8385cf8e 87 sendSPI(0x07,0b01000010);
jiuk 7:5f1c8385cf8e 88 wait(0.2);
jiuk 7:5f1c8385cf8e 89 }
jiuk 7:5f1c8385cf8e 90 }
jiuk 0:2dabb9782f24 91
jiuk 2:484928b9a5b5 92 //--------------------------------------------------
jiuk 2:484928b9a5b5 93 //-------------------TICKER------------------------
jiuk 2:484928b9a5b5 94 //--------------------------------------------------
jiuk 5:f8ca9f670abe 95 void attime()
jiuk 5:f8ca9f670abe 96 {
jiuk 2:484928b9a5b5 97 blink();
jiuk 5:f8ca9f670abe 98 boton();
jiuk 7:5f1c8385cf8e 99 if (com_tar.readable())
jiuk 6:4c9e8118c303 100 {
jiuk 8:9c2dff610de9 101 int x=com_tar.getc();
jiuk 8:9c2dff610de9 102 if(x==1)
jiuk 7:5f1c8385cf8e 103 cara_triste();
jiuk 8:9c2dff610de9 104 //command.printf("Button pressed %b\n", _boton);
jiuk 6:4c9e8118c303 105 }
jiuk 5:f8ca9f670abe 106 };
jiuk 4:3426b2472f99 107
jiuk 4:3426b2472f99 108 //--------------------------------------------------
jiuk 4:3426b2472f99 109 //-------------------BOTON------------------------
jiuk 4:3426b2472f99 110 //--------------------------------------------------
jiuk 4:3426b2472f99 111 void boton()
jiuk 4:3426b2472f99 112 {
jiuk 5:f8ca9f670abe 113 if (pulsador == 0)
jiuk 4:3426b2472f99 114 {
jiuk 8:9c2dff610de9 115 //command.printf("Button pressed %b\n", _boton);
jiuk 5:f8ca9f670abe 116 _boton=!_boton;
jiuk 4:3426b2472f99 117 }
jiuk 4:3426b2472f99 118 }
jiuk 5:f8ca9f670abe 119
jiuk 2:484928b9a5b5 120 //--------------------------------------------------
jiuk 2:484928b9a5b5 121 //-------------------SPI------------------------
jiuk 2:484928b9a5b5 122 //--------------------------------------------------
jiuk 0:2dabb9782f24 123 void sendSPI(uint8_t d1, uint8_t d2)
jiuk 0:2dabb9782f24 124 {
jiuk 0:2dabb9782f24 125 deviceM.unlock();
jiuk 0:2dabb9782f24 126 ssel=0;
jiuk 0:2dabb9782f24 127 deviceM.write(d1);
jiuk 0:2dabb9782f24 128 deviceM.write(d2);
jiuk 0:2dabb9782f24 129 ssel=1;
jiuk 0:2dabb9782f24 130 deviceM.lock();
jiuk 2:484928b9a5b5 131 };
jiuk 2:484928b9a5b5 132
jiuk 0:2dabb9782f24 133
jiuk 2:484928b9a5b5 134 //--------------------------------------------------
jiuk 2:484928b9a5b5 135 //-------------------TEST------------------------
jiuk 2:484928b9a5b5 136 //--------------------------------------------------
jiuk 0:2dabb9782f24 137 void test() //test
jiuk 0:2dabb9782f24 138 {
jiuk 0:2dabb9782f24 139 sendSPI(0x09,0); //no decodificacion
jiuk 4:3426b2472f99 140 sendSPI(0x0A,0x9); //intensidad
jiuk 0:2dabb9782f24 141 sendSPI(0x0B,0x07); //usa 7 leds
jiuk 0:2dabb9782f24 142 sendSPI(0x0C,1); //no apaga
jiuk 0:2dabb9782f24 143 sendSPI(0x0F,0); //operacion normal
jiuk 0:2dabb9782f24 144 }
jiuk 0:2dabb9782f24 145
jiuk 2:484928b9a5b5 146
jiuk 2:484928b9a5b5 147 //--------------------------------------------------
jiuk 2:484928b9a5b5 148 //-------------------BORRAR------------------------
jiuk 2:484928b9a5b5 149 //--------------------------------------------------
jiuk 0:2dabb9782f24 150 void borrar() //borrar toda la matriz;
jiuk 0:2dabb9782f24 151 {
jiuk 0:2dabb9782f24 152 int i;
jiuk 0:2dabb9782f24 153 for(i=0;i<=8;i++)
jiuk 0:2dabb9782f24 154 {
jiuk 0:2dabb9782f24 155 sendSPI(i,0);
jiuk 0:2dabb9782f24 156 }
jiuk 0:2dabb9782f24 157 }
jiuk 0:2dabb9782f24 158
jiuk 2:484928b9a5b5 159
jiuk 2:484928b9a5b5 160 //--------------------------------------------------
jiuk 2:484928b9a5b5 161 //-------------------GENERAR_PUNTO------------------------
jiuk 2:484928b9a5b5 162 //--------------------------------------------------
jiuk 0:2dabb9782f24 163 void generar_punto()
jiuk 0:2dabb9782f24 164 {
jiuk 2:484928b9a5b5 165 int col[8]={1,2,4,8,16,32,64,128};
jiuk 0:2dabb9782f24 166 //int fil=0;
jiuk 0:2dabb9782f24 167 borrar();
jiuk 2:484928b9a5b5 168 int _fil=fil;
jiuk 2:484928b9a5b5 169 fil= rand() % 7+1;
jiuk 0:2dabb9782f24 170 int y= rand() % 7+1;
jiuk 8:9c2dff610de9 171 //command.printf("\n\n Fila: %d",fil);
jiuk 8:9c2dff610de9 172 //command.printf("\n Columna:%d",col[y]);
jiuk 0:2dabb9782f24 173 //int time=0;
jiuk 0:2dabb9782f24 174 //while(time<4)
jiuk 0:2dabb9782f24 175 // {
jiuk 2:484928b9a5b5 176 if(_fil==fil)
jiuk 2:484928b9a5b5 177 colum=colum+col[y];
jiuk 2:484928b9a5b5 178 colum=col[y];
jiuk 0:2dabb9782f24 179 if(fil==fila){
jiuk 0:2dabb9782f24 180 int guarda_linea=columna+colum;
jiuk 0:2dabb9782f24 181 sendSPI(fila,guarda_linea);
jiuk 0:2dabb9782f24 182 }
jiuk 0:2dabb9782f24 183 else
jiuk 0:2dabb9782f24 184 sendSPI(fil,col[y]);
jiuk 2:484928b9a5b5 185
jiuk 0:2dabb9782f24 186 // wait_ms(VEL);
jiuk 0:2dabb9782f24 187 // sendSPI(fil,0);
jiuk 0:2dabb9782f24 188 // wait_ms(VEL);
jiuk 0:2dabb9782f24 189 // time++;
jiuk 0:2dabb9782f24 190 // }
jiuk 0:2dabb9782f24 191
jiuk 0:2dabb9782f24 192 }
jiuk 0:2dabb9782f24 193
jiuk 2:484928b9a5b5 194 //--------------------------------------------------
jiuk 2:484928b9a5b5 195 //-------------------BLINK------------------------
jiuk 2:484928b9a5b5 196 //--------------------------------------------------
jiuk 2:484928b9a5b5 197 void blink(){
jiuk 2:484928b9a5b5 198 sendSPI(fil,0);
jiuk 2:484928b9a5b5 199 if(fil==fila)
jiuk 2:484928b9a5b5 200 sendSPI(fila,columna);
jiuk 5:f8ca9f670abe 201 wait(0.05);
jiuk 2:484928b9a5b5 202 }
jiuk 2:484928b9a5b5 203
jiuk 2:484928b9a5b5 204 //--------------------------------------------------
jiuk 2:484928b9a5b5 205 //-------------------REVISAR_MOV------------------------
jiuk 2:484928b9a5b5 206 //--------------------------------------------------
jiuk 0:2dabb9782f24 207 void revisar_mov(uint8_t correr){
jiuk 0:2dabb9782f24 208 switch (correr){
jiuk 3:81dc55b0a8d7 209
jiuk 3:81dc55b0a8d7 210 case 2:
jiuk 3:81dc55b0a8d7 211 columna=columna<<1;
jiuk 3:81dc55b0a8d7 212 fila--;
jiuk 3:81dc55b0a8d7 213 if (columna>MINC)
jiuk 3:81dc55b0a8d7 214 columna=MAXC;
jiuk 3:81dc55b0a8d7 215 if (fila<MIN){
jiuk 3:81dc55b0a8d7 216 fila=MAX;
jiuk 3:81dc55b0a8d7 217 sendSPI(MIN,0);
jiuk 3:81dc55b0a8d7 218 }
jiuk 3:81dc55b0a8d7 219 sendSPI(fila+1,0);
jiuk 3:81dc55b0a8d7 220 break;
jiuk 3:81dc55b0a8d7 221
jiuk 3:81dc55b0a8d7 222 case 4:
jiuk 3:81dc55b0a8d7 223 columna=columna<<1;
jiuk 3:81dc55b0a8d7 224 fila++;
jiuk 3:81dc55b0a8d7 225 if (fila>MAX){
jiuk 3:81dc55b0a8d7 226 fila=MIN;
jiuk 3:81dc55b0a8d7 227 sendSPI(MAX,0);
jiuk 3:81dc55b0a8d7 228 }
jiuk 3:81dc55b0a8d7 229 if (columna>MINC)
jiuk 3:81dc55b0a8d7 230 columna=MAXC;
jiuk 3:81dc55b0a8d7 231 sendSPI(fila-1,0);
jiuk 3:81dc55b0a8d7 232 break;
jiuk 3:81dc55b0a8d7 233
jiuk 3:81dc55b0a8d7 234 case 1:
jiuk 3:81dc55b0a8d7 235 columna=columna>>1;
jiuk 3:81dc55b0a8d7 236 fila--;
jiuk 3:81dc55b0a8d7 237 if (columna<MAXC)
jiuk 3:81dc55b0a8d7 238 columna=MINC;
jiuk 3:81dc55b0a8d7 239 if (fila<MIN){
jiuk 3:81dc55b0a8d7 240 fila=MAX;
jiuk 3:81dc55b0a8d7 241 sendSPI(MIN,0);
jiuk 3:81dc55b0a8d7 242 }
jiuk 3:81dc55b0a8d7 243 sendSPI(fila+1,0);
jiuk 3:81dc55b0a8d7 244 //command.printf("\n case1 Col:%d",columna);
jiuk 3:81dc55b0a8d7 245 //command.printf("\n FIL:%d",fila);
jiuk 3:81dc55b0a8d7 246 break;
jiuk 3:81dc55b0a8d7 247
jiuk 3:81dc55b0a8d7 248 case 3:
jiuk 3:81dc55b0a8d7 249 columna=columna>>1;
jiuk 3:81dc55b0a8d7 250 fila++;
jiuk 3:81dc55b0a8d7 251 if (columna<MAXC)
jiuk 3:81dc55b0a8d7 252 columna=MINC;
jiuk 3:81dc55b0a8d7 253 if (fila>MAX){
jiuk 3:81dc55b0a8d7 254 fila=MIN;
jiuk 3:81dc55b0a8d7 255 sendSPI(MAX,0);
jiuk 3:81dc55b0a8d7 256 }
jiuk 3:81dc55b0a8d7 257 sendSPI(fila-1,0);
jiuk 3:81dc55b0a8d7 258 //command.printf("\n case3 Col:%d",columna);
jiuk 3:81dc55b0a8d7 259 //command.printf("\n FIL:%d",fila);
jiuk 3:81dc55b0a8d7 260 break;
jiuk 3:81dc55b0a8d7 261
jiuk 0:2dabb9782f24 262 case 28:
jiuk 0:2dabb9782f24 263 columna=columna<<1;
jiuk 0:2dabb9782f24 264 if (columna>MINC)
jiuk 0:2dabb9782f24 265 columna=MAXC;
jiuk 0:2dabb9782f24 266 break;
jiuk 0:2dabb9782f24 267
jiuk 0:2dabb9782f24 268 case 29:
jiuk 0:2dabb9782f24 269 columna=columna>>1;
jiuk 0:2dabb9782f24 270 if (columna<MAXC)
jiuk 0:2dabb9782f24 271 columna=MINC;
jiuk 0:2dabb9782f24 272 break;
jiuk 0:2dabb9782f24 273
jiuk 0:2dabb9782f24 274 case 30:
jiuk 0:2dabb9782f24 275 fila--;
jiuk 3:81dc55b0a8d7 276 if (fila<MIN){
jiuk 3:81dc55b0a8d7 277 fila=MAX;
jiuk 3:81dc55b0a8d7 278 sendSPI(MIN,0);
jiuk 3:81dc55b0a8d7 279 }
jiuk 0:2dabb9782f24 280 sendSPI(fila+1,0);
jiuk 0:2dabb9782f24 281 break;
jiuk 0:2dabb9782f24 282
jiuk 0:2dabb9782f24 283 case 31:
jiuk 0:2dabb9782f24 284 fila++;
jiuk 3:81dc55b0a8d7 285 if (fila>MAX){
jiuk 3:81dc55b0a8d7 286 fila=MIN;
jiuk 3:81dc55b0a8d7 287 sendSPI(MAX,0);
jiuk 3:81dc55b0a8d7 288 }
jiuk 0:2dabb9782f24 289 sendSPI(fila-1,0);
jiuk 0:2dabb9782f24 290 break;
jiuk 1:efcead3fb5eb 291
jiuk 1:efcead3fb5eb 292 case 0:
jiuk 1:efcead3fb5eb 293 break;
jiuk 0:2dabb9782f24 294 }
jiuk 0:2dabb9782f24 295 }
jiuk 2:484928b9a5b5 296
jiuk 3:81dc55b0a8d7 297 //--------------------------------------------------
jiuk 3:81dc55b0a8d7 298 //-------------------VELOCIDAD-----------------------
jiuk 3:81dc55b0a8d7 299 //--------------------------------------------------
jiuk 3:81dc55b0a8d7 300 int velocidad(float _acc[3])
jiuk 3:81dc55b0a8d7 301 {
jiuk 5:f8ca9f670abe 302 int vel,x=1,y=2; //
jiuk 3:81dc55b0a8d7 303 int acc[3];
jiuk 4:3426b2472f99 304 acc[0]=(int)_acc[0];
jiuk 4:3426b2472f99 305 acc[1]=(int)_acc[1];
jiuk 3:81dc55b0a8d7 306 if((acc[0]>GIRO) || (acc[0]<-GIRO) || (acc[1]>GIRO) || (acc[1]<-GIRO))
jiuk 3:81dc55b0a8d7 307 {
jiuk 4:3426b2472f99 308 if((acc[0]>(GIRO+x)) || (acc[0]<-(GIRO+x)) || (acc[1]>(GIRO+x)) || (acc[1]<-(GIRO+x)))
jiuk 4:3426b2472f99 309 {
jiuk 8:9c2dff610de9 310 vel=200;
jiuk 4:3426b2472f99 311 if((acc[0]>(GIRO+y)) || (acc[0]<-(GIRO+y)) || (acc[1]>(GIRO+y)) || (acc[1]<-(GIRO+y)))
jiuk 4:3426b2472f99 312 vel=100;
jiuk 4:3426b2472f99 313 }
jiuk 4:3426b2472f99 314 else
jiuk 8:9c2dff610de9 315 vel=300;
jiuk 3:81dc55b0a8d7 316 }
jiuk 3:81dc55b0a8d7 317 return vel;
jiuk 3:81dc55b0a8d7 318 }
jiuk 2:484928b9a5b5 319
jiuk 2:484928b9a5b5 320 //--------------------------------------------------
jiuk 2:484928b9a5b5 321 //-------------------BUSCADOR------------------------
jiuk 2:484928b9a5b5 322 //--------------------------------------------------
jiuk 0:2dabb9782f24 323 void buscador()
jiuk 0:2dabb9782f24 324 {
jiuk 0:2dabb9782f24 325 uint8_t correr;
jiuk 4:3426b2472f99 326 int y=0,x=0,acc[3],v;
jiuk 0:2dabb9782f24 327 //float gyro[3]; Wire.getGyro(gyro);
jiuk 4:3426b2472f99 328 float _acc[3];
jiuk 4:3426b2472f99 329 //command.printf("Accelerometer: \t X= %f, \t Y= %f, \t Z=%f \n", acc[0],acc[1],acc[2]);
jiuk 4:3426b2472f99 330 //command.printf("Gyroscope: \t X= %f, \t Y= %f, \t Z=%f \n", gyro[0],gyro[1],gyro[2]);
jiuk 5:f8ca9f670abe 331 if(_boton==1)
jiuk 4:3426b2472f99 332 {
jiuk 4:3426b2472f99 333 x=((int)(in1.read()*-650))+13;
jiuk 4:3426b2472f99 334 y=((int)(in2.read()*-650))+13;
jiuk 4:3426b2472f99 335 acc[0]=x;
jiuk 4:3426b2472f99 336 acc[1]=y;
jiuk 6:4c9e8118c303 337 //command.printf("Joystick: \t X= %d, \t Y= %d, \n", x,y);
jiuk 4:3426b2472f99 338 }
jiuk 4:3426b2472f99 339 else
jiuk 4:3426b2472f99 340 {
jiuk 4:3426b2472f99 341 Wire.getAccelero(_acc);
jiuk 4:3426b2472f99 342 acc[0]=(int)_acc[0];
jiuk 4:3426b2472f99 343 acc[1]=(int)_acc[1];
jiuk 6:4c9e8118c303 344 //command.printf("Accelerometer: \t X= %d, \t Y= %d, \n", acc[0],acc[1]);
jiuk 4:3426b2472f99 345 }
jiuk 4:3426b2472f99 346
jiuk 6:4c9e8118c303 347 //command.printf("Velocidad %d \n", v);
jiuk 3:81dc55b0a8d7 348 if(acc[0]>GIRO) //eje x derecha
jiuk 3:81dc55b0a8d7 349 {
jiuk 3:81dc55b0a8d7 350 if(acc[1]>G_DIAG) //eje y arriba
jiuk 3:81dc55b0a8d7 351 correr=1;
jiuk 3:81dc55b0a8d7 352 else if(acc[1]<-G_DIAG)//eje y abajo
jiuk 3:81dc55b0a8d7 353 correr=2;
jiuk 3:81dc55b0a8d7 354 else
jiuk 3:81dc55b0a8d7 355 correr=30;
jiuk 3:81dc55b0a8d7 356 }
jiuk 3:81dc55b0a8d7 357 else if(acc[0]<-GIRO) //eje x izquierda
jiuk 3:81dc55b0a8d7 358 {
jiuk 3:81dc55b0a8d7 359 if(acc[1]>G_DIAG) //eje y arriba
jiuk 3:81dc55b0a8d7 360 correr=3;
jiuk 3:81dc55b0a8d7 361 else if(acc[1]<-G_DIAG)//eje y abajo
jiuk 3:81dc55b0a8d7 362 correr=4;
jiuk 3:81dc55b0a8d7 363 else
jiuk 3:81dc55b0a8d7 364 correr=31;
jiuk 3:81dc55b0a8d7 365 }
jiuk 3:81dc55b0a8d7 366 else if(acc[1]>GIRO) //eje y arriba
jiuk 3:81dc55b0a8d7 367 correr=29;
jiuk 3:81dc55b0a8d7 368 else if(acc[1]<-GIRO) //eje y abajo
jiuk 3:81dc55b0a8d7 369 correr=28;
jiuk 3:81dc55b0a8d7 370 else
jiuk 3:81dc55b0a8d7 371 correr=0; //
jiuk 4:3426b2472f99 372 revisar_mov(correr);
jiuk 4:3426b2472f99 373 v=velocidad(_acc);
jiuk 4:3426b2472f99 374 wait_ms(v);
jiuk 0:2dabb9782f24 375 //wait (DEL);
jiuk 2:484928b9a5b5 376 //command.printf("\n correr:\n %d",correr);
jiuk 0:2dabb9782f24 377 }
jiuk 0:2dabb9782f24 378
jiuk 2:484928b9a5b5 379
jiuk 2:484928b9a5b5 380 //--------------------------------------------------
jiuk 2:484928b9a5b5 381 //-------------------COMER------------------------
jiuk 2:484928b9a5b5 382 //--------------------------------------------------
jiuk 0:2dabb9782f24 383 int comer ()
jiuk 0:2dabb9782f24 384 {
jiuk 0:2dabb9782f24 385 int x=0;
jiuk 2:484928b9a5b5 386 if((fil==fila)&&((colum & columna) != 0))
jiuk 2:484928b9a5b5 387 {
jiuk 2:484928b9a5b5 388 manzanas++;
jiuk 2:484928b9a5b5 389 sendSPI(fila,columna);
jiuk 6:4c9e8118c303 390 int guarda_linea=columna+colum;
jiuk 6:4c9e8118c303 391 sendSPI(fila,guarda_linea);
jiuk 6:4c9e8118c303 392 generar_punto();
jiuk 6:4c9e8118c303 393 sendSPI(fil,colum);
jiuk 6:4c9e8118c303 394 if(manzanas==4)
jiuk 2:484928b9a5b5 395 {
jiuk 6:4c9e8118c303 396 com_tar.putc(1);
jiuk 8:9c2dff610de9 397 //command.printf("Enviado");
jiuk 7:5f1c8385cf8e 398 cara_feliz();
jiuk 2:484928b9a5b5 399 }
jiuk 0:2dabb9782f24 400 x=1;
jiuk 2:484928b9a5b5 401 }
jiuk 0:2dabb9782f24 402 return x;
jiuk 2:484928b9a5b5 403 }
jiuk 2:484928b9a5b5 404
jiuk 0:2dabb9782f24 405
jiuk 2:484928b9a5b5 406 //--------------------------------------------------
jiuk 2:484928b9a5b5 407 //-------------------VALIDAR_CONTRINCANTE------------------------
jiuk 2:484928b9a5b5 408 //--------------------------------------------------
jiuk 0:2dabb9782f24 409 int validar_contrincante(){
jiuk 0:2dabb9782f24 410 int x=com_tar.getc();
jiuk 0:2dabb9782f24 411 return x;
jiuk 0:2dabb9782f24 412 }
jiuk 0:2dabb9782f24 413
jiuk 4:3426b2472f99 414
jiuk 4:3426b2472f99 415 //--------------------------------------------------
jiuk 4:3426b2472f99 416 //-------------------MAIN------------------------
jiuk 4:3426b2472f99 417 //--------------------------------------------------
jiuk 0:2dabb9782f24 418 int main ()
jiuk 0:2dabb9782f24 419 {
jiuk 0:2dabb9782f24 420 int guarda_linea,x=0;
jiuk 5:f8ca9f670abe 421 timer.attach(&attime, 0.1);
jiuk 0:2dabb9782f24 422 test();
jiuk 0:2dabb9782f24 423 borrar();
jiuk 0:2dabb9782f24 424 sendSPI(fila,columna);
jiuk 0:2dabb9782f24 425 generar_punto();
jiuk 0:2dabb9782f24 426 while(1)
jiuk 0:2dabb9782f24 427 {
jiuk 0:2dabb9782f24 428 buscador();
jiuk 0:2dabb9782f24 429 //validar_contrincante();
jiuk 0:2dabb9782f24 430 x=comer();
jiuk 2:484928b9a5b5 431 //command.printf("\n comer:\n %d",x);
jiuk 0:2dabb9782f24 432 if (x==0)
jiuk 0:2dabb9782f24 433 {
jiuk 0:2dabb9782f24 434 if(fil==fila){
jiuk 0:2dabb9782f24 435 guarda_linea=columna+colum;
jiuk 0:2dabb9782f24 436 sendSPI(fila,guarda_linea);
jiuk 0:2dabb9782f24 437 }
jiuk 0:2dabb9782f24 438 else
jiuk 0:2dabb9782f24 439 {
jiuk 0:2dabb9782f24 440 guarda_linea=columna;
jiuk 0:2dabb9782f24 441 sendSPI(fila,guarda_linea);
jiuk 0:2dabb9782f24 442 sendSPI(fil,colum);
jiuk 0:2dabb9782f24 443 }
jiuk 0:2dabb9782f24 444 }
jiuk 0:2dabb9782f24 445 else{
jiuk 0:2dabb9782f24 446 sendSPI(fila,columna);
jiuk 0:2dabb9782f24 447 }
jiuk 0:2dabb9782f24 448 //generar_punto();
jiuk 0:2dabb9782f24 449 }
jiuk 0:2dabb9782f24 450 }