Switch con SPI terminado

Dependencies:   mbed

Revision:
0:116c0226508c
Child:
1:b1870397ef59
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tetris.cpp	Tue Sep 11 02:02:37 2018 +0000
@@ -0,0 +1,146 @@
+#include "mbed.h"
+#include "piezas.h"
+
+SPI deviceM(PB_15, PB_14, PB_13);
+DigitalOut ssel (PB_12);
+ 
+void sendSPI(uint8_t d1, uint8_t d2)
+{
+    deviceM.unlock();
+    ssel=0;
+    deviceM.write(d1); 
+    deviceM.write(d2);  
+    ssel=1;
+    deviceM.lock();
+};
+ 
+void inicializar_matriz(){
+    sendSPI(0x0c,1);
+    sendSPI(0x0b,7);
+    sendSPI(0x09,0);
+    sendSPI(0x0A,0x0f);
+    int i;
+    for (i=0;i<2;i++){
+        sendSPI(0x0F,1);
+        wait (0.5);
+        sendSPI(0x0f,0);
+        wait (0.5);
+    }
+  
+  }
+  
+int main() {
+                   
+   inicializar_matriz();
+   
+while(1){
+       
+       read_in(); // Llama a la funcion de lectura de los valores de entrada
+
+       
+         
+                       
+  }
+    
+}
+
+void captura_matriz(){
+    
+    
+    }
+
+void read_in(){
+         
+         // Seleccion de lugar. figura y giro
+         char pos    = 0;
+         char figura = 0;
+         char giro   = 0;
+    
+         switch(figura){
+             case 0:
+                   switch(giro){
+                       case 0:
+                       captura_matriz(PZA_LD);
+                             break;
+                       case 1:
+                       captura_matriz(PZA_LDN);
+                             break;
+                       case 2:
+                       captura_matriz(PZA_LDO);
+                             break;
+                       case 3:
+                       captura_matriz(PZA_LDD);
+                             break;
+                       default:
+                       captura_matriz(VACIO);
+                             break;             
+                       }
+                   break;
+             case 1:
+                   switch(giro){
+                       case 0:
+                       captura_matriz(PZA_T);
+                             break;
+                       case 1:
+                       captura_matriz(PZA_TN);
+                             break;
+                       case 2:
+                       captura_matriz(PZA_TO);
+                             break;
+                       case 3:
+                       captura_matriz(PZA_TD);
+                             break;
+                       default:
+                       captura_matriz(VACIO);
+                             break;             
+                       }
+                   break;      
+             case 2:
+                   switch(giro){
+                       case 0: case 2:
+                       captura_matriz(PZA_I);
+                             break;
+                       case 1: case 3:
+                       captura_matriz(PZA_IR);
+                             break;
+                       default:
+                       captura_matriz(VACIO);
+                             break;             
+                       }
+                   break;
+             case 3:
+                   switch(giro){
+                       case 0: case 1: case 2: case 3:
+                       captura_matriz(PZA_C);
+                             break;
+                       default:
+                       captura_matriz(VACIO);
+                             break;             
+                       }
+                   break;
+             case 4:
+                   switch(giro){
+                       case 0:
+                       captura_matriz(PZA_Z);
+                             break;
+                       case 1:
+                       captura_matriz(PZA_ZN);
+                             break;
+                       case 2:
+                       captura_matriz(PZA_ZO);
+                             break;
+                       case 3:
+                       captura_matriz(PZA_ZD);
+                             break;
+                       default:
+                       captura_matriz(VACIO);
+                             break;             
+                       }
+                   break;      
+             default:
+             captura_matriz(VACIO);
+                    break; 
+
+             }
+
+    }
\ No newline at end of file