NUEVO

Dependencies:   mbed

Fork of 00_01LAB_matrix8x8_fig_tetris by Alyson Castiblanco

Committer:
fabeltranm
Date:
Tue Sep 04 22:31:01 2018 +0000
Revision:
4:2bc5dfe058ef
Parent:
3:4a8de2f71ed0
Child:
5:819f043b99a5
EJEMPLO ENVIO FIGURAS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fabeltranm 0:61199d9d0aed 1
fabeltranm 0:61199d9d0aed 2 #include "mbed.h"
fabeltranm 4:2bc5dfe058ef 3 #include "figuras.h"
fabeltranm 0:61199d9d0aed 4
fabeltranm 0:61199d9d0aed 5 SPI deviceM(PB_15, PB_14, PB_13);
fabeltranm 0:61199d9d0aed 6 DigitalOut ssel (PB_12);
fabeltranm 4:2bc5dfe058ef 7 Serial command(USBTX, USBRX);
fabeltranm 0:61199d9d0aed 8
fabeltranm 4:2bc5dfe058ef 9 #define DEBUG 1
fabeltranm 4:2bc5dfe058ef 10 #define VELOCITY 500 // ms
fabeltranm 1:b732136485e0 11
fabeltranm 4:2bc5dfe058ef 12 void debug_m(char *s , ... );
fabeltranm 4:2bc5dfe058ef 13
fabeltranm 4:2bc5dfe058ef 14 uint8_t matrix_act[8]={0,0,0,0,0,0,0,0};
fabeltranm 4:2bc5dfe058ef 15 uint8_t matrix_tmp[11]={0b10000000,0b10000000,0b11000000,0,0,0,0,0,0,0};
fabeltranm 4:2bc5dfe058ef 16
fabeltranm 0:61199d9d0aed 17
fabeltranm 0:61199d9d0aed 18 void sendSPI(uint8_t d1, uint8_t d2)
fabeltranm 0:61199d9d0aed 19 {
fabeltranm 0:61199d9d0aed 20 deviceM.unlock();
fabeltranm 0:61199d9d0aed 21 ssel=0;
fabeltranm 0:61199d9d0aed 22 deviceM.write(d1);
fabeltranm 0:61199d9d0aed 23 deviceM.write(d2);
fabeltranm 0:61199d9d0aed 24 ssel=1;
fabeltranm 0:61199d9d0aed 25 deviceM.lock();
fabeltranm 0:61199d9d0aed 26 };
fabeltranm 0:61199d9d0aed 27
fabeltranm 0:61199d9d0aed 28
fabeltranm 0:61199d9d0aed 29 void printMatrix(uint8_t* vC)
fabeltranm 0:61199d9d0aed 30
fabeltranm 0:61199d9d0aed 31 {
fabeltranm 0:61199d9d0aed 32 uint8_t i =0;
fabeltranm 0:61199d9d0aed 33 for (i=1;i<9;i++){
fabeltranm 4:2bc5dfe058ef 34 sendSPI(i,*(vC+i-1));
fabeltranm 0:61199d9d0aed 35 }
fabeltranm 0:61199d9d0aed 36
fabeltranm 0:61199d9d0aed 37 };
fabeltranm 2:414129d953dd 38
fabeltranm 4:2bc5dfe058ef 39
fabeltranm 4:2bc5dfe058ef 40
fabeltranm 4:2bc5dfe058ef 41 int init_display(){
fabeltranm 4:2bc5dfe058ef 42 sendSPI(0x0c,1);
fabeltranm 4:2bc5dfe058ef 43 sendSPI(0x0b,7);
fabeltranm 4:2bc5dfe058ef 44 sendSPI(0x09,0);
fabeltranm 4:2bc5dfe058ef 45 sendSPI(0x0A,0x0f);
fabeltranm 4:2bc5dfe058ef 46 printMatrix(matrix_act);
fabeltranm 4:2bc5dfe058ef 47 int i;
fabeltranm 4:2bc5dfe058ef 48 for (i=0;i<2;i++){
fabeltranm 4:2bc5dfe058ef 49 sendSPI(0x0F,1);
fabeltranm 4:2bc5dfe058ef 50 wait (0.5);
fabeltranm 4:2bc5dfe058ef 51 sendSPI(0x0f,0);
fabeltranm 4:2bc5dfe058ef 52 wait (0.5);
fabeltranm 4:2bc5dfe058ef 53 }
fabeltranm 4:2bc5dfe058ef 54 }
fabeltranm 4:2bc5dfe058ef 55
fabeltranm 4:2bc5dfe058ef 56 void act_matrix(uint8_t* mascara){
fabeltranm 4:2bc5dfe058ef 57 for (int i=0; i<8;i++)
fabeltranm 4:2bc5dfe058ef 58 matrix_act[i]= ( *(mascara+i));
fabeltranm 4:2bc5dfe058ef 59
fabeltranm 4:2bc5dfe058ef 60 }
fabeltranm 4:2bc5dfe058ef 61 void copy_matrix(uint8_t* m2){
fabeltranm 4:2bc5dfe058ef 62
fabeltranm 4:2bc5dfe058ef 63 for (int i=0; i<11;i++){
fabeltranm 4:2bc5dfe058ef 64 matrix_tmp[i]= *(m2+i);
fabeltranm 4:2bc5dfe058ef 65 }
fabeltranm 4:2bc5dfe058ef 66 }
fabeltranm 4:2bc5dfe058ef 67
fabeltranm 4:2bc5dfe058ef 68 void new_read(){
fabeltranm 4:2bc5dfe058ef 69 char tf=command.getc();
fabeltranm 4:2bc5dfe058ef 70 switch (tf) {
fabeltranm 4:2bc5dfe058ef 71 case L_TYPE:
fabeltranm 4:2bc5dfe058ef 72 copy_matrix(FIG_L);
fabeltranm 4:2bc5dfe058ef 73 break ;
fabeltranm 4:2bc5dfe058ef 74 case S_TYPE:
fabeltranm 4:2bc5dfe058ef 75 copy_matrix(FIG_S);
fabeltranm 4:2bc5dfe058ef 76 break ;
fabeltranm 4:2bc5dfe058ef 77 case I_TYPE:
fabeltranm 4:2bc5dfe058ef 78 copy_matrix(FIG_I);
fabeltranm 4:2bc5dfe058ef 79 break ;
fabeltranm 4:2bc5dfe058ef 80 default:
fabeltranm 4:2bc5dfe058ef 81 copy_matrix(FIG_NULL);
fabeltranm 4:2bc5dfe058ef 82
fabeltranm 2:414129d953dd 83 }
fabeltranm 0:61199d9d0aed 84
fabeltranm 2:414129d953dd 85
fabeltranm 4:2bc5dfe058ef 86 }
fabeltranm 4:2bc5dfe058ef 87 void desplazar_fila(){
fabeltranm 4:2bc5dfe058ef 88 for (int i=0; i<11;i++)
fabeltranm 4:2bc5dfe058ef 89 matrix_tmp[i]= matrix_tmp[i]>>1;
fabeltranm 3:4a8de2f71ed0 90
fabeltranm 4:2bc5dfe058ef 91 }
fabeltranm 4:2bc5dfe058ef 92 int main() {
fabeltranm 4:2bc5dfe058ef 93 init_display();
fabeltranm 4:2bc5dfe058ef 94 while(1){
fabeltranm 4:2bc5dfe058ef 95 new_read();
fabeltranm 4:2bc5dfe058ef 96 for(int i=0;i<8;i++){
fabeltranm 4:2bc5dfe058ef 97 desplazar_fila();
fabeltranm 4:2bc5dfe058ef 98 act_matrix(matrix_tmp);
fabeltranm 4:2bc5dfe058ef 99 printMatrix(matrix_act);
fabeltranm 4:2bc5dfe058ef 100 wait_ms(VELOCITY);
fabeltranm 4:2bc5dfe058ef 101 }
fabeltranm 4:2bc5dfe058ef 102 }
fabeltranm 2:414129d953dd 103 }
fabeltranm 2:414129d953dd 104
fabeltranm 0:61199d9d0aed 105
fabeltranm 4:2bc5dfe058ef 106 void debug_m(char *s , ... ){
fabeltranm 4:2bc5dfe058ef 107 #if DEBUG
fabeltranm 4:2bc5dfe058ef 108 command.printf(s);
fabeltranm 4:2bc5dfe058ef 109 #endif
fabeltranm 4:2bc5dfe058ef 110 }