Alyson Castiblanco
/
TETRISACT
ok
Fork of 00_01LAB_matrix8x8_fig_tetris1 by
main.cpp@7:0a94835bc6e4, 2018-09-13 (annotated)
- Committer:
- acastiblancoc
- Date:
- Thu Sep 13 11:54:25 2018 +0000
- Revision:
- 7:0a94835bc6e4
- Parent:
- 6:2f42f0b53611
- Child:
- 8:0ddb5ffca870
MATRIX
Who changed what in which revision?
User | Revision | Line number | New 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 |
acastiblancoc | 5:819f043b99a5 | 10 | #define VELOCITY 1000 // ms |
fabeltranm | 1:b732136485e0 | 11 | |
acastiblancoc | 5:819f043b99a5 | 12 | |
fabeltranm | 4:2bc5dfe058ef | 13 | |
fabeltranm | 4:2bc5dfe058ef | 14 | uint8_t matrix_act[8]={0,0,0,0,0,0,0,0}; |
acastiblancoc | 5:819f043b99a5 | 15 | uint8_t matrix_tmp[11]={0b00000000,0b00000000,0b00000000,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 | |
acastiblancoc | 5:819f043b99a5 | 29 | |
acastiblancoc | 5:819f043b99a5 | 30 | |
acastiblancoc | 5:819f043b99a5 | 31 | void debug_m(char *s , ... ){ |
acastiblancoc | 5:819f043b99a5 | 32 | #if DEBUG |
acastiblancoc | 5:819f043b99a5 | 33 | command.printf(s); |
acastiblancoc | 5:819f043b99a5 | 34 | #endif |
acastiblancoc | 5:819f043b99a5 | 35 | } |
acastiblancoc | 5:819f043b99a5 | 36 | |
fabeltranm | 0:61199d9d0aed | 37 | void printMatrix(uint8_t* vC) |
fabeltranm | 0:61199d9d0aed | 38 | |
fabeltranm | 0:61199d9d0aed | 39 | { |
fabeltranm | 0:61199d9d0aed | 40 | uint8_t i =0; |
fabeltranm | 0:61199d9d0aed | 41 | for (i=1;i<9;i++){ |
fabeltranm | 4:2bc5dfe058ef | 42 | sendSPI(i,*(vC+i-1)); |
fabeltranm | 0:61199d9d0aed | 43 | } |
fabeltranm | 0:61199d9d0aed | 44 | |
acastiblancoc | 5:819f043b99a5 | 45 | } |
fabeltranm | 2:414129d953dd | 46 | |
fabeltranm | 4:2bc5dfe058ef | 47 | |
acastiblancoc | 5:819f043b99a5 | 48 | void init_display(){ |
fabeltranm | 4:2bc5dfe058ef | 49 | sendSPI(0x0c,1); |
fabeltranm | 4:2bc5dfe058ef | 50 | sendSPI(0x0b,7); |
fabeltranm | 4:2bc5dfe058ef | 51 | sendSPI(0x09,0); |
acastiblancoc | 5:819f043b99a5 | 52 | sendSPI(0x0A,0x0E); |
fabeltranm | 4:2bc5dfe058ef | 53 | printMatrix(matrix_act); |
fabeltranm | 4:2bc5dfe058ef | 54 | int i; |
acastiblancoc | 5:819f043b99a5 | 55 | for (i=0;i<4;i++){ |
fabeltranm | 4:2bc5dfe058ef | 56 | sendSPI(0x0F,1); |
acastiblancoc | 5:819f043b99a5 | 57 | wait (0.2); |
fabeltranm | 4:2bc5dfe058ef | 58 | sendSPI(0x0f,0); |
acastiblancoc | 5:819f043b99a5 | 59 | wait (0.2); |
fabeltranm | 4:2bc5dfe058ef | 60 | } |
acastiblancoc | 5:819f043b99a5 | 61 | } |
acastiblancoc | 5:819f043b99a5 | 62 | |
acastiblancoc | 5:819f043b99a5 | 63 | |
acastiblancoc | 5:819f043b99a5 | 64 | |
fabeltranm | 4:2bc5dfe058ef | 65 | |
fabeltranm | 4:2bc5dfe058ef | 66 | void act_matrix(uint8_t* mascara){ |
fabeltranm | 4:2bc5dfe058ef | 67 | for (int i=0; i<8;i++) |
fabeltranm | 4:2bc5dfe058ef | 68 | matrix_act[i]= ( *(mascara+i)); |
fabeltranm | 4:2bc5dfe058ef | 69 | |
fabeltranm | 4:2bc5dfe058ef | 70 | } |
acastiblancoc | 5:819f043b99a5 | 71 | void copy_matrix(uint8_t* m2, char col){ |
fabeltranm | 4:2bc5dfe058ef | 72 | |
fabeltranm | 4:2bc5dfe058ef | 73 | for (int i=0; i<11;i++){ |
acastiblancoc | 6:2f42f0b53611 | 74 | matrix_tmp[i]= (*(m2+i)>>(col-1)); |
fabeltranm | 4:2bc5dfe058ef | 75 | } |
fabeltranm | 4:2bc5dfe058ef | 76 | } |
acastiblancoc | 7:0a94835bc6e4 | 77 | |
acastiblancoc | 7:0a94835bc6e4 | 78 | |
acastiblancoc | 5:819f043b99a5 | 79 | |
fabeltranm | 4:2bc5dfe058ef | 80 | void new_read(){ |
acastiblancoc | 5:819f043b99a5 | 81 | |
acastiblancoc | 5:819f043b99a5 | 82 | char ini=command.getc(); |
fabeltranm | 4:2bc5dfe058ef | 83 | char tf=command.getc(); |
acastiblancoc | 5:819f043b99a5 | 84 | char ang=command.getc(); |
acastiblancoc | 5:819f043b99a5 | 85 | char col=command.getc(); |
acastiblancoc | 5:819f043b99a5 | 86 | char fin=command.getc(); |
acastiblancoc | 5:819f043b99a5 | 87 | if(ini==0x3C && fin==0x3E) |
acastiblancoc | 5:819f043b99a5 | 88 | { |
fabeltranm | 4:2bc5dfe058ef | 89 | switch (tf) { |
fabeltranm | 4:2bc5dfe058ef | 90 | case L_TYPE: |
acastiblancoc | 5:819f043b99a5 | 91 | switch (ang) |
acastiblancoc | 5:819f043b99a5 | 92 | { case NOVEN: |
acastiblancoc | 6:2f42f0b53611 | 93 | switch(col) |
acastiblancoc | 6:2f42f0b53611 | 94 | {case 1: |
acastiblancoc | 6:2f42f0b53611 | 95 | copy_matrix(FIG_L1,1); |
acastiblancoc | 6:2f42f0b53611 | 96 | break; |
acastiblancoc | 6:2f42f0b53611 | 97 | case 2: |
acastiblancoc | 6:2f42f0b53611 | 98 | copy_matrix(FIG_L1,2); |
acastiblancoc | 6:2f42f0b53611 | 99 | break; |
acastiblancoc | 6:2f42f0b53611 | 100 | case 3: |
acastiblancoc | 6:2f42f0b53611 | 101 | copy_matrix(FIG_L1,3); |
acastiblancoc | 6:2f42f0b53611 | 102 | break; |
acastiblancoc | 6:2f42f0b53611 | 103 | case 4: |
acastiblancoc | 6:2f42f0b53611 | 104 | copy_matrix(FIG_L1,4); |
acastiblancoc | 6:2f42f0b53611 | 105 | break; |
acastiblancoc | 6:2f42f0b53611 | 106 | case 5: |
acastiblancoc | 6:2f42f0b53611 | 107 | copy_matrix(FIG_L1,5); |
acastiblancoc | 6:2f42f0b53611 | 108 | break; |
acastiblancoc | 6:2f42f0b53611 | 109 | case 6: |
acastiblancoc | 6:2f42f0b53611 | 110 | copy_matrix(FIG_L1,6); |
acastiblancoc | 6:2f42f0b53611 | 111 | break; |
acastiblancoc | 6:2f42f0b53611 | 112 | case 7: |
acastiblancoc | 6:2f42f0b53611 | 113 | copy_matrix(FIG_L1,7); |
acastiblancoc | 6:2f42f0b53611 | 114 | break; |
acastiblancoc | 6:2f42f0b53611 | 115 | case 8: |
acastiblancoc | 6:2f42f0b53611 | 116 | copy_matrix(FIG_L1,8); |
acastiblancoc | 6:2f42f0b53611 | 117 | break; |
acastiblancoc | 6:2f42f0b53611 | 118 | } |
acastiblancoc | 5:819f043b99a5 | 119 | break; |
acastiblancoc | 5:819f043b99a5 | 120 | case ZERO: |
acastiblancoc | 6:2f42f0b53611 | 121 | copy_matrix(FIG_L,1); |
acastiblancoc | 5:819f043b99a5 | 122 | break ; |
acastiblancoc | 5:819f043b99a5 | 123 | case PII: |
acastiblancoc | 6:2f42f0b53611 | 124 | copy_matrix(FIG_L2,1); |
acastiblancoc | 5:819f043b99a5 | 125 | break; |
acastiblancoc | 5:819f043b99a5 | 126 | case DOSSE: |
acastiblancoc | 6:2f42f0b53611 | 127 | copy_matrix(FIG_L3,1); |
acastiblancoc | 5:819f043b99a5 | 128 | break; |
acastiblancoc | 5:819f043b99a5 | 129 | } |
acastiblancoc | 6:2f42f0b53611 | 130 | break ; |
fabeltranm | 4:2bc5dfe058ef | 131 | case S_TYPE: |
acastiblancoc | 5:819f043b99a5 | 132 | switch (ang) |
acastiblancoc | 5:819f043b99a5 | 133 | { case NOVEN: |
acastiblancoc | 6:2f42f0b53611 | 134 | copy_matrix(FIG_S1,1); |
acastiblancoc | 5:819f043b99a5 | 135 | break; |
acastiblancoc | 5:819f043b99a5 | 136 | case ZERO: |
acastiblancoc | 6:2f42f0b53611 | 137 | copy_matrix(FIG_S,1); |
acastiblancoc | 5:819f043b99a5 | 138 | break ; |
acastiblancoc | 5:819f043b99a5 | 139 | case PII: |
acastiblancoc | 6:2f42f0b53611 | 140 | copy_matrix(FIG_S2,1); |
acastiblancoc | 5:819f043b99a5 | 141 | break; |
acastiblancoc | 5:819f043b99a5 | 142 | case DOSSE: |
acastiblancoc | 6:2f42f0b53611 | 143 | copy_matrix(FIG_S3,1); |
acastiblancoc | 5:819f043b99a5 | 144 | break; |
acastiblancoc | 5:819f043b99a5 | 145 | } |
fabeltranm | 4:2bc5dfe058ef | 146 | break ; |
fabeltranm | 4:2bc5dfe058ef | 147 | case I_TYPE: |
acastiblancoc | 5:819f043b99a5 | 148 | switch (ang) |
acastiblancoc | 5:819f043b99a5 | 149 | { case NOVEN: |
acastiblancoc | 6:2f42f0b53611 | 150 | copy_matrix(FIG_I1,1); |
acastiblancoc | 5:819f043b99a5 | 151 | break; |
acastiblancoc | 5:819f043b99a5 | 152 | case ZERO: |
acastiblancoc | 6:2f42f0b53611 | 153 | copy_matrix(FIG_I,1); |
acastiblancoc | 5:819f043b99a5 | 154 | break ; |
acastiblancoc | 5:819f043b99a5 | 155 | case PII: |
acastiblancoc | 6:2f42f0b53611 | 156 | copy_matrix(FIG_I2,1); |
acastiblancoc | 5:819f043b99a5 | 157 | break; |
acastiblancoc | 5:819f043b99a5 | 158 | case DOSSE: |
acastiblancoc | 6:2f42f0b53611 | 159 | copy_matrix(FIG_I3,1); |
acastiblancoc | 5:819f043b99a5 | 160 | break; |
acastiblancoc | 5:819f043b99a5 | 161 | } |
fabeltranm | 4:2bc5dfe058ef | 162 | break ; |
acastiblancoc | 5:819f043b99a5 | 163 | case C_TYPE: |
acastiblancoc | 6:2f42f0b53611 | 164 | copy_matrix(FIG_C,1); |
acastiblancoc | 5:819f043b99a5 | 165 | break ; |
acastiblancoc | 5:819f043b99a5 | 166 | case T_TYPE: |
acastiblancoc | 5:819f043b99a5 | 167 | switch (ang) |
acastiblancoc | 5:819f043b99a5 | 168 | { case NOVEN: |
acastiblancoc | 6:2f42f0b53611 | 169 | copy_matrix(FIG_T1,1); |
acastiblancoc | 5:819f043b99a5 | 170 | break; |
acastiblancoc | 5:819f043b99a5 | 171 | case ZERO: |
acastiblancoc | 6:2f42f0b53611 | 172 | copy_matrix(FIG_T,1); |
acastiblancoc | 5:819f043b99a5 | 173 | break ; |
acastiblancoc | 5:819f043b99a5 | 174 | case PII: |
acastiblancoc | 6:2f42f0b53611 | 175 | copy_matrix(FIG_T2,1); |
acastiblancoc | 5:819f043b99a5 | 176 | break; |
acastiblancoc | 5:819f043b99a5 | 177 | case DOSSE: |
acastiblancoc | 6:2f42f0b53611 | 178 | copy_matrix(FIG_T3,1); |
acastiblancoc | 5:819f043b99a5 | 179 | break; |
acastiblancoc | 5:819f043b99a5 | 180 | } |
acastiblancoc | 5:819f043b99a5 | 181 | break; |
fabeltranm | 4:2bc5dfe058ef | 182 | default: |
acastiblancoc | 6:2f42f0b53611 | 183 | copy_matrix(FIG_NULL,1); |
acastiblancoc | 5:819f043b99a5 | 184 | break; |
acastiblancoc | 5:819f043b99a5 | 185 | } |
acastiblancoc | 5:819f043b99a5 | 186 | } |
acastiblancoc | 5:819f043b99a5 | 187 | else |
acastiblancoc | 5:819f043b99a5 | 188 | {} |
fabeltranm | 4:2bc5dfe058ef | 189 | } |
acastiblancoc | 5:819f043b99a5 | 190 | //desplazamiento horizontal |
fabeltranm | 4:2bc5dfe058ef | 191 | void desplazar_fila(){ |
acastiblancoc | 5:819f043b99a5 | 192 | for (int i=0; i<8;i++) |
fabeltranm | 4:2bc5dfe058ef | 193 | matrix_tmp[i]= matrix_tmp[i]>>1; |
fabeltranm | 3:4a8de2f71ed0 | 194 | |
acastiblancoc | 5:819f043b99a5 | 195 | } |
acastiblancoc | 5:819f043b99a5 | 196 | |
acastiblancoc | 5:819f043b99a5 | 197 | |
fabeltranm | 4:2bc5dfe058ef | 198 | int main() { |
fabeltranm | 4:2bc5dfe058ef | 199 | init_display(); |
fabeltranm | 4:2bc5dfe058ef | 200 | while(1){ |
fabeltranm | 4:2bc5dfe058ef | 201 | new_read(); |
acastiblancoc | 5:819f043b99a5 | 202 | for(int i=0;i<8;i++){ |
fabeltranm | 4:2bc5dfe058ef | 203 | act_matrix(matrix_tmp); |
fabeltranm | 4:2bc5dfe058ef | 204 | printMatrix(matrix_act); |
acastiblancoc | 7:0a94835bc6e4 | 205 | for (int j=0;j<8;j++){ |
acastiblancoc | 7:0a94835bc6e4 | 206 | matrix_act[j+3]=matrix_act[j+2]; |
acastiblancoc | 7:0a94835bc6e4 | 207 | matrix_act[j+2]=matrix_act[j+1]; |
acastiblancoc | 7:0a94835bc6e4 | 208 | matrix_act[j]=0; |
acastiblancoc | 7:0a94835bc6e4 | 209 | |
acastiblancoc | 6:2f42f0b53611 | 210 | //desplazar_fila(); |
fabeltranm | 4:2bc5dfe058ef | 211 | wait_ms(VELOCITY); |
acastiblancoc | 5:819f043b99a5 | 212 | } |
acastiblancoc | 7:0a94835bc6e4 | 213 | |
acastiblancoc | 7:0a94835bc6e4 | 214 | } |
acastiblancoc | 5:819f043b99a5 | 215 | } |
fabeltranm | 4:2bc5dfe058ef | 216 | } |