NUEVO

Dependencies:   mbed

Fork of 00_01LAB_matrix8x8_fig_tetris by Alyson Castiblanco

Committer:
acastiblancoc
Date:
Wed Sep 12 18:27:06 2018 +0000
Revision:
6:2f42f0b53611
Parent:
5:819f043b99a5
Child:
7:0a94835bc6e4
ok

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
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 6:2f42f0b53611 77 void colum(){
acastiblancoc 6:2f42f0b53611 78 for (int i=0;i<7;i++){
acastiblancoc 6:2f42f0b53611 79 sendSPI(i-1,0);
acastiblancoc 6:2f42f0b53611 80 sendSPI(i,temp+i);
acastiblancoc 6:2f42f0b53611 81 }
acastiblancoc 6:2f42f0b53611 82 }
acastiblancoc 5:819f043b99a5 83
fabeltranm 4:2bc5dfe058ef 84 void new_read(){
acastiblancoc 5:819f043b99a5 85
acastiblancoc 5:819f043b99a5 86 char ini=command.getc();
fabeltranm 4:2bc5dfe058ef 87 char tf=command.getc();
acastiblancoc 5:819f043b99a5 88 char ang=command.getc();
acastiblancoc 5:819f043b99a5 89 char col=command.getc();
acastiblancoc 5:819f043b99a5 90 char fin=command.getc();
acastiblancoc 5:819f043b99a5 91 if(ini==0x3C && fin==0x3E)
acastiblancoc 5:819f043b99a5 92 {
fabeltranm 4:2bc5dfe058ef 93 switch (tf) {
fabeltranm 4:2bc5dfe058ef 94 case L_TYPE:
acastiblancoc 5:819f043b99a5 95 switch (ang)
acastiblancoc 5:819f043b99a5 96 { case NOVEN:
acastiblancoc 6:2f42f0b53611 97 switch(col)
acastiblancoc 6:2f42f0b53611 98 {case 1:
acastiblancoc 6:2f42f0b53611 99 copy_matrix(FIG_L1,1);
acastiblancoc 6:2f42f0b53611 100 break;
acastiblancoc 6:2f42f0b53611 101 case 2:
acastiblancoc 6:2f42f0b53611 102 copy_matrix(FIG_L1,2);
acastiblancoc 6:2f42f0b53611 103 break;
acastiblancoc 6:2f42f0b53611 104 case 3:
acastiblancoc 6:2f42f0b53611 105 copy_matrix(FIG_L1,3);
acastiblancoc 6:2f42f0b53611 106 break;
acastiblancoc 6:2f42f0b53611 107 case 4:
acastiblancoc 6:2f42f0b53611 108 copy_matrix(FIG_L1,4);
acastiblancoc 6:2f42f0b53611 109 break;
acastiblancoc 6:2f42f0b53611 110 case 5:
acastiblancoc 6:2f42f0b53611 111 copy_matrix(FIG_L1,5);
acastiblancoc 6:2f42f0b53611 112 break;
acastiblancoc 6:2f42f0b53611 113 case 6:
acastiblancoc 6:2f42f0b53611 114 copy_matrix(FIG_L1,6);
acastiblancoc 6:2f42f0b53611 115 break;
acastiblancoc 6:2f42f0b53611 116 case 7:
acastiblancoc 6:2f42f0b53611 117 copy_matrix(FIG_L1,7);
acastiblancoc 6:2f42f0b53611 118 break;
acastiblancoc 6:2f42f0b53611 119 case 8:
acastiblancoc 6:2f42f0b53611 120 copy_matrix(FIG_L1,8);
acastiblancoc 6:2f42f0b53611 121 break;
acastiblancoc 6:2f42f0b53611 122 }
acastiblancoc 5:819f043b99a5 123 break;
acastiblancoc 5:819f043b99a5 124 case ZERO:
acastiblancoc 6:2f42f0b53611 125 copy_matrix(FIG_L,1);
acastiblancoc 5:819f043b99a5 126 break ;
acastiblancoc 5:819f043b99a5 127 case PII:
acastiblancoc 6:2f42f0b53611 128 copy_matrix(FIG_L2,1);
acastiblancoc 5:819f043b99a5 129 break;
acastiblancoc 5:819f043b99a5 130 case DOSSE:
acastiblancoc 6:2f42f0b53611 131 copy_matrix(FIG_L3,1);
acastiblancoc 5:819f043b99a5 132 break;
acastiblancoc 5:819f043b99a5 133 }
acastiblancoc 6:2f42f0b53611 134 break ;
fabeltranm 4:2bc5dfe058ef 135 case S_TYPE:
acastiblancoc 5:819f043b99a5 136 switch (ang)
acastiblancoc 5:819f043b99a5 137 { case NOVEN:
acastiblancoc 6:2f42f0b53611 138 copy_matrix(FIG_S1,1);
acastiblancoc 5:819f043b99a5 139 break;
acastiblancoc 5:819f043b99a5 140 case ZERO:
acastiblancoc 6:2f42f0b53611 141 copy_matrix(FIG_S,1);
acastiblancoc 5:819f043b99a5 142 break ;
acastiblancoc 5:819f043b99a5 143 case PII:
acastiblancoc 6:2f42f0b53611 144 copy_matrix(FIG_S2,1);
acastiblancoc 5:819f043b99a5 145 break;
acastiblancoc 5:819f043b99a5 146 case DOSSE:
acastiblancoc 6:2f42f0b53611 147 copy_matrix(FIG_S3,1);
acastiblancoc 5:819f043b99a5 148 break;
acastiblancoc 5:819f043b99a5 149 }
fabeltranm 4:2bc5dfe058ef 150 break ;
fabeltranm 4:2bc5dfe058ef 151 case I_TYPE:
acastiblancoc 5:819f043b99a5 152 switch (ang)
acastiblancoc 5:819f043b99a5 153 { case NOVEN:
acastiblancoc 6:2f42f0b53611 154 copy_matrix(FIG_I1,1);
acastiblancoc 5:819f043b99a5 155 break;
acastiblancoc 5:819f043b99a5 156 case ZERO:
acastiblancoc 6:2f42f0b53611 157 copy_matrix(FIG_I,1);
acastiblancoc 5:819f043b99a5 158 break ;
acastiblancoc 5:819f043b99a5 159 case PII:
acastiblancoc 6:2f42f0b53611 160 copy_matrix(FIG_I2,1);
acastiblancoc 5:819f043b99a5 161 break;
acastiblancoc 5:819f043b99a5 162 case DOSSE:
acastiblancoc 6:2f42f0b53611 163 copy_matrix(FIG_I3,1);
acastiblancoc 5:819f043b99a5 164 break;
acastiblancoc 5:819f043b99a5 165 }
fabeltranm 4:2bc5dfe058ef 166 break ;
acastiblancoc 5:819f043b99a5 167 case C_TYPE:
acastiblancoc 6:2f42f0b53611 168 copy_matrix(FIG_C,1);
acastiblancoc 5:819f043b99a5 169 break ;
acastiblancoc 5:819f043b99a5 170 case T_TYPE:
acastiblancoc 5:819f043b99a5 171 switch (ang)
acastiblancoc 5:819f043b99a5 172 { case NOVEN:
acastiblancoc 6:2f42f0b53611 173 copy_matrix(FIG_T1,1);
acastiblancoc 5:819f043b99a5 174 break;
acastiblancoc 5:819f043b99a5 175 case ZERO:
acastiblancoc 6:2f42f0b53611 176 copy_matrix(FIG_T,1);
acastiblancoc 5:819f043b99a5 177 break ;
acastiblancoc 5:819f043b99a5 178 case PII:
acastiblancoc 6:2f42f0b53611 179 copy_matrix(FIG_T2,1);
acastiblancoc 5:819f043b99a5 180 break;
acastiblancoc 5:819f043b99a5 181 case DOSSE:
acastiblancoc 6:2f42f0b53611 182 copy_matrix(FIG_T3,1);
acastiblancoc 5:819f043b99a5 183 break;
acastiblancoc 5:819f043b99a5 184 }
acastiblancoc 5:819f043b99a5 185 break;
fabeltranm 4:2bc5dfe058ef 186 default:
acastiblancoc 6:2f42f0b53611 187 copy_matrix(FIG_NULL,1);
acastiblancoc 5:819f043b99a5 188 break;
acastiblancoc 5:819f043b99a5 189 }
acastiblancoc 5:819f043b99a5 190 }
acastiblancoc 5:819f043b99a5 191 else
acastiblancoc 5:819f043b99a5 192 {}
fabeltranm 4:2bc5dfe058ef 193 }
acastiblancoc 5:819f043b99a5 194 //desplazamiento horizontal
fabeltranm 4:2bc5dfe058ef 195 void desplazar_fila(){
acastiblancoc 5:819f043b99a5 196 for (int i=0; i<8;i++)
fabeltranm 4:2bc5dfe058ef 197 matrix_tmp[i]= matrix_tmp[i]>>1;
fabeltranm 3:4a8de2f71ed0 198
acastiblancoc 5:819f043b99a5 199 }
acastiblancoc 5:819f043b99a5 200
acastiblancoc 5:819f043b99a5 201
fabeltranm 4:2bc5dfe058ef 202 int main() {
fabeltranm 4:2bc5dfe058ef 203 init_display();
fabeltranm 4:2bc5dfe058ef 204 while(1){
fabeltranm 4:2bc5dfe058ef 205 new_read();
acastiblancoc 5:819f043b99a5 206 for(int i=0;i<8;i++){
fabeltranm 4:2bc5dfe058ef 207 act_matrix(matrix_tmp);
fabeltranm 4:2bc5dfe058ef 208 printMatrix(matrix_act);
acastiblancoc 6:2f42f0b53611 209 //desplazar_fila();
fabeltranm 4:2bc5dfe058ef 210 wait_ms(VELOCITY);
acastiblancoc 5:819f043b99a5 211 }
acastiblancoc 5:819f043b99a5 212 }
fabeltranm 4:2bc5dfe058ef 213 }