falta verificar cambio de joystick a accel

Dependencies:   mbed MPU6050

Committer:
jiuk
Date:
Mon Nov 19 06:25:35 2018 +0000
Revision:
4:3426b2472f99
Parent:
3:81dc55b0a8d7
Child:
5:f8ca9f670abe
FUNCIONA ACELE O JOYSTICK, FALLA PULSADOR.

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