Yosef Guevara Salamanca
/
TETS_PC
bien spi no se queda pegado
Diff: tets_pc.cpp
- Revision:
- 1:d99b6299bad8
- Parent:
- 0:4b2603e81763
- Child:
- 2:f9d289ee6b30
--- a/tets_pc.cpp Tue Sep 11 21:09:41 2018 +0000 +++ b/tets_pc.cpp Tue Sep 11 21:40:56 2018 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" - -#define DEBUG 1 +#include "piezas.h" +//#define DEBUG 1 Serial pc(USBTX,USBRX); SPI deviceM(PB_15, PB_14, PB_13); @@ -16,6 +16,7 @@ } + void sendSPI(uint8_t d1, uint8_t d2) { deviceM.unlock(); @@ -25,20 +26,36 @@ ssel=1; deviceM.lock(); }; - void imprimir(){ - // Sele aplica corrmiento a las posiciones del vecteor para facilitar selecccion de la posicion. + + +void captura_matriz(uint16_t* imprimir){ + + + for(int i=0; i<11; i++){ // realiza el desplazamiento de los bits + for (int j= 1; j<=8;j++){ // seleciona la columna a imprimir empezando desde la 1 + sendSPI(j, imprimir[j-1]>>i); + } + wait(1.5); + } - for(int i=0;i<=12;i++) - { - for (int j= 1; j<=8; j++){ - - sendSPI(j,matriz[j-1]>>i); - } - wait(1.0); - } - - } - void mostrar(){ + } + + + void desplazar(uint16_t* datos, char des){ + + uint16_t desplazamiento[8]={0}; + int j= 0; + + for(int i=des; i<(des+3);i++){ + desplazamiento[i]=datos[j]; + j++; + } + captura_matriz(desplazamiento); + + + } + + void read(){ pc.baud(38400); char pos= 0; @@ -53,17 +70,26 @@ switch(figura){ - case 1: - // Cuadrado - switch(giro){ - case 1: case 2: case 3: case 4: - matriz[pos]= 0b11000000000; - matriz[pos+1]=0b11000000000; - imprimir(); - break; + case 0: // L + switch(giro){ + case 0: + desplazar(PZA_T,pos); + break; + case 1: + desplazar(PZA_TN,pos); + + break; + case 2: + desplazar(PZA_TO,pos); + + break; + case 3: + desplazar(PZA_TD, pos); + + break; } break; - case 2: + /*case 2: //T switch(giro){ case 1: @@ -153,9 +179,10 @@ - + */ } + matriz[0]=0; matriz[1]=0; matriz[2]=0; @@ -166,6 +193,7 @@ matriz[7]=0; } + void inicializar(){ sendSPI(0x0c,1); @@ -186,7 +214,7 @@ int main() { inicializar(); while(1){ - mostrar(); + read(); }