julian alvarez / Mbed 2 deprecated moggo_1

Dependencies:   mbed mbed

Fork of moggo by julian alvarez

Files at this revision

API Documentation at this revision

Comitter:
jiuk
Date:
Thu Sep 06 21:58:40 2018 +0000
Child:
1:78d5142da831
Commit message:
Intercambio de piezas, bajan pero sin parar, faltan los grados y salir de una columna determinada.

Changed in this revision

mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show annotated file Show diff for this revision Revisions of this file
moggo.cpp Show annotated file Show diff for this revision Revisions of this file
moggo.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 06 21:58:40 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Thu Sep 06 21:58:40 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/gokmenascioglu/code/mbed/#a8fa94490a0a
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/moggo.h	Thu Sep 06 21:58:40 2018 +0000
@@ -0,0 +1,18 @@
+#ifndef MOGGO_H
+#define MOGGO_H
+
+#include "mbed.h"
+
+#define C_TYPE 1
+#define I_TYPE 2
+#define L_TYPE 3
+#define T_TYPE 4
+#define S_TYPE 5
+
+ uint8_t FIG_C[11]={0b11000000,0b11000000,0,0,0,0,0,0,0,0};
+ uint8_t FIG_I[11]={0b10000000,0b10000000,0b10000000,0,0,0,0,0,0,0};
+ uint8_t FIG_L[11]={0b10000000,0b10000000,0b11000000,0,0,0,0,0,0,0};
+ uint8_t FIG_T[11]={0b11100000,0b01000000,0,0,0,0,0,0,0,0};
+ uint8_t FIG_S[11]={0b01100000,0b11000000,0,0,0,0,0,0,0,0};
+
+#endif //  MOGGO_H
\ No newline at end of file