Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
funcion_matriz.h
- Committer:
- sanchezzbrahian
- Date:
- 2018-11-18
- Revision:
- 3:8a8ff76e84bc
- Parent:
- 2:15facba8b8b4
File content as of revision 3:8a8ff76e84bc:
#include "mbed.h" #ifndef funcion_matriz #define funcion_matriz #define MAXDAT 3 Serial pc(USBTX,USBRX);//conexion por puerto USB uint8_t mat_act[11]={0,0,0,0,0,0,0,0,0,0,0}; //Matriz para mostrar en pantalla. uint8_t mat_tmp[8]={0,0,0,0,0,0,0,0}; uint8_t mat_tmp1[8]={0,0,0,0,0,0,0,0}; //Matriz temporal de las fichas. uint8_t dat[MAXDAT]={0,0,0}; uint8_t fila=0,save=0,cont=0,num=0,grad=0,mcol=0,i; void imp_mat(uint8_t *temp) { sendSPI(cont-3,mat_act[cont-3]); sendSPI(cont-2,(*(temp+0) | mat_act[cont-2])); sendSPI(cont-1,(*(temp+1) | mat_act[cont-1])); sendSPI(cont,(*(temp+2) | mat_act[cont])); } uint32_t read_command() //ingresa "<",">" y define el tamaño del vector "dat" { char intc=pc.getc(); while(intc != '<') intc=pc.getc(); for (int i =0;i<MAXDAT;i++) dat[i]=pc.getc(); intc=pc.getc(); if(intc != '>'){ return 0; } return 1; } void cop_fi (uint8_t* tfig) //Almacena la figura en la matriz temporal { for(int i=0;i<8;i++) { mat_tmp[i]=*(tfig+i)>>dat[1]-1; } for(int i=0;i<8;i++) { mat_tmp1[i]= mat_tmp[i]; } } void ingred_d() //Tipo de figuras { uint8_t tf=dat[0]; switch(tf) { case tipo_c: // Cuadrado cop_fi(FIG_C); break; case tipo_s: //S cop_fi(FIG_S); break; case tipo_t: //T cop_fi(FIG_T); break; case tipo_i: //I cop_fi(FIG_I); break; case tipo_l: //L cop_fi(FIG_L); break; } } void mover_fig()//mueve la figura por medio de botones { analogo(); if(mx<0.1) { int temp1 = mat_tmp[i+1]&(0x01); if(temp1==0) { for(int i=0;i<7;i++) { mat_tmp[i]=mat_tmp[i]>>1; } } } //mover figura a la derecha if(mx>0.9) { int temp2 = mat_tmp[i+2]&(0x80); if(temp2==0) { for(int i=0;i<7;i++) { mat_tmp[i]=mat_tmp[i]<<1; } }//mover figura a la izquierda } } void rotar_fig() { analogo(); if(my>0.6) { grad++; if(grad<5) { switch (grad) { case 1: mat_tmp[0]=mat_tmp1[4]; mat_tmp[1]=mat_tmp1[5]; mat_tmp[2]=mat_tmp1[6]; break; case 2: mat_tmp[0]=mat_tmp1[0]; mat_tmp[1]=mat_tmp1[2]; mat_tmp[2]=mat_tmp1[1]; break; case 3: mat_tmp[0]=mat_tmp1[6]; mat_tmp[1]=mat_tmp1[5]; mat_tmp[2]=mat_tmp1[4]; break; case 4: mat_tmp[0]=mat_tmp1[0]; mat_tmp[1]=mat_tmp1[1]; mat_tmp[2]=mat_tmp1[2]; break; } } if(grad>4) { grad=0; } } } void act_matrix(uint8_t*temp)//Evalua figura guardada y su espacio { for (int i=0;i<9;i++) { save=*(temp+2)& mat_act[i]; if (save==0 ) { fila=i+1; } if (save!=0) { fila=i; i=9; } } } void guardar_mat(uint8_t *temp)//guarda la matriz { mat_act[fila-3]=(*(temp+0))| mat_act[fila-3]; mat_act[fila-2]=(*(temp+1))| mat_act[fila-2]; mat_act[fila-1]=(*(temp+2))| mat_act[fila-1]; }; void most_fail() { if(j+1==7){ mat_act[i] = 0x00; mat_act[i+1] = 0x00;} } void elim_lin() { for(i=0;i<9;i++){ if(mat_act[i]==255){ for(uint8_t a=i;a>=1;a--){ sendSPI(a,mat_act[a-1]); mat_act[a]=mat_act[a-1]; } } } } #endif