Alyson Castiblanco
/
TETRISACT
ok
Fork of 00_01LAB_matrix8x8_fig_tetris1 by
main.cpp
- Committer:
- fabeltranm
- Date:
- 2018-09-04
- Revision:
- 4:2bc5dfe058ef
- Parent:
- 3:4a8de2f71ed0
- Child:
- 5:819f043b99a5
File content as of revision 4:2bc5dfe058ef:
#include "mbed.h" #include "figuras.h" SPI deviceM(PB_15, PB_14, PB_13); DigitalOut ssel (PB_12); Serial command(USBTX, USBRX); #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) { deviceM.unlock(); ssel=0; deviceM.write(d1); deviceM.write(d2); ssel=1; deviceM.lock(); }; void printMatrix(uint8_t* vC) { uint8_t i =0; for (i=1;i<9;i++){ sendSPI(i,*(vC+i-1)); } }; 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 desplazar_fila(){ for (int i=0; i<11;i++) matrix_tmp[i]= matrix_tmp[i]>>1; } 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 debug_m(char *s , ... ){ #if DEBUG command.printf(s); #endif }