Funciona con acelero-metro, falta comunicación y blink.

Dependencies:   mbed MPU6050

Committer:
jiuk
Date:
Wed Nov 21 15:57:09 2018 +0000
Revision:
6:eadec7d43859
Parent:
5:1292da7b7c6f
Version 21-11 previa cambios.

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 #include "MPU6050.h"
jiuk 0:2dabb9782f24 5
jiuk 0:2dabb9782f24 6 Serial command(USBTX,USBRX); //habilitar la comunicacion serial a traves del puerto usb.
jiuk 6:eadec7d43859 7 MPU6050 Wire(PB_9 , PB_8);
jiuk 0:2dabb9782f24 8
jiuk 0:2dabb9782f24 9 SPI deviceM(PB_15, PB_14, PB_13);
jiuk 0:2dabb9782f24 10 DigitalOut ssel (PB_12);
jiuk 0:2dabb9782f24 11 //SPI deviceM(PB_5, PB_4, PB_3); //define el Clock, Dato salida (miso) y Dato de entrada (mosi).
jiuk 0:2dabb9782f24 12 //DigitalOut ssel (PB_9); //Chip Select para el controlador.
jiuk 0:2dabb9782f24 13 //Serial command(USBTX,USBRX); //habilitar la comunicacion serial a traves del puerto usb.
jiuk 0:2dabb9782f24 14 Serial com_tar(PC_10,PC_11); //master f446R
jiuk 0:2dabb9782f24 15 //Serial com_tar(PA_15,PB_7); //slave f411R //habilitar la comunicacion serial a traves del puerto usb.
jiuk 6:eadec7d43859 16 Ticker timer, timer_1;
jiuk 4:3426b2472f99 17 DigitalIn pulsador(PH_1);
jiuk 4:3426b2472f99 18 AnalogIn in1(PC_2);
jiuk 4:3426b2472f99 19 AnalogIn in2(PC_3);
jiuk 5:1292da7b7c6f 20 DigitalOut led(LED1);
jiuk 0:2dabb9782f24 21
jiuk 6:eadec7d43859 22 #define VEL 400 //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 5:1292da7b7c6f 28 #define GIRO 3
jiuk 5:1292da7b7c6f 29 #define G_DIAG 3
jiuk 0:2dabb9782f24 30
jiuk 5:1292da7b7c6f 31 int columna=1, manzanas=0, fila=1, fil=1, colum=0;
jiuk 5:1292da7b7c6f 32 uint8_t _guarda_manzanas[8]={0,0,0,0,0,0,0,0};
jiuk 6:eadec7d43859 33 uint8_t mat_act[11]={0,0,0,0,0,0,0,0,0,0,0}; //Matriz para mostrar en pantalla.
jiuk 6:eadec7d43859 34 uint8_t mat_tmp1[8]={0,0,0,0,0,0,0,0};
jiuk 6:eadec7d43859 35 uint8_t cont=0, correr=0, metrix=0,type_fig=0,reset=0;
jiuk 6:eadec7d43859 36 uint8_t ncolumna=1,grados=1,ficha=0;
jiuk 6:eadec7d43859 37 uint8_t mat_tmp[8]={0,0,0,0,0,0,0,0}; //Matriz temporal para arrojar las fichas.
jiuk 6:eadec7d43859 38 // 0 , 1 , 2 , 3 , 4 ,5, 6
jiuk 6:eadec7d43859 39 uint8_t FIG_ALL[8]={0b10000000,0b11000000,0b11100000,0b01000000,0b01100000,0,0b00100000};//FIG_C[0]=1; FIG_C[1]=11; FIG_C[2]=111; FIG_C[3]=01; FIG_C[4]=011
jiuk 6:eadec7d43859 40
jiuk 4:3426b2472f99 41 bool _boton=0;
jiuk 2:484928b9a5b5 42 void blink();
jiuk 4:3426b2472f99 43 void boton();
jiuk 5:1292da7b7c6f 44 void guarda_manzana();
jiuk 5:1292da7b7c6f 45 void imprime_manzanas();
jiuk 6:eadec7d43859 46 void cop_mat(uint8_t,uint8_t,uint8_t,uint8_t);
jiuk 6:eadec7d43859 47 void borrar();
jiuk 6:eadec7d43859 48 void dibujar();
jiuk 6:eadec7d43859 49 void buscar_fil();
jiuk 6:eadec7d43859 50 void guardar_mat();
jiuk 6:eadec7d43859 51 void correr_fig();
jiuk 6:eadec7d43859 52 void imp_mat();
jiuk 6:eadec7d43859 53 void fichas();
jiuk 6:eadec7d43859 54 void buscar_linea();
jiuk 6:eadec7d43859 55 void revisar_mov();
jiuk 6:eadec7d43859 56 void manzanas_revisar_mov();
jiuk 6:eadec7d43859 57 void cambiar_jugador();
jiuk 6:eadec7d43859 58 void sendSPI(uint8_t, uint8_t);
jiuk 6:eadec7d43859 59 void buscador();
jiuk 6:eadec7d43859 60 int main ();
jiuk 6:eadec7d43859 61
jiuk 6:eadec7d43859 62 //--------------------------------------------------
jiuk 6:eadec7d43859 63 //-------------------BUSCAR_FILA------------------------
jiuk 6:eadec7d43859 64 //--------------------------------------------------
jiuk 6:eadec7d43859 65 void buscar_fil(){
jiuk 6:eadec7d43859 66 for (uint8_t i=0;i<9;i++){
jiuk 6:eadec7d43859 67 if((mat_act[i]& mat_tmp[3])==0){
jiuk 6:eadec7d43859 68 fila=i;
jiuk 6:eadec7d43859 69 //command.printf("\n1- comparacion inicial:\n %d",mat_act[i]& mat_tmp[2]);
jiuk 6:eadec7d43859 70 }
jiuk 6:eadec7d43859 71 if((mat_act[i]& mat_tmp[3])!=0){
jiuk 6:eadec7d43859 72 fila=i-1; //cambio de 2 a 1
jiuk 6:eadec7d43859 73 i=9;
jiuk 6:eadec7d43859 74 //command.printf("\n2- comparacion mat_act[i]& mat_tmp[2] :\n %d",mat_act[i]& mat_tmp[2]);
jiuk 6:eadec7d43859 75 }
jiuk 6:eadec7d43859 76 if((mat_act[i]& mat_tmp[2])!=0){ //se condicionan las salidas de la busqueda de lanueva fila
jiuk 6:eadec7d43859 77 fila=i; //cambio de 2 a 1
jiuk 6:eadec7d43859 78 i=9;
jiuk 6:eadec7d43859 79 //command.printf("\n3- comparacion mat_act[i]& mat_tmp[1] :\n %d",mat_act[i]& mat_tmp[1]);
jiuk 6:eadec7d43859 80 }
jiuk 6:eadec7d43859 81 if((mat_act[i]& mat_tmp[1])!=0){
jiuk 6:eadec7d43859 82 fila=i+1; //cambio de 2 a 1
jiuk 6:eadec7d43859 83 i=9;
jiuk 6:eadec7d43859 84 //command.printf("\n4- comparacion mat_act[i]& mat_tmp[0]:\n %d",mat_act[i]& mat_tmp[0]);
jiuk 6:eadec7d43859 85 }
jiuk 6:eadec7d43859 86 }
jiuk 6:eadec7d43859 87 if(fila>8)
jiuk 6:eadec7d43859 88 fila=8;
jiuk 6:eadec7d43859 89 if(fila<=1){
jiuk 6:eadec7d43859 90 wait_ms(VEL);
jiuk 6:eadec7d43859 91 borrar();
jiuk 6:eadec7d43859 92 fila=8;
jiuk 6:eadec7d43859 93 }
jiuk 6:eadec7d43859 94 command.printf("\n buscar fila \n %d",fila);
jiuk 6:eadec7d43859 95 command.printf("\n ******************************* \n ");
jiuk 6:eadec7d43859 96 };
jiuk 6:eadec7d43859 97
jiuk 6:eadec7d43859 98
jiuk 6:eadec7d43859 99 //--------------------------------------------------
jiuk 6:eadec7d43859 100 //-------------------GUARDAR_MATRIZ------------------------
jiuk 6:eadec7d43859 101 //--------------------------------------------------
jiuk 6:eadec7d43859 102 void guardar_mat(){
jiuk 6:eadec7d43859 103 for (uint8_t i=0;i<9;i++){
jiuk 6:eadec7d43859 104 mat_act[fila-(8-i)]=mat_tmp1[i];
jiuk 6:eadec7d43859 105 }
jiuk 6:eadec7d43859 106 };
jiuk 6:eadec7d43859 107
jiuk 6:eadec7d43859 108
jiuk 6:eadec7d43859 109 //--------------------------------------------------
jiuk 6:eadec7d43859 110 //-------------------CORRER_FIGURA------------------------
jiuk 6:eadec7d43859 111 //--------------------------------------------------
jiuk 6:eadec7d43859 112 void correr_fig(){
jiuk 6:eadec7d43859 113
jiuk 6:eadec7d43859 114 uint8_t correr=command.getc();
jiuk 6:eadec7d43859 115
jiuk 6:eadec7d43859 116 if(correr==30) //Arriba, voltear figura.
jiuk 6:eadec7d43859 117 correr=1;
jiuk 6:eadec7d43859 118
jiuk 6:eadec7d43859 119 else if(correr==29) //izquierda, correr la figura.
jiuk 6:eadec7d43859 120 correr=2;
jiuk 6:eadec7d43859 121
jiuk 6:eadec7d43859 122 else if(correr==28) //Derecha correr la figura.
jiuk 6:eadec7d43859 123 correr=3;
jiuk 6:eadec7d43859 124
jiuk 6:eadec7d43859 125 else if(correr==31) //bajar, baja la figura.
jiuk 6:eadec7d43859 126 correr=0;
jiuk 6:eadec7d43859 127 command.printf("\n correr fig \n %d",correr);
jiuk 6:eadec7d43859 128 revisar_mov();
jiuk 6:eadec7d43859 129 }
jiuk 6:eadec7d43859 130
jiuk 6:eadec7d43859 131
jiuk 6:eadec7d43859 132 //--------------------------------------------------
jiuk 6:eadec7d43859 133 //-------------------IMPRIMIR_MATRIZ------------------------
jiuk 6:eadec7d43859 134 //--------------------------------------------------
jiuk 6:eadec7d43859 135 void imp_mat(){ //se genera la variable global cont.
jiuk 6:eadec7d43859 136 mat_tmp1[0]=(mat_tmp[0]+ mat_act[cont-3]);
jiuk 6:eadec7d43859 137 mat_tmp1[1]=(mat_tmp[1]+ mat_act[cont-2]);
jiuk 6:eadec7d43859 138 mat_tmp1[2]=(mat_tmp[2]+ mat_act[cont-1]);
jiuk 6:eadec7d43859 139 mat_tmp1[3]=(mat_tmp[3]+ mat_act[cont]); //condicionador de funcion, se descarta por una funcion smart.
jiuk 6:eadec7d43859 140 sendSPI(cont-3,mat_tmp1[0]);
jiuk 6:eadec7d43859 141 sendSPI(cont-2,mat_tmp1[1]);
jiuk 6:eadec7d43859 142 sendSPI(cont-1,mat_tmp1[2]);
jiuk 6:eadec7d43859 143 sendSPI(cont ,mat_tmp1[3]); //pasa de i+2 a i+1
jiuk 6:eadec7d43859 144 wait_ms(VEL);
jiuk 6:eadec7d43859 145 }
jiuk 6:eadec7d43859 146
jiuk 6:eadec7d43859 147
jiuk 6:eadec7d43859 148 //--------------------------------------------------
jiuk 6:eadec7d43859 149 //-------------------DIBUJAR_FICHAS------------------------
jiuk 6:eadec7d43859 150 //--------------------------------------------------
jiuk 6:eadec7d43859 151 void dibujar()
jiuk 6:eadec7d43859 152 {
jiuk 6:eadec7d43859 153 switch (ficha){ //Se envia el vector que contiene la figura a la funcion copiar matriz.
jiuk 6:eadec7d43859 154 case 1: if(ncolumna>7)
jiuk 6:eadec7d43859 155 ncolumna=7;
jiuk 6:eadec7d43859 156 cop_mat(5,1,1,ncolumna);
jiuk 6:eadec7d43859 157 break; //1: cuadro;
jiuk 6:eadec7d43859 158
jiuk 6:eadec7d43859 159 case 2: if(grados==1 || grados==3)
jiuk 6:eadec7d43859 160 cop_mat(0,0,0,ncolumna);
jiuk 6:eadec7d43859 161 if(grados==2 || grados==4)
jiuk 6:eadec7d43859 162 cop_mat(5,5,2,ncolumna); //2: I;
jiuk 6:eadec7d43859 163 break;
jiuk 6:eadec7d43859 164
jiuk 6:eadec7d43859 165 case 3: if(grados==1)
jiuk 6:eadec7d43859 166 cop_mat(0,0,1,ncolumna); //3: L;
jiuk 6:eadec7d43859 167 if(grados==2)
jiuk 6:eadec7d43859 168 cop_mat(5,2,0,ncolumna);
jiuk 6:eadec7d43859 169 if(grados==3)
jiuk 6:eadec7d43859 170 cop_mat(1,3,3,ncolumna);
jiuk 6:eadec7d43859 171 if(grados==4)
jiuk 6:eadec7d43859 172 cop_mat(5,6,2,ncolumna);
jiuk 6:eadec7d43859 173 break;
jiuk 6:eadec7d43859 174
jiuk 6:eadec7d43859 175 case 4: if(grados==1)
jiuk 6:eadec7d43859 176 cop_mat(5,3,2,ncolumna); //4: T;
jiuk 6:eadec7d43859 177 if(grados==2)
jiuk 6:eadec7d43859 178 cop_mat(0,1,0,ncolumna);
jiuk 6:eadec7d43859 179 if(grados==3)
jiuk 6:eadec7d43859 180 cop_mat(5,2,3,ncolumna);
jiuk 6:eadec7d43859 181 if(grados==4)
jiuk 6:eadec7d43859 182 cop_mat(3,1,3,ncolumna);
jiuk 6:eadec7d43859 183 break;
jiuk 6:eadec7d43859 184
jiuk 6:eadec7d43859 185 case 5: if(grados==1 || grados==3)
jiuk 6:eadec7d43859 186 cop_mat(5,4,1,ncolumna); //5: S;
jiuk 6:eadec7d43859 187 if(grados==2 || grados==4)
jiuk 6:eadec7d43859 188 cop_mat(0,1,3,ncolumna);
jiuk 6:eadec7d43859 189 break;
jiuk 6:eadec7d43859 190 }
jiuk 6:eadec7d43859 191 }
jiuk 6:eadec7d43859 192
jiuk 6:eadec7d43859 193
jiuk 6:eadec7d43859 194 //--------------------------------------------------
jiuk 6:eadec7d43859 195 //-------------------FICHAS_RANDOM------------------------
jiuk 6:eadec7d43859 196 //--------------------------------------------------
jiuk 6:eadec7d43859 197 void fichas(){
jiuk 6:eadec7d43859 198 ficha= rand() % 5;
jiuk 6:eadec7d43859 199 }
jiuk 6:eadec7d43859 200
jiuk 6:eadec7d43859 201
jiuk 6:eadec7d43859 202 //--------------------------------------------------
jiuk 6:eadec7d43859 203 //-------------------BUSCAR_LINEA------------------------
jiuk 6:eadec7d43859 204 //--------------------------------------------------
jiuk 6:eadec7d43859 205 void buscar_linea(){
jiuk 6:eadec7d43859 206 for(uint8_t i=0;i<9;i++){
jiuk 6:eadec7d43859 207 if(mat_act[i]==255){
jiuk 6:eadec7d43859 208 for(uint8_t a=i;a>=1;a--){
jiuk 6:eadec7d43859 209 sendSPI(a,mat_act[a-1]);
jiuk 6:eadec7d43859 210 mat_act[a]=mat_act[a-1];
jiuk 6:eadec7d43859 211 }
jiuk 6:eadec7d43859 212 }
jiuk 6:eadec7d43859 213 }
jiuk 6:eadec7d43859 214 }
jiuk 6:eadec7d43859 215
jiuk 6:eadec7d43859 216
jiuk 6:eadec7d43859 217 //--------------------------------------------------
jiuk 6:eadec7d43859 218 //-------------------REVISAR_MOVIMIENTO------------------------
jiuk 6:eadec7d43859 219 //--------------------------------------------------
jiuk 6:eadec7d43859 220 void revisar_mov(){
jiuk 6:eadec7d43859 221 command.printf("\n correr:\n %d",correr);
jiuk 6:eadec7d43859 222 switch (correr){
jiuk 6:eadec7d43859 223
jiuk 6:eadec7d43859 224 case 0:
jiuk 6:eadec7d43859 225 cont++;
jiuk 6:eadec7d43859 226 if(cont>8)cont=8;
jiuk 6:eadec7d43859 227 break; //cae la figura;
jiuk 6:eadec7d43859 228
jiuk 6:eadec7d43859 229 case 1:
jiuk 6:eadec7d43859 230 if((mat_tmp[1]==2) || (mat_tmp[1]==1) || (mat_tmp[1]==3)) //faltan condiciones para evitar desplazamiento innecesario.
jiuk 6:eadec7d43859 231 ncolumna--;
jiuk 6:eadec7d43859 232 grados++;
jiuk 6:eadec7d43859 233 if(grados>4)
jiuk 6:eadec7d43859 234 grados=1;
jiuk 6:eadec7d43859 235 break; //Girar la figura;
jiuk 6:eadec7d43859 236
jiuk 6:eadec7d43859 237 case 2:
jiuk 6:eadec7d43859 238 if((mat_tmp[1]!=1) && (mat_tmp[2]!=1) && (mat_tmp[3]!=1)){
jiuk 6:eadec7d43859 239 if((mat_tmp[1]!=3) && (mat_tmp[2]!=3) && (mat_tmp[3]!=3)){
jiuk 6:eadec7d43859 240 if((mat_tmp[1]!=7) && (mat_tmp[2]!=7) && (mat_tmp[3]!=7))
jiuk 6:eadec7d43859 241 ncolumna++;
jiuk 6:eadec7d43859 242 }
jiuk 6:eadec7d43859 243 }
jiuk 6:eadec7d43859 244 command.printf("\n columna:\n %d",ncolumna);
jiuk 6:eadec7d43859 245
jiuk 6:eadec7d43859 246 break; //correr a la Derecha;
jiuk 6:eadec7d43859 247
jiuk 6:eadec7d43859 248 case 3:
jiuk 6:eadec7d43859 249 ncolumna--;
jiuk 6:eadec7d43859 250 command.printf("\n columna:\n %d",ncolumna);
jiuk 6:eadec7d43859 251 if(ncolumna<1)
jiuk 6:eadec7d43859 252 ncolumna=1;
jiuk 6:eadec7d43859 253 break; //correr a la izquierda;
jiuk 6:eadec7d43859 254 /*
jiuk 6:eadec7d43859 255 case 4:
jiuk 6:eadec7d43859 256 cont++;
jiuk 6:eadec7d43859 257 if(cont>8)cont=8;
jiuk 6:eadec7d43859 258 break;
jiuk 6:eadec7d43859 259 */
jiuk 6:eadec7d43859 260 }
jiuk 6:eadec7d43859 261 }
jiuk 6:eadec7d43859 262
jiuk 6:eadec7d43859 263
jiuk 6:eadec7d43859 264 //--------------------------------------------------
jiuk 6:eadec7d43859 265 //-------------------ESCOGER_JUEGO------------------------
jiuk 6:eadec7d43859 266 //--------------------------------------------------
jiuk 6:eadec7d43859 267 int escoger_juego(){
jiuk 6:eadec7d43859 268 uint8_t escoger=0;
jiuk 6:eadec7d43859 269 float _acc[3];
jiuk 6:eadec7d43859 270 int acc[3],buscado=32;
jiuk 6:eadec7d43859 271 while(escoger==0)
jiuk 6:eadec7d43859 272 {
jiuk 6:eadec7d43859 273 ncolumna=3;
jiuk 6:eadec7d43859 274 cont=3;
jiuk 6:eadec7d43859 275 ficha=4;
jiuk 6:eadec7d43859 276 dibujar();
jiuk 6:eadec7d43859 277 imp_mat();
jiuk 6:eadec7d43859 278 guardar_mat();
jiuk 6:eadec7d43859 279 //////////////////
jiuk 6:eadec7d43859 280 sendSPI(7,36);
jiuk 6:eadec7d43859 281 //wait(0.5);
jiuk 6:eadec7d43859 282 if(_boton==1)
jiuk 6:eadec7d43859 283 {
jiuk 6:eadec7d43859 284 Wire.getAccelero(_acc);
jiuk 6:eadec7d43859 285 acc[0]=((int)_acc[0])+2;
jiuk 6:eadec7d43859 286 acc[1]=((int)_acc[1])+2;
jiuk 6:eadec7d43859 287 }
jiuk 6:eadec7d43859 288 else
jiuk 6:eadec7d43859 289 {
jiuk 6:eadec7d43859 290 int x=((int)(in1.read()*-650))+13;
jiuk 6:eadec7d43859 291 int y=((int)(in2.read()*-650))+13;
jiuk 6:eadec7d43859 292 acc[0]=x;
jiuk 6:eadec7d43859 293 acc[1]=y;
jiuk 6:eadec7d43859 294 //command.printf("Joystick: \t X= %d, \t Y= %d, \n", x,y);
jiuk 6:eadec7d43859 295 }
jiuk 6:eadec7d43859 296 if(acc[0]>GIRO) //eje x derecha
jiuk 6:eadec7d43859 297 {
jiuk 6:eadec7d43859 298 correr=30;
jiuk 6:eadec7d43859 299 command.printf("\nJoystick: correr= %d, \n", correr);
jiuk 6:eadec7d43859 300 }
jiuk 6:eadec7d43859 301 else if(acc[0]<-GIRO) //eje x izquierda
jiuk 6:eadec7d43859 302 {
jiuk 6:eadec7d43859 303 correr=31;
jiuk 6:eadec7d43859 304 command.printf("\nJoystick: correr= %d, \n", correr);
jiuk 6:eadec7d43859 305 }
jiuk 6:eadec7d43859 306 if(correr==30)
jiuk 6:eadec7d43859 307 {
jiuk 6:eadec7d43859 308 grados= rand() % 4;
jiuk 6:eadec7d43859 309 ficha= rand() % 5;
jiuk 6:eadec7d43859 310 ncolumna=ncolumna++;
jiuk 6:eadec7d43859 311 cont=3;
jiuk 6:eadec7d43859 312 dibujar();
jiuk 6:eadec7d43859 313 imp_mat();
jiuk 6:eadec7d43859 314 guardar_mat();
jiuk 6:eadec7d43859 315 sendSPI(0,0);
jiuk 6:eadec7d43859 316 sendSPI(1,0);
jiuk 6:eadec7d43859 317 sendSPI(2,0);
jiuk 6:eadec7d43859 318 sendSPI(3,0);
jiuk 6:eadec7d43859 319 wait(0.1);
jiuk 6:eadec7d43859 320 if(_boton==1)
jiuk 6:eadec7d43859 321 escoger=1;
jiuk 6:eadec7d43859 322 command.printf("\nTetris: escoger= %d, \n", escoger);
jiuk 6:eadec7d43859 323 }
jiuk 6:eadec7d43859 324 else if(correr==31)
jiuk 6:eadec7d43859 325 {
jiuk 6:eadec7d43859 326 sendSPI(7,4+buscado);
jiuk 6:eadec7d43859 327 wait(0.05);
jiuk 6:eadec7d43859 328 sendSPI(7,buscado);
jiuk 6:eadec7d43859 329 buscado=buscado>>1;
jiuk 6:eadec7d43859 330 if(buscado==4)
jiuk 6:eadec7d43859 331 buscado=32;
jiuk 6:eadec7d43859 332 if(_boton==1)
jiuk 6:eadec7d43859 333 escoger=2;
jiuk 6:eadec7d43859 334 command.printf("\nRecoge_manzanas: escoger= %d, \n", escoger);
jiuk 6:eadec7d43859 335 }
jiuk 6:eadec7d43859 336 }
jiuk 6:eadec7d43859 337 return escoger;
jiuk 6:eadec7d43859 338 }
jiuk 6:eadec7d43859 339
jiuk 6:eadec7d43859 340 //--------------------------------------------------
jiuk 6:eadec7d43859 341 //-------------------COPIAR_MATRIZ------------------------
jiuk 6:eadec7d43859 342 //--------------------------------------------------
jiuk 6:eadec7d43859 343 void cop_mat(uint8_t a,uint8_t b,uint8_t c,uint8_t columna)
jiuk 6:eadec7d43859 344 {
jiuk 6:eadec7d43859 345 if(((mat_act[cont-2]& FIG_ALL[c]>>columna-1)==0)&&((mat_act[cont-1]& FIG_ALL[b]>>columna-1)==0)&&((mat_act[cont]& FIG_ALL[a]>>columna-1)==0)){
jiuk 6:eadec7d43859 346 mat_tmp[0]= FIG_ALL[5]>>columna-1;
jiuk 6:eadec7d43859 347 mat_tmp[1]= FIG_ALL[a]>>columna-1; //Realiza una copia de la matriz actual fila por fila.
jiuk 6:eadec7d43859 348 mat_tmp[2]= FIG_ALL[b]>>columna-1;
jiuk 6:eadec7d43859 349 mat_tmp[3]= FIG_ALL[c]>>columna-1;
jiuk 6:eadec7d43859 350 }
jiuk 6:eadec7d43859 351 }
jiuk 5:1292da7b7c6f 352
jiuk 5:1292da7b7c6f 353 //--------------------------------------------------
jiuk 5:1292da7b7c6f 354 //-------------------GUARDA_MANZANAS------------------------
jiuk 5:1292da7b7c6f 355 //--------------------------------------------------
jiuk 5:1292da7b7c6f 356 void guarda_manzana()
jiuk 5:1292da7b7c6f 357 {
jiuk 5:1292da7b7c6f 358 _guarda_manzanas[fil]=_guarda_manzanas[fil]+colum;
jiuk 5:1292da7b7c6f 359 }
jiuk 0:2dabb9782f24 360
jiuk 2:484928b9a5b5 361 //--------------------------------------------------
jiuk 2:484928b9a5b5 362 //-------------------TICKER------------------------
jiuk 2:484928b9a5b5 363 //--------------------------------------------------
jiuk 6:eadec7d43859 364 void attime()
jiuk 6:eadec7d43859 365 {
jiuk 6:eadec7d43859 366 //blink();
jiuk 5:1292da7b7c6f 367 boton();
jiuk 6:eadec7d43859 368 };
jiuk 6:eadec7d43859 369
jiuk 6:eadec7d43859 370 //--------------------------------------------------
jiuk 6:eadec7d43859 371 //-------------------TICKER_TETRIS------------------------
jiuk 6:eadec7d43859 372 //--------------------------------------------------
jiuk 6:eadec7d43859 373 void attime_tetris()
jiuk 6:eadec7d43859 374 {
jiuk 6:eadec7d43859 375 //blink();
jiuk 6:eadec7d43859 376 cont++;
jiuk 6:eadec7d43859 377 };
jiuk 4:3426b2472f99 378
jiuk 4:3426b2472f99 379 //--------------------------------------------------
jiuk 4:3426b2472f99 380 //-------------------BOTON------------------------
jiuk 4:3426b2472f99 381 //--------------------------------------------------
jiuk 4:3426b2472f99 382 void boton()
jiuk 4:3426b2472f99 383 {
jiuk 6:eadec7d43859 384 uint8_t a=0;
jiuk 6:eadec7d43859 385 if(reset==1)
jiuk 6:eadec7d43859 386 reset=0;
jiuk 6:eadec7d43859 387 while (pulsador == 0)
jiuk 4:3426b2472f99 388 {
jiuk 6:eadec7d43859 389 command.printf("Button pressed %d\n", a);
jiuk 6:eadec7d43859 390 a++;
jiuk 6:eadec7d43859 391 if (a>20)
jiuk 6:eadec7d43859 392 {
jiuk 6:eadec7d43859 393 for(int i=0;i<9;i++)
jiuk 6:eadec7d43859 394 {
jiuk 6:eadec7d43859 395 borrar();
jiuk 6:eadec7d43859 396 wait(0.1);
jiuk 6:eadec7d43859 397 sendSPI(4,24);
jiuk 6:eadec7d43859 398 sendSPI(5,24);
jiuk 6:eadec7d43859 399 wait(0.1);
jiuk 6:eadec7d43859 400 }
jiuk 6:eadec7d43859 401 reset=1;
jiuk 6:eadec7d43859 402 }
jiuk 6:eadec7d43859 403
jiuk 5:1292da7b7c6f 404 _boton= !_boton;
jiuk 4:3426b2472f99 405 }
jiuk 4:3426b2472f99 406 }
jiuk 5:1292da7b7c6f 407
jiuk 2:484928b9a5b5 408 //--------------------------------------------------
jiuk 2:484928b9a5b5 409 //-------------------SPI------------------------
jiuk 2:484928b9a5b5 410 //--------------------------------------------------
jiuk 0:2dabb9782f24 411 void sendSPI(uint8_t d1, uint8_t d2)
jiuk 0:2dabb9782f24 412 {
jiuk 0:2dabb9782f24 413 deviceM.unlock();
jiuk 0:2dabb9782f24 414 ssel=0;
jiuk 0:2dabb9782f24 415 deviceM.write(d1);
jiuk 0:2dabb9782f24 416 deviceM.write(d2);
jiuk 0:2dabb9782f24 417 ssel=1;
jiuk 0:2dabb9782f24 418 deviceM.lock();
jiuk 2:484928b9a5b5 419 };
jiuk 2:484928b9a5b5 420
jiuk 2:484928b9a5b5 421 //--------------------------------------------------
jiuk 2:484928b9a5b5 422 //-------------------TEST------------------------
jiuk 2:484928b9a5b5 423 //--------------------------------------------------
jiuk 0:2dabb9782f24 424 void test() //test
jiuk 0:2dabb9782f24 425 {
jiuk 0:2dabb9782f24 426 sendSPI(0x09,0); //no decodificacion
jiuk 4:3426b2472f99 427 sendSPI(0x0A,0x9); //intensidad
jiuk 0:2dabb9782f24 428 sendSPI(0x0B,0x07); //usa 7 leds
jiuk 0:2dabb9782f24 429 sendSPI(0x0C,1); //no apaga
jiuk 0:2dabb9782f24 430 sendSPI(0x0F,0); //operacion normal
jiuk 0:2dabb9782f24 431 }
jiuk 0:2dabb9782f24 432
jiuk 2:484928b9a5b5 433 //--------------------------------------------------
jiuk 2:484928b9a5b5 434 //-------------------BORRAR------------------------
jiuk 2:484928b9a5b5 435 //--------------------------------------------------
jiuk 0:2dabb9782f24 436 void borrar() //borrar toda la matriz;
jiuk 0:2dabb9782f24 437 {
jiuk 0:2dabb9782f24 438 int i;
jiuk 0:2dabb9782f24 439 for(i=0;i<=8;i++)
jiuk 0:2dabb9782f24 440 {
jiuk 0:2dabb9782f24 441 sendSPI(i,0);
jiuk 0:2dabb9782f24 442 }
jiuk 0:2dabb9782f24 443 }
jiuk 0:2dabb9782f24 444
jiuk 5:1292da7b7c6f 445 //--------------------------------------------------
jiuk 5:1292da7b7c6f 446 //-------------------IMPRIME_MANZANAS------------------------
jiuk 5:1292da7b7c6f 447 //--------------------------------------------------
jiuk 5:1292da7b7c6f 448 void imprime_manzanas()
jiuk 5:1292da7b7c6f 449 {
jiuk 5:1292da7b7c6f 450 for(int i=0;i<9;i++)
jiuk 5:1292da7b7c6f 451 {
jiuk 5:1292da7b7c6f 452 if(i==fila)
jiuk 5:1292da7b7c6f 453 {
jiuk 5:1292da7b7c6f 454 uint8_t x=_guarda_manzanas[i]+columna;
jiuk 5:1292da7b7c6f 455 sendSPI(i,x);
jiuk 5:1292da7b7c6f 456 command.printf("if=fila.imprime_manzanas: X=%d\n", x);
jiuk 5:1292da7b7c6f 457 }
jiuk 5:1292da7b7c6f 458 else
jiuk 5:1292da7b7c6f 459 {
jiuk 5:1292da7b7c6f 460 sendSPI(i,_guarda_manzanas[i]);
jiuk 5:1292da7b7c6f 461 command.printf("else.imprime_manzanas: %d\n", _guarda_manzanas[i]);
jiuk 5:1292da7b7c6f 462 }
jiuk 5:1292da7b7c6f 463 }
jiuk 5:1292da7b7c6f 464 }
jiuk 2:484928b9a5b5 465
jiuk 2:484928b9a5b5 466 //--------------------------------------------------
jiuk 2:484928b9a5b5 467 //-------------------GENERAR_PUNTO------------------------
jiuk 2:484928b9a5b5 468 //--------------------------------------------------
jiuk 0:2dabb9782f24 469 void generar_punto()
jiuk 0:2dabb9782f24 470 {
jiuk 2:484928b9a5b5 471 int col[8]={1,2,4,8,16,32,64,128};
jiuk 6:eadec7d43859 472 borrar();
jiuk 2:484928b9a5b5 473 int _fil=fil;
jiuk 2:484928b9a5b5 474 fil= rand() % 7+1;
jiuk 0:2dabb9782f24 475 int y= rand() % 7+1;
jiuk 6:eadec7d43859 476 command.printf("\n\n Fila: %d",fil);
jiuk 6:eadec7d43859 477 command.printf("\n Columna:%d",col[y]);
jiuk 2:484928b9a5b5 478 if(_fil==fil)
jiuk 6:eadec7d43859 479 colum=colum+col[y];
jiuk 6:eadec7d43859 480 colum=col[y];
jiuk 6:eadec7d43859 481 if(fil==fila)
jiuk 6:eadec7d43859 482 {
jiuk 6:eadec7d43859 483 int guarda_linea=columna+colum;
jiuk 6:eadec7d43859 484 sendSPI(fila,guarda_linea);
jiuk 6:eadec7d43859 485 }
jiuk 0:2dabb9782f24 486 else
jiuk 6:eadec7d43859 487 sendSPI(fil,col[y]);
jiuk 0:2dabb9782f24 488 }
jiuk 0:2dabb9782f24 489
jiuk 2:484928b9a5b5 490 //--------------------------------------------------
jiuk 2:484928b9a5b5 491 //-------------------BLINK------------------------
jiuk 2:484928b9a5b5 492 //--------------------------------------------------
jiuk 5:1292da7b7c6f 493 void blink()
jiuk 5:1292da7b7c6f 494 {
jiuk 5:1292da7b7c6f 495 borrar();
jiuk 5:1292da7b7c6f 496 sendSPI(fila,columna);
jiuk 5:1292da7b7c6f 497 wait(0.05);
jiuk 5:1292da7b7c6f 498 }
jiuk 2:484928b9a5b5 499
jiuk 2:484928b9a5b5 500 //--------------------------------------------------
jiuk 6:eadec7d43859 501 //-------------------MANZANAS_REVISAR_MOV------------------------
jiuk 2:484928b9a5b5 502 //--------------------------------------------------
jiuk 6:eadec7d43859 503 void manzanas_revisar_mov(){
jiuk 5:1292da7b7c6f 504 //uint8_t guardar_linea=0;
jiuk 5:1292da7b7c6f 505 switch (correr)
jiuk 5:1292da7b7c6f 506 {
jiuk 3:81dc55b0a8d7 507
jiuk 3:81dc55b0a8d7 508 case 2:
jiuk 5:1292da7b7c6f 509 columna=columna<<1;
jiuk 5:1292da7b7c6f 510 fila--;
jiuk 5:1292da7b7c6f 511 if (columna>MINC)
jiuk 5:1292da7b7c6f 512 columna=MAXC;
jiuk 5:1292da7b7c6f 513 if (fila<MIN)
jiuk 5:1292da7b7c6f 514 {
jiuk 5:1292da7b7c6f 515 fila=MAX;
jiuk 5:1292da7b7c6f 516 sendSPI(MIN,0);
jiuk 5:1292da7b7c6f 517 }
jiuk 6:eadec7d43859 518 sendSPI(fila+1,_guarda_manzanas[fila+1]);
jiuk 3:81dc55b0a8d7 519 break;
jiuk 3:81dc55b0a8d7 520
jiuk 3:81dc55b0a8d7 521 case 4:
jiuk 5:1292da7b7c6f 522 columna=columna<<1;
jiuk 5:1292da7b7c6f 523 fila++;
jiuk 5:1292da7b7c6f 524 if (fila>MAX){
jiuk 5:1292da7b7c6f 525 fila=MIN;
jiuk 5:1292da7b7c6f 526 sendSPI(MAX,0);
jiuk 5:1292da7b7c6f 527 }
jiuk 5:1292da7b7c6f 528 if (columna>MINC)
jiuk 5:1292da7b7c6f 529 columna=MAXC;
jiuk 6:eadec7d43859 530 sendSPI(fila-1,_guarda_manzanas[fila-1]);
jiuk 3:81dc55b0a8d7 531 break;
jiuk 3:81dc55b0a8d7 532
jiuk 3:81dc55b0a8d7 533 case 1:
jiuk 5:1292da7b7c6f 534 columna=columna>>1;
jiuk 5:1292da7b7c6f 535 fila--;
jiuk 5:1292da7b7c6f 536 if (columna<MAXC)
jiuk 5:1292da7b7c6f 537 columna=MINC;
jiuk 5:1292da7b7c6f 538 if (fila<MIN){
jiuk 5:1292da7b7c6f 539 fila=MAX;
jiuk 5:1292da7b7c6f 540 sendSPI(MIN,0);
jiuk 5:1292da7b7c6f 541 }
jiuk 6:eadec7d43859 542 sendSPI(fila+1,_guarda_manzanas[fila+1]);
jiuk 3:81dc55b0a8d7 543 break;
jiuk 3:81dc55b0a8d7 544
jiuk 3:81dc55b0a8d7 545 case 3:
jiuk 5:1292da7b7c6f 546 columna=columna>>1;
jiuk 5:1292da7b7c6f 547 fila++;
jiuk 5:1292da7b7c6f 548 if (columna<MAXC)
jiuk 5:1292da7b7c6f 549 columna=MINC;
jiuk 5:1292da7b7c6f 550 if (fila>MAX){
jiuk 5:1292da7b7c6f 551 fila=MIN;
jiuk 5:1292da7b7c6f 552 sendSPI(MAX,0);
jiuk 5:1292da7b7c6f 553 }
jiuk 6:eadec7d43859 554 sendSPI(fila-1,_guarda_manzanas[fila-1]);
jiuk 3:81dc55b0a8d7 555 break;
jiuk 3:81dc55b0a8d7 556
jiuk 0:2dabb9782f24 557 case 28:
jiuk 5:1292da7b7c6f 558 columna=columna<<1;
jiuk 5:1292da7b7c6f 559 if (columna>MINC)
jiuk 5:1292da7b7c6f 560 columna=MAXC;
jiuk 0:2dabb9782f24 561 break;
jiuk 0:2dabb9782f24 562
jiuk 0:2dabb9782f24 563 case 29:
jiuk 5:1292da7b7c6f 564 columna=columna>>1;
jiuk 5:1292da7b7c6f 565 if (columna<MAXC)
jiuk 5:1292da7b7c6f 566 columna=MINC;
jiuk 0:2dabb9782f24 567 break;
jiuk 0:2dabb9782f24 568
jiuk 0:2dabb9782f24 569 case 30:
jiuk 5:1292da7b7c6f 570 fila--;
jiuk 5:1292da7b7c6f 571 if (fila<MIN){
jiuk 5:1292da7b7c6f 572 fila=MAX;
jiuk 5:1292da7b7c6f 573 sendSPI(MIN,0);
jiuk 5:1292da7b7c6f 574 }
jiuk 6:eadec7d43859 575 sendSPI(fila+1,_guarda_manzanas[fila+1]);
jiuk 0:2dabb9782f24 576 break;
jiuk 0:2dabb9782f24 577
jiuk 0:2dabb9782f24 578 case 31:
jiuk 5:1292da7b7c6f 579 fila++;
jiuk 5:1292da7b7c6f 580 if (fila>MAX){
jiuk 5:1292da7b7c6f 581 fila=MIN;
jiuk 5:1292da7b7c6f 582 sendSPI(MAX,0);
jiuk 5:1292da7b7c6f 583 }
jiuk 6:eadec7d43859 584 sendSPI(fila-1,_guarda_manzanas[fila-1]);
jiuk 0:2dabb9782f24 585 break;
jiuk 1:efcead3fb5eb 586
jiuk 1:efcead3fb5eb 587 case 0:
jiuk 1:efcead3fb5eb 588 break;
jiuk 0:2dabb9782f24 589 }
jiuk 0:2dabb9782f24 590 }
jiuk 2:484928b9a5b5 591
jiuk 3:81dc55b0a8d7 592 //--------------------------------------------------
jiuk 3:81dc55b0a8d7 593 //-------------------VELOCIDAD-----------------------
jiuk 3:81dc55b0a8d7 594 //--------------------------------------------------
jiuk 3:81dc55b0a8d7 595 int velocidad(float _acc[3])
jiuk 3:81dc55b0a8d7 596 {
jiuk 5:1292da7b7c6f 597 int vel=0,x=2,y=4; //
jiuk 3:81dc55b0a8d7 598 int acc[3];
jiuk 4:3426b2472f99 599 acc[0]=(int)_acc[0];
jiuk 4:3426b2472f99 600 acc[1]=(int)_acc[1];
jiuk 3:81dc55b0a8d7 601 if((acc[0]>GIRO) || (acc[0]<-GIRO) || (acc[1]>GIRO) || (acc[1]<-GIRO))
jiuk 3:81dc55b0a8d7 602 {
jiuk 4:3426b2472f99 603 if((acc[0]>(GIRO+x)) || (acc[0]<-(GIRO+x)) || (acc[1]>(GIRO+x)) || (acc[1]<-(GIRO+x)))
jiuk 4:3426b2472f99 604 {
jiuk 6:eadec7d43859 605 vel=VEL/2;
jiuk 4:3426b2472f99 606 if((acc[0]>(GIRO+y)) || (acc[0]<-(GIRO+y)) || (acc[1]>(GIRO+y)) || (acc[1]<-(GIRO+y)))
jiuk 6:eadec7d43859 607 vel=VEL;
jiuk 4:3426b2472f99 608 }
jiuk 4:3426b2472f99 609 else
jiuk 6:eadec7d43859 610 vel=VEL/3;
jiuk 3:81dc55b0a8d7 611 }
jiuk 3:81dc55b0a8d7 612 return vel;
jiuk 3:81dc55b0a8d7 613 }
jiuk 2:484928b9a5b5 614
jiuk 2:484928b9a5b5 615 //--------------------------------------------------
jiuk 2:484928b9a5b5 616 //-------------------BUSCADOR------------------------
jiuk 2:484928b9a5b5 617 //--------------------------------------------------
jiuk 5:1292da7b7c6f 618 //command.printf("Accelerometer: \t X= %f, \t Y= %f, \t Z=%f \n", acc[0],acc[1],acc[2]);
jiuk 5:1292da7b7c6f 619 //command.printf("Gyroscope: \t X= %f, \t Y= %f, \t Z=%f \n", gyro[0],gyro[1],gyro[2]);
jiuk 5:1292da7b7c6f 620 //float gyro[3]; Wire.getGyro(gyro);
jiuk 5:1292da7b7c6f 621 //command.printf("Accelerometer: \t X= %d, \t Y= %d, \n", acc[0],acc[1]);
jiuk 5:1292da7b7c6f 622
jiuk 0:2dabb9782f24 623 void buscador()
jiuk 0:2dabb9782f24 624 {
jiuk 6:eadec7d43859 625 //uint8_t correr;
jiuk 4:3426b2472f99 626 int y=0,x=0,acc[3],v;
jiuk 4:3426b2472f99 627 float _acc[3];
jiuk 5:1292da7b7c6f 628
jiuk 5:1292da7b7c6f 629 if(_boton==1)
jiuk 5:1292da7b7c6f 630 {
jiuk 5:1292da7b7c6f 631 Wire.getAccelero(_acc);
jiuk 5:1292da7b7c6f 632 acc[0]=((int)_acc[0])+2;
jiuk 5:1292da7b7c6f 633 acc[1]=((int)_acc[1])+2;
jiuk 5:1292da7b7c6f 634 }
jiuk 5:1292da7b7c6f 635 else
jiuk 4:3426b2472f99 636 {
jiuk 4:3426b2472f99 637 x=((int)(in1.read()*-650))+13;
jiuk 4:3426b2472f99 638 y=((int)(in2.read()*-650))+13;
jiuk 4:3426b2472f99 639 acc[0]=x;
jiuk 4:3426b2472f99 640 acc[1]=y;
jiuk 5:1292da7b7c6f 641 //command.printf("Joystick: \t X= %d, \t Y= %d, \n", x,y);
jiuk 4:3426b2472f99 642 }
jiuk 4:3426b2472f99 643
jiuk 5:1292da7b7c6f 644 //command.printf("Velocidad %d \n", v);
jiuk 5:1292da7b7c6f 645 if(acc[0]>GIRO) //eje x derecha
jiuk 3:81dc55b0a8d7 646 {
jiuk 5:1292da7b7c6f 647 if(acc[1]>G_DIAG) //eje y arriba
jiuk 3:81dc55b0a8d7 648 correr=1;
jiuk 3:81dc55b0a8d7 649 else if(acc[1]<-G_DIAG)//eje y abajo
jiuk 3:81dc55b0a8d7 650 correr=2;
jiuk 3:81dc55b0a8d7 651 else
jiuk 3:81dc55b0a8d7 652 correr=30;
jiuk 5:1292da7b7c6f 653 }
jiuk 5:1292da7b7c6f 654 else if(acc[0]<-GIRO) //eje x izquierda
jiuk 3:81dc55b0a8d7 655 {
jiuk 3:81dc55b0a8d7 656 if(acc[1]>G_DIAG) //eje y arriba
jiuk 3:81dc55b0a8d7 657 correr=3;
jiuk 3:81dc55b0a8d7 658 else if(acc[1]<-G_DIAG)//eje y abajo
jiuk 3:81dc55b0a8d7 659 correr=4;
jiuk 3:81dc55b0a8d7 660 else
jiuk 3:81dc55b0a8d7 661 correr=31;
jiuk 5:1292da7b7c6f 662 }
jiuk 5:1292da7b7c6f 663 else if(acc[1]>GIRO) //eje y arriba
jiuk 3:81dc55b0a8d7 664 correr=29;
jiuk 5:1292da7b7c6f 665 else if(acc[1]<-GIRO) //eje y abajo
jiuk 3:81dc55b0a8d7 666 correr=28;
jiuk 5:1292da7b7c6f 667 else
jiuk 5:1292da7b7c6f 668 correr=0;
jiuk 6:eadec7d43859 669 manzanas_revisar_mov();
jiuk 4:3426b2472f99 670 v=velocidad(_acc);
jiuk 4:3426b2472f99 671 wait_ms(v);
jiuk 0:2dabb9782f24 672 }
jiuk 0:2dabb9782f24 673
jiuk 2:484928b9a5b5 674 //--------------------------------------------------
jiuk 2:484928b9a5b5 675 //-------------------COMER------------------------
jiuk 2:484928b9a5b5 676 //--------------------------------------------------
jiuk 0:2dabb9782f24 677 int comer ()
jiuk 0:2dabb9782f24 678 {
jiuk 0:2dabb9782f24 679 int x=0;
jiuk 2:484928b9a5b5 680 if((fil==fila)&&((colum & columna) != 0))
jiuk 2:484928b9a5b5 681 {
jiuk 2:484928b9a5b5 682 manzanas++;
jiuk 2:484928b9a5b5 683 sendSPI(fila,columna);
jiuk 2:484928b9a5b5 684 for(int i=0;i<manzanas;i++)
jiuk 2:484928b9a5b5 685 {
jiuk 2:484928b9a5b5 686 int guarda_linea=columna+colum;
jiuk 2:484928b9a5b5 687 sendSPI(fila,guarda_linea);
jiuk 2:484928b9a5b5 688 generar_punto();
jiuk 2:484928b9a5b5 689 sendSPI(fil,colum);
jiuk 2:484928b9a5b5 690 //com_tar.putc(x);
jiuk 2:484928b9a5b5 691 }
jiuk 0:2dabb9782f24 692 x=1;
jiuk 2:484928b9a5b5 693 }
jiuk 0:2dabb9782f24 694 return x;
jiuk 2:484928b9a5b5 695 }
jiuk 2:484928b9a5b5 696
jiuk 0:2dabb9782f24 697
jiuk 2:484928b9a5b5 698 //--------------------------------------------------
jiuk 2:484928b9a5b5 699 //-------------------VALIDAR_CONTRINCANTE------------------------
jiuk 2:484928b9a5b5 700 //--------------------------------------------------
jiuk 0:2dabb9782f24 701 int validar_contrincante(){
jiuk 0:2dabb9782f24 702 int x=com_tar.getc();
jiuk 0:2dabb9782f24 703 return x;
jiuk 0:2dabb9782f24 704 }
jiuk 0:2dabb9782f24 705
jiuk 4:3426b2472f99 706
jiuk 4:3426b2472f99 707 //--------------------------------------------------
jiuk 4:3426b2472f99 708 //-------------------MAIN------------------------
jiuk 4:3426b2472f99 709 //--------------------------------------------------
jiuk 0:2dabb9782f24 710 int main ()
jiuk 0:2dabb9782f24 711 {
jiuk 0:2dabb9782f24 712 int guarda_linea,x=0;
jiuk 2:484928b9a5b5 713 timer.attach(&attime, 0.3);
jiuk 6:eadec7d43859 714 timer_1.attach(&attime_tetris, 0.4);
jiuk 0:2dabb9782f24 715 test();
jiuk 0:2dabb9782f24 716 while(1)
jiuk 6:eadec7d43859 717 {
jiuk 6:eadec7d43859 718 borrar();
jiuk 6:eadec7d43859 719 int juego=escoger_juego();
jiuk 6:eadec7d43859 720 if(juego==1)
jiuk 6:eadec7d43859 721 {
jiuk 6:eadec7d43859 722 while(reset==0)
jiuk 6:eadec7d43859 723 {
jiuk 6:eadec7d43859 724 //cambiar_jugador();
jiuk 6:eadec7d43859 725 fichas();
jiuk 6:eadec7d43859 726 buscar_fil();
jiuk 6:eadec7d43859 727 cont=0;
jiuk 6:eadec7d43859 728 // correr=command.getc(); //recibe el comando para orientar la ficha.
jiuk 6:eadec7d43859 729 while (cont<fila)
jiuk 6:eadec7d43859 730 {
jiuk 6:eadec7d43859 731 //cambiar_jugador();
jiuk 6:eadec7d43859 732 correr_fig();
jiuk 6:eadec7d43859 733 dibujar();
jiuk 6:eadec7d43859 734 buscar_fil();
jiuk 6:eadec7d43859 735 imp_mat();
jiuk 6:eadec7d43859 736 wait_ms(VEL);
jiuk 6:eadec7d43859 737 }
jiuk 6:eadec7d43859 738 guardar_mat();
jiuk 6:eadec7d43859 739 buscar_linea();
jiuk 6:eadec7d43859 740 } //fin while
jiuk 6:eadec7d43859 741 }
jiuk 6:eadec7d43859 742 else if(juego==2)
jiuk 0:2dabb9782f24 743 {
jiuk 6:eadec7d43859 744 sendSPI(fila,columna);
jiuk 6:eadec7d43859 745 generar_punto();
jiuk 6:eadec7d43859 746 while(reset==0)
jiuk 6:eadec7d43859 747 {
jiuk 6:eadec7d43859 748 buscador();
jiuk 6:eadec7d43859 749 //validar_contrincante();
jiuk 6:eadec7d43859 750 x=comer();
jiuk 6:eadec7d43859 751 //command.printf("\n comer:\n %d",x);
jiuk 6:eadec7d43859 752 if (x==0)
jiuk 0:2dabb9782f24 753 {
jiuk 6:eadec7d43859 754 if(fil==fila)
jiuk 6:eadec7d43859 755 {
jiuk 6:eadec7d43859 756 guarda_linea=columna+colum;
jiuk 6:eadec7d43859 757 sendSPI(fila,guarda_linea);
jiuk 6:eadec7d43859 758 }
jiuk 6:eadec7d43859 759 else
jiuk 6:eadec7d43859 760 {
jiuk 6:eadec7d43859 761 guarda_linea=columna;
jiuk 6:eadec7d43859 762 sendSPI(fila,guarda_linea);
jiuk 6:eadec7d43859 763 sendSPI(fil,colum);
jiuk 6:eadec7d43859 764 }
jiuk 0:2dabb9782f24 765 }
jiuk 6:eadec7d43859 766 else
jiuk 6:eadec7d43859 767 {
jiuk 6:eadec7d43859 768 sendSPI(fila,columna);
jiuk 6:eadec7d43859 769 }
jiuk 6:eadec7d43859 770 //generar_punto();
jiuk 6:eadec7d43859 771 }
jiuk 0:2dabb9782f24 772 }
jiuk 6:eadec7d43859 773 }
jiuk 0:2dabb9782f24 774 }