NUEVO

Dependencies:   mbed

Fork of 00_01LAB_matrix8x8_fig_tetris by Alyson Castiblanco

Revision:
4:2bc5dfe058ef
Parent:
3:4a8de2f71ed0
Child:
5:819f043b99a5
diff -r 4a8de2f71ed0 -r 2bc5dfe058ef main.cpp
--- a/main.cpp	Thu Mar 16 22:56:47 2017 +0000
+++ b/main.cpp	Tue Sep 04 22:31:01 2018 +0000
@@ -1,16 +1,19 @@
 
 #include "mbed.h"
-//#include "max7219.h"
+#include "figuras.h"
 
-// ***************************************************************************
-// option 1 : use  SPI
-// ***************************************************************************
 SPI deviceM(PB_15, PB_14, PB_13);
 DigitalOut ssel (PB_12);
+Serial command(USBTX, USBRX);
 
-#define  uint8_t unsigned char
-uint8_t vcol2[8]={0,0,0,0,0,0,0,0};
+#define DEBUG 1
+#define  VELOCITY 500 // 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};
+  
  
 void sendSPI(uint8_t d1, uint8_t d2)
 {
@@ -28,115 +31,80 @@
 {
     uint8_t i =0;
     for (i=1;i<9;i++){
-        sendSPI(i,*(vC+i));
+        sendSPI(i,*(vC+i-1));
     }
         
     };
 
-void clr_vcol()
-    {
-    for (int i=0; i<8;i++){
-            vcol2[i]=0;
+
+
+int init_display(){
+    sendSPI(0x0c,1);
+    sendSPI(0x0b,7);
+    sendSPI(0x09,0);
+    sendSPI(0x0A,0x0f);
+    printMatrix(matrix_act);
+    int i;
+    for (i=0;i<2;i++){
+        sendSPI(0x0F,1);
+        wait (0.5);
+        sendSPI(0x0f,0);
+        wait (0.5);
+    }
+ }
+ 
+void act_matrix(uint8_t*  mascara){ 
+    for (int i=0; i<8;i++)
+        matrix_act[i]=  ( *(mascara+i));
+ 
+ } 
+ void copy_matrix(uint8_t*  m2){
+  
+    for (int i=0; i<11;i++){
+        matrix_tmp[i]=  *(m2+i);
+    }
+ } 
+
+void new_read(){
+    char tf=command.getc();
+    switch (tf) {
+    case  L_TYPE: 
+        copy_matrix(FIG_L);
+        break ;     
+    case  S_TYPE: 
+        copy_matrix(FIG_S);
+        break ;     
+    case  I_TYPE: 
+        copy_matrix(FIG_I);
+        break ;     
+    default: 
+        copy_matrix(FIG_NULL);
+        
     }
     
-}   
- 
-void print_Snake2()
-{
     
-    int j, i;
-      //reset
+}
+void desplazar_fila(){
+     for (int i=0; i<11;i++)
+        matrix_tmp[i]= matrix_tmp[i]>>1;
     
-    for (j=0; j<8;j++){
-        clr_vcol();
-        if(j % 2 == 0)
-            vcol2[j]=1;
-        else
-            vcol2[j]=0b10000000;
-    
-        for (i=0; i<8;i++){
-            if(j % 2 == 0){
-                 vcol2[j]=3<<i;
-                }
-            else{
-                 vcol2[j]=0b1100000000>>i;
-                }
-            printMatrix(vcol2);
-            wait_ms(5);
-            }
-        }
+}
+int main() {
+    init_display();
+    while(1){
+       new_read();
+       for(int i=0;i<8;i++){
+            desplazar_fila();
+            act_matrix(matrix_tmp);
+            printMatrix(matrix_act);
+            wait_ms(VELOCITY);
+       }   
+    }
 }
 
-void print_Snake()
-{
-       
-    uint8_t vt1[8]={1,3,7,0xf,0x1f,0x3f, 0x7f,0xff};
-    uint8_t vt2[8]={0b10000000,0b11000000,0b11100000,0b11110000,0b11111000,0b11111100,0b11111110,0b11111111};
-    
-      
-    int j, i;
-      //reset
-    clr_vcol();
-    for (j=0; j<8;j++){
-        for (i=0; i<8;i++){
-            if(j % 2 == 0){
-                vcol2[j]=vt1[i];
-            }else{
-                vcol2[j]=vt2[i];
-            }
-            printMatrix(vcol2);
-            wait_ms(5);
-        }
-        }    
-}   
-int main() {
-                    uint8_t vcol[8]={0,0,0,0,0,0,0,0};
-                    sendSPI(0x0c,1);
-                    sendSPI(0x0F,1);
-                    wait (0.1);
-                    sendSPI(0x0f,0);
-                    wait (0.1);
-                    int i =0;
-                    while(1){
-                        print_Snake();
-                        }
-}
-// ***************************************************************************
-// option two: use maz7219 library
 
-// ***************************************************************************    
-/*
-Max7219 deviceM(PB_15, PB_14, PB_13, PB_12);
-
-
-int main() {
-    
-    max7219_configuration_t cfg = {
-    .device_number = 1,
-    .decode_mode = 0,
-    .intensity = Max7219::MAX7219_INTENSITY_8,
-    .scan_limit = Max7219::MAX7219_SCAN_8
-};
-   
-    deviceM.init_device(cfg);
-    
-    deviceM.enable_device(1);
-   
-    deviceM.set_display_test();
-    wait(1);   
-   deviceM.clear_display_test();
-    wait(1);
-  
-    while(1){
-         deviceM.write_digit(1,8,0b11111111);
-         deviceM.write_digit(1,1,0b01010101);
-         deviceM.write_digit(1,2,0b10101010);
-         deviceM.write_digit(1,3,0b01010101);
-         deviceM.write_digit(1,4,0b10101010);
-         deviceM.write_digit(1,5,0b01010101);
-         deviceM.write_digit(1,6,0b10101010);
-         deviceM.write_digit(1,7,0b01010101);
-        }
-}
-*/
-
+void debug_m(char *s , ... ){
+    #if DEBUG
+    command.printf(s);
+    #endif  
+}
\ No newline at end of file