NUEVO

Dependencies:   mbed

Fork of 00_01LAB_matrix8x8_fig_tetris by Alyson Castiblanco

Revision:
5:819f043b99a5
Parent:
4:2bc5dfe058ef
Child:
6:2f42f0b53611
diff -r 2bc5dfe058ef -r 819f043b99a5 main.cpp
--- a/main.cpp	Tue Sep 04 22:31:01 2018 +0000
+++ b/main.cpp	Sat Sep 08 03:46:46 2018 +0000
@@ -7,12 +7,12 @@
 Serial command(USBTX, USBRX);
 
 #define DEBUG 1
-#define  VELOCITY 500 // ms
+#define  VELOCITY 1000 // ms
 
-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]={0b00000000,0b00000000,0b00000000,0,0,0,0,0,0,0};
   
  
 void sendSPI(uint8_t d1, uint8_t d2)
@@ -26,6 +26,14 @@
 };
 
 
+
+
+void debug_m(char *s , ... ){
+    #if DEBUG
+    command.printf(s);
+    #endif  
+}
+
 void printMatrix(uint8_t*  vC)
 
 {
@@ -34,77 +42,142 @@
         sendSPI(i,*(vC+i-1));
     }
         
-    };
+    }
 
 
-
-int init_display(){
+void init_display(){
     sendSPI(0x0c,1);
     sendSPI(0x0b,7);
     sendSPI(0x09,0);
-    sendSPI(0x0A,0x0f);
+    sendSPI(0x0A,0x0E);
     printMatrix(matrix_act);
     int i;
-    for (i=0;i<2;i++){
+    for (i=0;i<4;i++){
         sendSPI(0x0F,1);
-        wait (0.5);
+        wait (0.2);
         sendSPI(0x0f,0);
-        wait (0.5);
+        wait (0.2);
     }
- }
+}
+
+
+
  
 void act_matrix(uint8_t*  mascara){ 
     for (int i=0; i<8;i++)
         matrix_act[i]=  ( *(mascara+i));
  
  } 
- void copy_matrix(uint8_t*  m2){
+ void copy_matrix(uint8_t*  m2, char col){
   
     for (int i=0; i<11;i++){
-        matrix_tmp[i]=  *(m2+i);
+        matrix_tmp[i]=  (*(m2+i)>>col);
     }
  } 
 
+    
 void new_read(){
+    
+    char ini=command.getc();
     char tf=command.getc();
+    char ang=command.getc();
+    char col=command.getc();
+    char fin=command.getc();
+    if(ini==0x3C && fin==0x3E)
+    {
     switch (tf) {
     case  L_TYPE: 
-        copy_matrix(FIG_L);
+    switch (ang)
+         {  case NOVEN:
+            copy_matrix(FIG_L1);
+            break;
+            case ZERO:
+            copy_matrix(FIG_L);
+        break ; 
+        case PII:
+            copy_matrix(FIG_L2);
+            break;
+            case DOSSE:
+            copy_matrix(FIG_L3);
+            break; 
+        }
         break ;     
     case  S_TYPE: 
-        copy_matrix(FIG_S);
+        switch (ang)
+         {  case NOVEN:
+            copy_matrix(FIG_S1);
+            break;
+            case ZERO:
+            copy_matrix(FIG_S);
+        break ; 
+        case PII:
+            copy_matrix(FIG_S2);
+            break;
+            case DOSSE:
+            copy_matrix(FIG_S3);
+            break; 
+        }
         break ;     
     case  I_TYPE: 
-        copy_matrix(FIG_I);
+        switch (ang)
+         {  case NOVEN:
+            copy_matrix(FIG_I1);
+            break;
+            case ZERO:
+            copy_matrix(FIG_I);
+        break ; 
+        case PII:
+            copy_matrix(FIG_I2);
+            break;
+            case DOSSE:
+            copy_matrix(FIG_I3);
+            break; 
+        }
         break ;     
+    case  C_TYPE: 
+        copy_matrix(FIG_C);
+        break ; 
+    case  T_TYPE:
+         switch (ang)
+         {  case NOVEN:
+            copy_matrix(FIG_T1);
+            break;
+            case ZERO:
+            copy_matrix(FIG_T);
+        break ; 
+        case PII:
+            copy_matrix(FIG_T2);
+            break;
+            case DOSSE:
+            copy_matrix(FIG_T3);
+            break; 
+        }
+        break;
     default: 
         copy_matrix(FIG_NULL);
-        
-    }
-    
-    
+        break;
+        }
+        }
+        else
+        {}
 }
+//desplazamiento horizontal
 void desplazar_fila(){
-     for (int i=0; i<11;i++)
+    for (int i=0; i<8;i++)
         matrix_tmp[i]= matrix_tmp[i]>>1;
     
-}
+    }
+
+
 int main() {
     init_display();
     while(1){
        new_read();
-       for(int i=0;i<8;i++){
+           for(int i=0;i<8;i++){
             desplazar_fila();
             act_matrix(matrix_tmp);
             printMatrix(matrix_act);
             wait_ms(VELOCITY);
-       }   
+       }  
+       } 
     }
-}
-
-
-void debug_m(char *s , ... ){
-    #if DEBUG
-    command.printf(s);
-    #endif  
-}
\ No newline at end of file