final, faltan ganas

Dependencies:   mbed MPU6050

Committer:
jiuk
Date:
Thu Nov 22 09:57:49 2018 +0000
Revision:
6:4c9e8118c303
Parent:
5:f8ca9f670abe
Child:
7:5f1c8385cf8e
con interrupci?n de serial

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