Código simplificado, grados, funciona detencion filas, columna completo, puede recoger 4 fuguras en caracteres.

Dependencies:   mbed mbed

Fork of moggo_2 by julian alvarez

Revision:
0:3a60cf1c28ca
Child:
1:78d5142da831
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/moggo.cpp	Thu Sep 06 21:58:40 2018 +0000
@@ -0,0 +1,117 @@
+#include "mbed.h"
+#include "moggo.h" //agrega la libreria que contiene las figuras.
+
+SPI deviceM(PB_5, PB_4, PB_3); //define el Clock, Dato salida (miso) y Dato de entrada (mosi).
+DigitalOut ssel (PB_9);         //Chip Select para el controlador.
+Serial command(USBTX,USBRX); //habilitar la comunicacion serial a traves del puerto usb.
+
+#define  VEL 500 //Velocidad de actualizacion de dato en el controlador.
+
+void debug_m(char *s , ... ); //depurador de errores, probador.
+
+uint8_t mat_act[8]={0,0,0,0,0,0,0,0};    //Matriz para mostrar en pantalla.
+uint8_t mat_tmp[11]={0b10000000,0b10000000,0b11000000,0,0,0,0,0,0,0}; //Matriz temporal para arrojar las fichas.
+
+ 
+void sendSPI(uint8_t d1, uint8_t d2)
+{
+    deviceM.unlock();
+    ssel=0;
+    deviceM.write(d1);
+    deviceM.write(d2);
+    ssel=1;
+    deviceM.lock();
+}
+
+void test()  //test
+{
+    sendSPI(0x09,0);        //no decodificacion
+    sendSPI(0x0A,0x0);     //intensidad
+    sendSPI(0x0B,0x07);     //usa 7 leds                     
+    sendSPI(0x0C,1);        //no apaga
+    sendSPI(0x0F,0);        //operacion normal     
+}
+
+
+void imp_mat(uint8_t*  vC)
+
+{
+    uint8_t i =0;
+    for (i=1;i<9;i++){                      //Realiza la impresion de la matriz.
+        sendSPI(i,*(vC+i-1));
+    }
+}
+
+void act_mat(uint8_t*  mascara)
+{ 
+    for (int i=0; i<8;i++)                  //Es la matriz que tenemos como resultado de las diferentes piezas.
+        mat_act[i]=  (*(mascara+i));
+ } 
+ 
+void cop_mat(uint8_t*  m2)
+{
+    for (int i=0; i<11;i++){                //Realiza una copia de la matriz actual fila por fila.
+        mat_tmp[i]=  *(m2+i);
+    }
+}
+
+
+void desplazar_fila(){                      //Realiza el desplazamiento para bajar la figura.
+     for (int i=0; i<11;i++)
+        mat_tmp[i]= mat_tmp[i]>>1;
+    
+} 
+
+void borrar()
+{
+    int i;
+    for(i=0;i<=8;i++)
+    {
+        sendSPI(0x0+i,0x00);
+    }
+};
+
+void dibujar(char type_fig,char grados, char columna)
+{
+    //borrar();
+    
+    switch (type_fig){
+        case C_TYPE: cop_mat(FIG_C); break; //Se envia el vector que contiene la figura a la funcion copiar matriz.
+        case I_TYPE: cop_mat(FIG_I); break;
+        case L_TYPE: cop_mat(FIG_L); break;
+        case T_TYPE: cop_mat(FIG_T); break;
+        case S_TYPE: cop_mat(FIG_S); break;  
+    }
+    
+}
+
+int main() {
+    char tipo_fig=1,ncolumna=1,grados=1,lee1=0x00,lee2=0x00;  // enviar ficha y columna
+    test();
+    while(1){
+        borrar();
+        lee1=command.getc();      //recive '<' para iniciar la linea de comandos.
+        tipo_fig=command.getc();
+        grados=command.getc();
+        ncolumna=command.getc();       
+        lee2=command.getc();       //recive '>' para terminar la linea de comandos.
+            if(lee1==0x3c && lee2==0x3e) //solo imprime una figura si viene bajo el parametro '<(t_fig) (Grados) (Col)>'.
+            {
+            dibujar(tipo_fig,grados,ncolumna);
+            for(int i=0;i<8;i++){
+                desplazar_fila();
+                act_mat(mat_tmp);
+                imp_mat(mat_act);
+                wait_ms(VEL);
+                }          
+            }     
+        }
+    }
+    
+
+    
+void debug_m(char *s , ... ){
+    #if DEBUG
+    command.printf(s);   //busca errores para depurar en el sistema datos guardados.
+    #endif  
+}
\ No newline at end of file