EJEMPLO

Dependencies:   mbed

Fork of 00_LAB_matrix8x8_SPI by ferney alberto beltran molina

Files at this revision

API Documentation at this revision

Comitter:
fabeltranm
Date:
Fri Sep 14 17:59:35 2018 +0000
Parent:
4:2bc5dfe058ef
Commit message:
ok1

Changed in this revision

figuras.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 2bc5dfe058ef -r d1c3238ea285 figuras.h
--- a/figuras.h	Tue Sep 04 22:31:01 2018 +0000
+++ b/figuras.h	Fri Sep 14 17:59:35 2018 +0000
@@ -3,14 +3,38 @@
 
 #include "mbed.h"
 
-#define L_TYPE 'L'
-#define S_TYPE 'S'
-#define I_TYPE 'I'
-#define NULL_TYPE 'N'
+#define L_TYPE 0x01
+#define S_TYPE 0x02
+#define I_TYPE 0x03
+#define NULL_TYPE 0x00
+/* 
+    FIG_L                FIG_I              FIG_S               FIG_T
+1 0 0 0 0 0 0 0     1 0 0 0 0 0 0 0     0 0 1 0 0 0 0 0     0 1 0 0 0 0 0 0
+1 0 0 0 0 0 0 0     1 0 0 0 0 0 0 0     1 1 0 0 0 0 0 0     1 1 1 0 0 0 0 0
+1 1 0 0 0 0 0 0     1 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0     0 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_I[11]={0b10000000,0b10000000,0b10000000,0,0,0,0,0,0,0};
- uint8_t FIG_S[11]={0b01100000,0b01000000,0b11000000,0,0,0,0,0,0,0};
- uint8_t FIG_NULL[11]={0,0,0,0,0,0,0,0,0,0,0};
+*/
+struct {
+    uint8_t fig[3];
+    int posx;
+} fig_act;
+
+
+
+uint8_t FIG_L[3]={0b11100000,0b00100000,0b00000000};
+uint8_t FIG_I[3]={0b10000000,0b10000000,0b10000000};
+uint8_t FIG_S[3]={0b01000000,0b01000000,0b10000000};
+uint8_t FIG_T[3]={0b01000000,0b01000000,0b11000000};
+uint8_t FIG_NULL[3]={0,0,0};
+
+
+
+
 
 #endif //  FIGURAS_H 
\ No newline at end of file
diff -r 2bc5dfe058ef -r d1c3238ea285 main.cpp
--- a/main.cpp	Tue Sep 04 22:31:01 2018 +0000
+++ b/main.cpp	Fri Sep 14 17:59:35 2018 +0000
@@ -12,7 +12,8 @@
 void debug_m(char *s , ... );
 
 uint8_t matrix_act[8]={0,0,0,0,0,0,0,0};
-uint8_t matrix_tmp[11]={0b10000000,0b10000000,0b11000000,0,0,0,0,0,0,0};
+uint8_t matrix_tmp[11]={0,0,0,0,0,0,0,0,0,0};
+uint8_t matrix_fig[3]={0,0,0};
   
  
 void sendSPI(uint8_t d1, uint8_t d2)
@@ -53,40 +54,49 @@
     }
  }
  
-void act_matrix(uint8_t*  mascara){ 
-    for (int i=0; i<8;i++)
-        matrix_act[i]=  ( *(mascara+i));
+void actualizar_matrix(){ 
+    for (int i=fig_act.posx; i<fig_act.posx+3;i++)
+        matrix_act[i]= fig_act.fig[i] ;
  
  } 
- void copy_matrix(uint8_t*  m2){
-  
-    for (int i=0; i<11;i++){
-        matrix_tmp[i]=  *(m2+i);
+
+
+void copy_fig(uint8_t*  m2, uint8_t ncol){
+   for (int i=0; i<3;i++){
+        fig_act.fig[i]= *(m2+i);
+        debug_m("%b\n",*(m2+i));
     }
- } 
+    fig_act.posx=ncol;
+    
+} 
+
+
 
 void new_read(){
-    char tf=command.getc();
+    uint8_t tf=command.getc();
+    char nc=command.getc();
+    debug_m("se recibe la figura %d, en la columna %d",tf);
     switch (tf) {
     case  L_TYPE: 
-        copy_matrix(FIG_L);
+        copy_fig(FIG_L,nc);
         break ;     
     case  S_TYPE: 
-        copy_matrix(FIG_S);
+        copy_fig(FIG_S,nc);
         break ;     
     case  I_TYPE: 
-        copy_matrix(FIG_I);
+        copy_fig(FIG_I,nc);
         break ;     
     default: 
-        copy_matrix(FIG_NULL);
+        copy_fig(FIG_NULL,nc);
         
     }
     
     
 }
+
 void desplazar_fila(){
-     for (int i=0; i<11;i++)
-        matrix_tmp[i]= matrix_tmp[i]>>1;
+     for (int i=0; i<3;i++)
+        fig_act.fig[i]= fig_act.fig[i]>>1;
     
 }
 int main() {
@@ -95,7 +105,7 @@
        new_read();
        for(int i=0;i<8;i++){
             desplazar_fila();
-            act_matrix(matrix_tmp);
+            actualizar_matrix();
             printMatrix(matrix_act);
             wait_ms(VELOCITY);
        }