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.
Diff: funcion_matriz.h
- Revision:
- 1:ebfb091d5b63
- Child:
- 2:15facba8b8b4
diff -r b09782a64039 -r ebfb091d5b63 funcion_matriz.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/funcion_matriz.h Sat Nov 17 02:16:21 2018 +0000
@@ -0,0 +1,191 @@
+#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,i=0,cont=0,mcol=0,num=0,grad=0;
+
+void imp_mat(uint8_t *temp)// Hace el desplazamiento hacia abajo de la figura
+{
+ 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(i=0;i<8;i++)
+ {
+ mat_tmp[i]=*(tfig+i)>>dat[1]-1;
+
+ }
+for(i=0;i<8;i++)
+{
+ mat_tmp1[i]= mat_tmp[i];
+ }
+}
+void d_ale()
+ {
+ num=rand()%5+1;
+ mcol=4;
+ }
+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 analogoo()
+ {
+ mx=vrx.read();
+ msx=mx*3300;
+ my=vry.read();
+ msy=my*3300;
+ printf("Datosx = %f",msx);
+ }
+ void mover_fig()//mueve la figura por medio de botones
+{
+ analogoo();
+ int mfig;
+
+ if(msx>1800){
+ mfig=1;}
+ if(msy<300){//mover figura a la derecha
+ mfig=2;}
+ if(msy>3000){//mover figura a la izquierda
+ mfig=3;}
+
+ switch(mfig)
+ {
+ case 1:
+ 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;
+ }
+ break;
+ case 2:
+ int temp1 = mat_tmp[i]&(0x01);
+ if(temp1==0)
+ {
+ for(i=0;i<3;i++)
+ {
+ mat_tmp[i]=mat_tmp[i]>>1; //mover derecha
+
+ }
+ for(i=0;i<7;i++){
+ mat_tmp1[i]=mat_tmp1[i]>>1;
+ }
+ }
+ break;
+ case 3:
+ int temp2 = mat_tmp[i]&(0x80);
+ if(temp2==0)
+ {
+ for(i=0;i<7;i++){
+ mat_tmp1[i]=mat_tmp1[i]<<1;
+ }
+ for(i=0;i<3;i++)
+ {
+ mat_tmp[i]=mat_tmp[i]<<1; //mover izquierda
+ }
+ }
+ break;
+}
+}
+void act_matrix(uint8_t* temp)//Evalua figura guardada y su espacio
+{
+ for (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 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
\ No newline at end of file