falta verificar cambio de joystick a accel

Dependencies:   mbed MPU6050

Committer:
jiuk
Date:
Thu Nov 22 09:00:51 2018 +0000
Revision:
5:f8ca9f670abe
Parent:
4:3426b2472f99
Child:
6:4c9e8118c303
Codigo con joystick y acelerometro

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 0:2dabb9782f24 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.
jiuk 0:2dabb9782f24 15 Serial com_tar(PC_10,PC_11); //master f446R
jiuk 0:2dabb9782f24 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 0:2dabb9782f24 36
jiuk 2:484928b9a5b5 37 //--------------------------------------------------
jiuk 2:484928b9a5b5 38 //-------------------TICKER------------------------
jiuk 2:484928b9a5b5 39 //--------------------------------------------------
jiuk 5:f8ca9f670abe 40 void attime()
jiuk 5:f8ca9f670abe 41 {
jiuk 2:484928b9a5b5 42 blink();
jiuk 5:f8ca9f670abe 43 boton();
jiuk 5:f8ca9f670abe 44 };
jiuk 4:3426b2472f99 45
jiuk 4:3426b2472f99 46 //--------------------------------------------------
jiuk 4:3426b2472f99 47 //-------------------BOTON------------------------
jiuk 4:3426b2472f99 48 //--------------------------------------------------
jiuk 4:3426b2472f99 49 void boton()
jiuk 4:3426b2472f99 50 {
jiuk 5:f8ca9f670abe 51 if (pulsador == 0)
jiuk 4:3426b2472f99 52 {
jiuk 5:f8ca9f670abe 53 command.printf("Button pressed %b\n", _boton);
jiuk 5:f8ca9f670abe 54 _boton=!_boton;
jiuk 4:3426b2472f99 55 }
jiuk 4:3426b2472f99 56 }
jiuk 5:f8ca9f670abe 57
jiuk 2:484928b9a5b5 58 //--------------------------------------------------
jiuk 2:484928b9a5b5 59 //-------------------SPI------------------------
jiuk 2:484928b9a5b5 60 //--------------------------------------------------
jiuk 0:2dabb9782f24 61 void sendSPI(uint8_t d1, uint8_t d2)
jiuk 0:2dabb9782f24 62 {
jiuk 0:2dabb9782f24 63 deviceM.unlock();
jiuk 0:2dabb9782f24 64 ssel=0;
jiuk 0:2dabb9782f24 65 deviceM.write(d1);
jiuk 0:2dabb9782f24 66 deviceM.write(d2);
jiuk 0:2dabb9782f24 67 ssel=1;
jiuk 0:2dabb9782f24 68 deviceM.lock();
jiuk 2:484928b9a5b5 69 };
jiuk 2:484928b9a5b5 70
jiuk 0:2dabb9782f24 71
jiuk 2:484928b9a5b5 72 //--------------------------------------------------
jiuk 2:484928b9a5b5 73 //-------------------TEST------------------------
jiuk 2:484928b9a5b5 74 //--------------------------------------------------
jiuk 0:2dabb9782f24 75 void test() //test
jiuk 0:2dabb9782f24 76 {
jiuk 0:2dabb9782f24 77 sendSPI(0x09,0); //no decodificacion
jiuk 4:3426b2472f99 78 sendSPI(0x0A,0x9); //intensidad
jiuk 0:2dabb9782f24 79 sendSPI(0x0B,0x07); //usa 7 leds
jiuk 0:2dabb9782f24 80 sendSPI(0x0C,1); //no apaga
jiuk 0:2dabb9782f24 81 sendSPI(0x0F,0); //operacion normal
jiuk 0:2dabb9782f24 82 }
jiuk 0:2dabb9782f24 83
jiuk 2:484928b9a5b5 84
jiuk 2:484928b9a5b5 85 //--------------------------------------------------
jiuk 2:484928b9a5b5 86 //-------------------BORRAR------------------------
jiuk 2:484928b9a5b5 87 //--------------------------------------------------
jiuk 0:2dabb9782f24 88 void borrar() //borrar toda la matriz;
jiuk 0:2dabb9782f24 89 {
jiuk 0:2dabb9782f24 90 int i;
jiuk 0:2dabb9782f24 91 for(i=0;i<=8;i++)
jiuk 0:2dabb9782f24 92 {
jiuk 0:2dabb9782f24 93 sendSPI(i,0);
jiuk 0:2dabb9782f24 94 }
jiuk 0:2dabb9782f24 95 }
jiuk 0:2dabb9782f24 96
jiuk 2:484928b9a5b5 97
jiuk 2:484928b9a5b5 98 //--------------------------------------------------
jiuk 2:484928b9a5b5 99 //-------------------GENERAR_PUNTO------------------------
jiuk 2:484928b9a5b5 100 //--------------------------------------------------
jiuk 0:2dabb9782f24 101 void generar_punto()
jiuk 0:2dabb9782f24 102 {
jiuk 2:484928b9a5b5 103 int col[8]={1,2,4,8,16,32,64,128};
jiuk 0:2dabb9782f24 104 //int fil=0;
jiuk 0:2dabb9782f24 105 borrar();
jiuk 2:484928b9a5b5 106 int _fil=fil;
jiuk 2:484928b9a5b5 107 fil= rand() % 7+1;
jiuk 0:2dabb9782f24 108 int y= rand() % 7+1;
jiuk 0:2dabb9782f24 109 command.printf("\n\n Fila: %d",fil);
jiuk 0:2dabb9782f24 110 command.printf("\n Columna:%d",col[y]);
jiuk 0:2dabb9782f24 111 //int time=0;
jiuk 0:2dabb9782f24 112 //while(time<4)
jiuk 0:2dabb9782f24 113 // {
jiuk 2:484928b9a5b5 114 if(_fil==fil)
jiuk 2:484928b9a5b5 115 colum=colum+col[y];
jiuk 2:484928b9a5b5 116 colum=col[y];
jiuk 0:2dabb9782f24 117 if(fil==fila){
jiuk 0:2dabb9782f24 118 int guarda_linea=columna+colum;
jiuk 0:2dabb9782f24 119 sendSPI(fila,guarda_linea);
jiuk 0:2dabb9782f24 120 }
jiuk 0:2dabb9782f24 121 else
jiuk 0:2dabb9782f24 122 sendSPI(fil,col[y]);
jiuk 2:484928b9a5b5 123
jiuk 0:2dabb9782f24 124 // wait_ms(VEL);
jiuk 0:2dabb9782f24 125 // sendSPI(fil,0);
jiuk 0:2dabb9782f24 126 // wait_ms(VEL);
jiuk 0:2dabb9782f24 127 // time++;
jiuk 0:2dabb9782f24 128 // }
jiuk 0:2dabb9782f24 129
jiuk 0:2dabb9782f24 130 }
jiuk 0:2dabb9782f24 131
jiuk 2:484928b9a5b5 132 //--------------------------------------------------
jiuk 2:484928b9a5b5 133 //-------------------BLINK------------------------
jiuk 2:484928b9a5b5 134 //--------------------------------------------------
jiuk 2:484928b9a5b5 135 void blink(){
jiuk 2:484928b9a5b5 136 sendSPI(fil,0);
jiuk 2:484928b9a5b5 137 if(fil==fila)
jiuk 2:484928b9a5b5 138 sendSPI(fila,columna);
jiuk 5:f8ca9f670abe 139 wait(0.05);
jiuk 2:484928b9a5b5 140 }
jiuk 2:484928b9a5b5 141
jiuk 2:484928b9a5b5 142 //--------------------------------------------------
jiuk 2:484928b9a5b5 143 //-------------------REVISAR_MOV------------------------
jiuk 2:484928b9a5b5 144 //--------------------------------------------------
jiuk 0:2dabb9782f24 145 void revisar_mov(uint8_t correr){
jiuk 0:2dabb9782f24 146 switch (correr){
jiuk 3:81dc55b0a8d7 147
jiuk 3:81dc55b0a8d7 148 case 2:
jiuk 3:81dc55b0a8d7 149 columna=columna<<1;
jiuk 3:81dc55b0a8d7 150 fila--;
jiuk 3:81dc55b0a8d7 151 if (columna>MINC)
jiuk 3:81dc55b0a8d7 152 columna=MAXC;
jiuk 3:81dc55b0a8d7 153 if (fila<MIN){
jiuk 3:81dc55b0a8d7 154 fila=MAX;
jiuk 3:81dc55b0a8d7 155 sendSPI(MIN,0);
jiuk 3:81dc55b0a8d7 156 }
jiuk 3:81dc55b0a8d7 157 sendSPI(fila+1,0);
jiuk 3:81dc55b0a8d7 158 break;
jiuk 3:81dc55b0a8d7 159
jiuk 3:81dc55b0a8d7 160 case 4:
jiuk 3:81dc55b0a8d7 161 columna=columna<<1;
jiuk 3:81dc55b0a8d7 162 fila++;
jiuk 3:81dc55b0a8d7 163 if (fila>MAX){
jiuk 3:81dc55b0a8d7 164 fila=MIN;
jiuk 3:81dc55b0a8d7 165 sendSPI(MAX,0);
jiuk 3:81dc55b0a8d7 166 }
jiuk 3:81dc55b0a8d7 167 if (columna>MINC)
jiuk 3:81dc55b0a8d7 168 columna=MAXC;
jiuk 3:81dc55b0a8d7 169 sendSPI(fila-1,0);
jiuk 3:81dc55b0a8d7 170 break;
jiuk 3:81dc55b0a8d7 171
jiuk 3:81dc55b0a8d7 172 case 1:
jiuk 3:81dc55b0a8d7 173 columna=columna>>1;
jiuk 3:81dc55b0a8d7 174 fila--;
jiuk 3:81dc55b0a8d7 175 if (columna<MAXC)
jiuk 3:81dc55b0a8d7 176 columna=MINC;
jiuk 3:81dc55b0a8d7 177 if (fila<MIN){
jiuk 3:81dc55b0a8d7 178 fila=MAX;
jiuk 3:81dc55b0a8d7 179 sendSPI(MIN,0);
jiuk 3:81dc55b0a8d7 180 }
jiuk 3:81dc55b0a8d7 181 sendSPI(fila+1,0);
jiuk 3:81dc55b0a8d7 182 //command.printf("\n case1 Col:%d",columna);
jiuk 3:81dc55b0a8d7 183 //command.printf("\n FIL:%d",fila);
jiuk 3:81dc55b0a8d7 184 break;
jiuk 3:81dc55b0a8d7 185
jiuk 3:81dc55b0a8d7 186 case 3:
jiuk 3:81dc55b0a8d7 187 columna=columna>>1;
jiuk 3:81dc55b0a8d7 188 fila++;
jiuk 3:81dc55b0a8d7 189 if (columna<MAXC)
jiuk 3:81dc55b0a8d7 190 columna=MINC;
jiuk 3:81dc55b0a8d7 191 if (fila>MAX){
jiuk 3:81dc55b0a8d7 192 fila=MIN;
jiuk 3:81dc55b0a8d7 193 sendSPI(MAX,0);
jiuk 3:81dc55b0a8d7 194 }
jiuk 3:81dc55b0a8d7 195 sendSPI(fila-1,0);
jiuk 3:81dc55b0a8d7 196 //command.printf("\n case3 Col:%d",columna);
jiuk 3:81dc55b0a8d7 197 //command.printf("\n FIL:%d",fila);
jiuk 3:81dc55b0a8d7 198 break;
jiuk 3:81dc55b0a8d7 199
jiuk 0:2dabb9782f24 200 case 28:
jiuk 0:2dabb9782f24 201 columna=columna<<1;
jiuk 0:2dabb9782f24 202 if (columna>MINC)
jiuk 0:2dabb9782f24 203 columna=MAXC;
jiuk 0:2dabb9782f24 204 break;
jiuk 0:2dabb9782f24 205
jiuk 0:2dabb9782f24 206 case 29:
jiuk 0:2dabb9782f24 207 columna=columna>>1;
jiuk 0:2dabb9782f24 208 if (columna<MAXC)
jiuk 0:2dabb9782f24 209 columna=MINC;
jiuk 0:2dabb9782f24 210 break;
jiuk 0:2dabb9782f24 211
jiuk 0:2dabb9782f24 212 case 30:
jiuk 0:2dabb9782f24 213 fila--;
jiuk 3:81dc55b0a8d7 214 if (fila<MIN){
jiuk 3:81dc55b0a8d7 215 fila=MAX;
jiuk 3:81dc55b0a8d7 216 sendSPI(MIN,0);
jiuk 3:81dc55b0a8d7 217 }
jiuk 0:2dabb9782f24 218 sendSPI(fila+1,0);
jiuk 0:2dabb9782f24 219 break;
jiuk 0:2dabb9782f24 220
jiuk 0:2dabb9782f24 221 case 31:
jiuk 0:2dabb9782f24 222 fila++;
jiuk 3:81dc55b0a8d7 223 if (fila>MAX){
jiuk 3:81dc55b0a8d7 224 fila=MIN;
jiuk 3:81dc55b0a8d7 225 sendSPI(MAX,0);
jiuk 3:81dc55b0a8d7 226 }
jiuk 0:2dabb9782f24 227 sendSPI(fila-1,0);
jiuk 0:2dabb9782f24 228 break;
jiuk 1:efcead3fb5eb 229
jiuk 1:efcead3fb5eb 230 case 0:
jiuk 1:efcead3fb5eb 231 break;
jiuk 0:2dabb9782f24 232 }
jiuk 0:2dabb9782f24 233 }
jiuk 2:484928b9a5b5 234
jiuk 3:81dc55b0a8d7 235 //--------------------------------------------------
jiuk 3:81dc55b0a8d7 236 //-------------------VELOCIDAD-----------------------
jiuk 3:81dc55b0a8d7 237 //--------------------------------------------------
jiuk 3:81dc55b0a8d7 238 int velocidad(float _acc[3])
jiuk 3:81dc55b0a8d7 239 {
jiuk 5:f8ca9f670abe 240 int vel,x=1,y=2; //
jiuk 3:81dc55b0a8d7 241 int acc[3];
jiuk 4:3426b2472f99 242 acc[0]=(int)_acc[0];
jiuk 4:3426b2472f99 243 acc[1]=(int)_acc[1];
jiuk 3:81dc55b0a8d7 244 if((acc[0]>GIRO) || (acc[0]<-GIRO) || (acc[1]>GIRO) || (acc[1]<-GIRO))
jiuk 3:81dc55b0a8d7 245 {
jiuk 4:3426b2472f99 246 if((acc[0]>(GIRO+x)) || (acc[0]<-(GIRO+x)) || (acc[1]>(GIRO+x)) || (acc[1]<-(GIRO+x)))
jiuk 4:3426b2472f99 247 {
jiuk 4:3426b2472f99 248 vel=300;
jiuk 4:3426b2472f99 249 if((acc[0]>(GIRO+y)) || (acc[0]<-(GIRO+y)) || (acc[1]>(GIRO+y)) || (acc[1]<-(GIRO+y)))
jiuk 4:3426b2472f99 250 vel=100;
jiuk 4:3426b2472f99 251 }
jiuk 4:3426b2472f99 252 else
jiuk 4:3426b2472f99 253 vel=500;
jiuk 3:81dc55b0a8d7 254 }
jiuk 3:81dc55b0a8d7 255 return vel;
jiuk 3:81dc55b0a8d7 256 }
jiuk 2:484928b9a5b5 257
jiuk 2:484928b9a5b5 258 //--------------------------------------------------
jiuk 2:484928b9a5b5 259 //-------------------BUSCADOR------------------------
jiuk 2:484928b9a5b5 260 //--------------------------------------------------
jiuk 0:2dabb9782f24 261 void buscador()
jiuk 0:2dabb9782f24 262 {
jiuk 0:2dabb9782f24 263 uint8_t correr;
jiuk 4:3426b2472f99 264 int y=0,x=0,acc[3],v;
jiuk 0:2dabb9782f24 265 //float gyro[3]; Wire.getGyro(gyro);
jiuk 4:3426b2472f99 266 float _acc[3];
jiuk 4:3426b2472f99 267 //command.printf("Accelerometer: \t X= %f, \t Y= %f, \t Z=%f \n", acc[0],acc[1],acc[2]);
jiuk 4:3426b2472f99 268 //command.printf("Gyroscope: \t X= %f, \t Y= %f, \t Z=%f \n", gyro[0],gyro[1],gyro[2]);
jiuk 5:f8ca9f670abe 269 if(_boton==1)
jiuk 4:3426b2472f99 270 {
jiuk 4:3426b2472f99 271 x=((int)(in1.read()*-650))+13;
jiuk 4:3426b2472f99 272 y=((int)(in2.read()*-650))+13;
jiuk 4:3426b2472f99 273 acc[0]=x;
jiuk 4:3426b2472f99 274 acc[1]=y;
jiuk 4:3426b2472f99 275 command.printf("Joystick: \t X= %d, \t Y= %d, \n", x,y);
jiuk 4:3426b2472f99 276 }
jiuk 4:3426b2472f99 277 else
jiuk 4:3426b2472f99 278 {
jiuk 4:3426b2472f99 279 Wire.getAccelero(_acc);
jiuk 4:3426b2472f99 280 acc[0]=(int)_acc[0];
jiuk 4:3426b2472f99 281 acc[1]=(int)_acc[1];
jiuk 4:3426b2472f99 282 command.printf("Accelerometer: \t X= %d, \t Y= %d, \n", acc[0],acc[1]);
jiuk 4:3426b2472f99 283 }
jiuk 4:3426b2472f99 284
jiuk 4:3426b2472f99 285 command.printf("Velocidad %d \n", v);
jiuk 3:81dc55b0a8d7 286 if(acc[0]>GIRO) //eje x derecha
jiuk 3:81dc55b0a8d7 287 {
jiuk 3:81dc55b0a8d7 288 if(acc[1]>G_DIAG) //eje y arriba
jiuk 3:81dc55b0a8d7 289 correr=1;
jiuk 3:81dc55b0a8d7 290 else if(acc[1]<-G_DIAG)//eje y abajo
jiuk 3:81dc55b0a8d7 291 correr=2;
jiuk 3:81dc55b0a8d7 292 else
jiuk 3:81dc55b0a8d7 293 correr=30;
jiuk 3:81dc55b0a8d7 294 }
jiuk 3:81dc55b0a8d7 295 else if(acc[0]<-GIRO) //eje x izquierda
jiuk 3:81dc55b0a8d7 296 {
jiuk 3:81dc55b0a8d7 297 if(acc[1]>G_DIAG) //eje y arriba
jiuk 3:81dc55b0a8d7 298 correr=3;
jiuk 3:81dc55b0a8d7 299 else if(acc[1]<-G_DIAG)//eje y abajo
jiuk 3:81dc55b0a8d7 300 correr=4;
jiuk 3:81dc55b0a8d7 301 else
jiuk 3:81dc55b0a8d7 302 correr=31;
jiuk 3:81dc55b0a8d7 303 }
jiuk 3:81dc55b0a8d7 304 else if(acc[1]>GIRO) //eje y arriba
jiuk 3:81dc55b0a8d7 305 correr=29;
jiuk 3:81dc55b0a8d7 306 else if(acc[1]<-GIRO) //eje y abajo
jiuk 3:81dc55b0a8d7 307 correr=28;
jiuk 3:81dc55b0a8d7 308 else
jiuk 3:81dc55b0a8d7 309 correr=0; //
jiuk 4:3426b2472f99 310 revisar_mov(correr);
jiuk 4:3426b2472f99 311 v=velocidad(_acc);
jiuk 4:3426b2472f99 312 wait_ms(v);
jiuk 0:2dabb9782f24 313 //wait (DEL);
jiuk 2:484928b9a5b5 314 //command.printf("\n correr:\n %d",correr);
jiuk 0:2dabb9782f24 315 }
jiuk 0:2dabb9782f24 316
jiuk 2:484928b9a5b5 317
jiuk 2:484928b9a5b5 318 //--------------------------------------------------
jiuk 2:484928b9a5b5 319 //-------------------COMER------------------------
jiuk 2:484928b9a5b5 320 //--------------------------------------------------
jiuk 0:2dabb9782f24 321 int comer ()
jiuk 0:2dabb9782f24 322 {
jiuk 0:2dabb9782f24 323 int x=0;
jiuk 2:484928b9a5b5 324 if((fil==fila)&&((colum & columna) != 0))
jiuk 2:484928b9a5b5 325 {
jiuk 2:484928b9a5b5 326 manzanas++;
jiuk 2:484928b9a5b5 327 sendSPI(fila,columna);
jiuk 2:484928b9a5b5 328 for(int i=0;i<manzanas;i++)
jiuk 2:484928b9a5b5 329 {
jiuk 2:484928b9a5b5 330 int guarda_linea=columna+colum;
jiuk 2:484928b9a5b5 331 sendSPI(fila,guarda_linea);
jiuk 2:484928b9a5b5 332 generar_punto();
jiuk 2:484928b9a5b5 333 sendSPI(fil,colum);
jiuk 2:484928b9a5b5 334 //com_tar.putc(x);
jiuk 2:484928b9a5b5 335 }
jiuk 0:2dabb9782f24 336 x=1;
jiuk 2:484928b9a5b5 337 }
jiuk 0:2dabb9782f24 338 return x;
jiuk 2:484928b9a5b5 339 }
jiuk 2:484928b9a5b5 340
jiuk 0:2dabb9782f24 341
jiuk 2:484928b9a5b5 342 //--------------------------------------------------
jiuk 2:484928b9a5b5 343 //-------------------VALIDAR_CONTRINCANTE------------------------
jiuk 2:484928b9a5b5 344 //--------------------------------------------------
jiuk 0:2dabb9782f24 345 int validar_contrincante(){
jiuk 0:2dabb9782f24 346 int x=com_tar.getc();
jiuk 0:2dabb9782f24 347 return x;
jiuk 0:2dabb9782f24 348 }
jiuk 0:2dabb9782f24 349
jiuk 4:3426b2472f99 350
jiuk 4:3426b2472f99 351 //--------------------------------------------------
jiuk 4:3426b2472f99 352 //-------------------MAIN------------------------
jiuk 4:3426b2472f99 353 //--------------------------------------------------
jiuk 0:2dabb9782f24 354 int main ()
jiuk 0:2dabb9782f24 355 {
jiuk 0:2dabb9782f24 356 int guarda_linea,x=0;
jiuk 5:f8ca9f670abe 357 timer.attach(&attime, 0.1);
jiuk 0:2dabb9782f24 358 test();
jiuk 0:2dabb9782f24 359 borrar();
jiuk 0:2dabb9782f24 360 sendSPI(fila,columna);
jiuk 0:2dabb9782f24 361 generar_punto();
jiuk 0:2dabb9782f24 362 while(1)
jiuk 0:2dabb9782f24 363 {
jiuk 0:2dabb9782f24 364 buscador();
jiuk 0:2dabb9782f24 365 //validar_contrincante();
jiuk 0:2dabb9782f24 366 x=comer();
jiuk 2:484928b9a5b5 367 //command.printf("\n comer:\n %d",x);
jiuk 0:2dabb9782f24 368 if (x==0)
jiuk 0:2dabb9782f24 369 {
jiuk 0:2dabb9782f24 370 if(fil==fila){
jiuk 0:2dabb9782f24 371 guarda_linea=columna+colum;
jiuk 0:2dabb9782f24 372 sendSPI(fila,guarda_linea);
jiuk 0:2dabb9782f24 373 }
jiuk 0:2dabb9782f24 374 else
jiuk 0:2dabb9782f24 375 {
jiuk 0:2dabb9782f24 376 guarda_linea=columna;
jiuk 0:2dabb9782f24 377 sendSPI(fila,guarda_linea);
jiuk 0:2dabb9782f24 378 sendSPI(fil,colum);
jiuk 0:2dabb9782f24 379 }
jiuk 0:2dabb9782f24 380 }
jiuk 0:2dabb9782f24 381 else{
jiuk 0:2dabb9782f24 382 sendSPI(fila,columna);
jiuk 0:2dabb9782f24 383 }
jiuk 0:2dabb9782f24 384 //generar_punto();
jiuk 0:2dabb9782f24 385 }
jiuk 0:2dabb9782f24 386 }