Código simplificado, grados, funciona detencion filas, columna falta.
Fork of moggo by
moggo.cpp@0:3a60cf1c28ca, 2018-09-06 (annotated)
- Committer:
- jiuk
- Date:
- Thu Sep 06 21:58:40 2018 +0000
- Revision:
- 0:3a60cf1c28ca
- Child:
- 1:78d5142da831
Intercambio de piezas, bajan pero sin parar, faltan los grados y salir de una columna determinada.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jiuk | 0:3a60cf1c28ca | 1 | #include "mbed.h" |
jiuk | 0:3a60cf1c28ca | 2 | #include "moggo.h" //agrega la libreria que contiene las figuras. |
jiuk | 0:3a60cf1c28ca | 3 | |
jiuk | 0:3a60cf1c28ca | 4 | SPI deviceM(PB_5, PB_4, PB_3); //define el Clock, Dato salida (miso) y Dato de entrada (mosi). |
jiuk | 0:3a60cf1c28ca | 5 | DigitalOut ssel (PB_9); //Chip Select para el controlador. |
jiuk | 0:3a60cf1c28ca | 6 | Serial command(USBTX,USBRX); //habilitar la comunicacion serial a traves del puerto usb. |
jiuk | 0:3a60cf1c28ca | 7 | |
jiuk | 0:3a60cf1c28ca | 8 | #define VEL 500 //Velocidad de actualizacion de dato en el controlador. |
jiuk | 0:3a60cf1c28ca | 9 | |
jiuk | 0:3a60cf1c28ca | 10 | void debug_m(char *s , ... ); //depurador de errores, probador. |
jiuk | 0:3a60cf1c28ca | 11 | |
jiuk | 0:3a60cf1c28ca | 12 | uint8_t mat_act[8]={0,0,0,0,0,0,0,0}; //Matriz para mostrar en pantalla. |
jiuk | 0:3a60cf1c28ca | 13 | uint8_t mat_tmp[11]={0b10000000,0b10000000,0b11000000,0,0,0,0,0,0,0}; //Matriz temporal para arrojar las fichas. |
jiuk | 0:3a60cf1c28ca | 14 | |
jiuk | 0:3a60cf1c28ca | 15 | |
jiuk | 0:3a60cf1c28ca | 16 | void sendSPI(uint8_t d1, uint8_t d2) |
jiuk | 0:3a60cf1c28ca | 17 | { |
jiuk | 0:3a60cf1c28ca | 18 | deviceM.unlock(); |
jiuk | 0:3a60cf1c28ca | 19 | ssel=0; |
jiuk | 0:3a60cf1c28ca | 20 | deviceM.write(d1); |
jiuk | 0:3a60cf1c28ca | 21 | deviceM.write(d2); |
jiuk | 0:3a60cf1c28ca | 22 | ssel=1; |
jiuk | 0:3a60cf1c28ca | 23 | deviceM.lock(); |
jiuk | 0:3a60cf1c28ca | 24 | } |
jiuk | 0:3a60cf1c28ca | 25 | |
jiuk | 0:3a60cf1c28ca | 26 | void test() //test |
jiuk | 0:3a60cf1c28ca | 27 | { |
jiuk | 0:3a60cf1c28ca | 28 | sendSPI(0x09,0); //no decodificacion |
jiuk | 0:3a60cf1c28ca | 29 | sendSPI(0x0A,0x0); //intensidad |
jiuk | 0:3a60cf1c28ca | 30 | sendSPI(0x0B,0x07); //usa 7 leds |
jiuk | 0:3a60cf1c28ca | 31 | sendSPI(0x0C,1); //no apaga |
jiuk | 0:3a60cf1c28ca | 32 | sendSPI(0x0F,0); //operacion normal |
jiuk | 0:3a60cf1c28ca | 33 | } |
jiuk | 0:3a60cf1c28ca | 34 | |
jiuk | 0:3a60cf1c28ca | 35 | |
jiuk | 0:3a60cf1c28ca | 36 | void imp_mat(uint8_t* vC) |
jiuk | 0:3a60cf1c28ca | 37 | |
jiuk | 0:3a60cf1c28ca | 38 | { |
jiuk | 0:3a60cf1c28ca | 39 | uint8_t i =0; |
jiuk | 0:3a60cf1c28ca | 40 | for (i=1;i<9;i++){ //Realiza la impresion de la matriz. |
jiuk | 0:3a60cf1c28ca | 41 | sendSPI(i,*(vC+i-1)); |
jiuk | 0:3a60cf1c28ca | 42 | } |
jiuk | 0:3a60cf1c28ca | 43 | } |
jiuk | 0:3a60cf1c28ca | 44 | |
jiuk | 0:3a60cf1c28ca | 45 | void act_mat(uint8_t* mascara) |
jiuk | 0:3a60cf1c28ca | 46 | { |
jiuk | 0:3a60cf1c28ca | 47 | for (int i=0; i<8;i++) //Es la matriz que tenemos como resultado de las diferentes piezas. |
jiuk | 0:3a60cf1c28ca | 48 | mat_act[i]= (*(mascara+i)); |
jiuk | 0:3a60cf1c28ca | 49 | } |
jiuk | 0:3a60cf1c28ca | 50 | |
jiuk | 0:3a60cf1c28ca | 51 | void cop_mat(uint8_t* m2) |
jiuk | 0:3a60cf1c28ca | 52 | { |
jiuk | 0:3a60cf1c28ca | 53 | for (int i=0; i<11;i++){ //Realiza una copia de la matriz actual fila por fila. |
jiuk | 0:3a60cf1c28ca | 54 | mat_tmp[i]= *(m2+i); |
jiuk | 0:3a60cf1c28ca | 55 | } |
jiuk | 0:3a60cf1c28ca | 56 | } |
jiuk | 0:3a60cf1c28ca | 57 | |
jiuk | 0:3a60cf1c28ca | 58 | |
jiuk | 0:3a60cf1c28ca | 59 | void desplazar_fila(){ //Realiza el desplazamiento para bajar la figura. |
jiuk | 0:3a60cf1c28ca | 60 | for (int i=0; i<11;i++) |
jiuk | 0:3a60cf1c28ca | 61 | mat_tmp[i]= mat_tmp[i]>>1; |
jiuk | 0:3a60cf1c28ca | 62 | |
jiuk | 0:3a60cf1c28ca | 63 | } |
jiuk | 0:3a60cf1c28ca | 64 | |
jiuk | 0:3a60cf1c28ca | 65 | void borrar() |
jiuk | 0:3a60cf1c28ca | 66 | { |
jiuk | 0:3a60cf1c28ca | 67 | int i; |
jiuk | 0:3a60cf1c28ca | 68 | for(i=0;i<=8;i++) |
jiuk | 0:3a60cf1c28ca | 69 | { |
jiuk | 0:3a60cf1c28ca | 70 | sendSPI(0x0+i,0x00); |
jiuk | 0:3a60cf1c28ca | 71 | } |
jiuk | 0:3a60cf1c28ca | 72 | }; |
jiuk | 0:3a60cf1c28ca | 73 | |
jiuk | 0:3a60cf1c28ca | 74 | void dibujar(char type_fig,char grados, char columna) |
jiuk | 0:3a60cf1c28ca | 75 | { |
jiuk | 0:3a60cf1c28ca | 76 | //borrar(); |
jiuk | 0:3a60cf1c28ca | 77 | |
jiuk | 0:3a60cf1c28ca | 78 | switch (type_fig){ |
jiuk | 0:3a60cf1c28ca | 79 | case C_TYPE: cop_mat(FIG_C); break; //Se envia el vector que contiene la figura a la funcion copiar matriz. |
jiuk | 0:3a60cf1c28ca | 80 | case I_TYPE: cop_mat(FIG_I); break; |
jiuk | 0:3a60cf1c28ca | 81 | case L_TYPE: cop_mat(FIG_L); break; |
jiuk | 0:3a60cf1c28ca | 82 | case T_TYPE: cop_mat(FIG_T); break; |
jiuk | 0:3a60cf1c28ca | 83 | case S_TYPE: cop_mat(FIG_S); break; |
jiuk | 0:3a60cf1c28ca | 84 | } |
jiuk | 0:3a60cf1c28ca | 85 | |
jiuk | 0:3a60cf1c28ca | 86 | } |
jiuk | 0:3a60cf1c28ca | 87 | |
jiuk | 0:3a60cf1c28ca | 88 | int main() { |
jiuk | 0:3a60cf1c28ca | 89 | char tipo_fig=1,ncolumna=1,grados=1,lee1=0x00,lee2=0x00; // enviar ficha y columna |
jiuk | 0:3a60cf1c28ca | 90 | test(); |
jiuk | 0:3a60cf1c28ca | 91 | while(1){ |
jiuk | 0:3a60cf1c28ca | 92 | borrar(); |
jiuk | 0:3a60cf1c28ca | 93 | lee1=command.getc(); //recive '<' para iniciar la linea de comandos. |
jiuk | 0:3a60cf1c28ca | 94 | tipo_fig=command.getc(); |
jiuk | 0:3a60cf1c28ca | 95 | grados=command.getc(); |
jiuk | 0:3a60cf1c28ca | 96 | ncolumna=command.getc(); |
jiuk | 0:3a60cf1c28ca | 97 | lee2=command.getc(); //recive '>' para terminar la linea de comandos. |
jiuk | 0:3a60cf1c28ca | 98 | if(lee1==0x3c && lee2==0x3e) //solo imprime una figura si viene bajo el parametro '<(t_fig) (Grados) (Col)>'. |
jiuk | 0:3a60cf1c28ca | 99 | { |
jiuk | 0:3a60cf1c28ca | 100 | dibujar(tipo_fig,grados,ncolumna); |
jiuk | 0:3a60cf1c28ca | 101 | for(int i=0;i<8;i++){ |
jiuk | 0:3a60cf1c28ca | 102 | desplazar_fila(); |
jiuk | 0:3a60cf1c28ca | 103 | act_mat(mat_tmp); |
jiuk | 0:3a60cf1c28ca | 104 | imp_mat(mat_act); |
jiuk | 0:3a60cf1c28ca | 105 | wait_ms(VEL); |
jiuk | 0:3a60cf1c28ca | 106 | } |
jiuk | 0:3a60cf1c28ca | 107 | } |
jiuk | 0:3a60cf1c28ca | 108 | } |
jiuk | 0:3a60cf1c28ca | 109 | } |
jiuk | 0:3a60cf1c28ca | 110 | |
jiuk | 0:3a60cf1c28ca | 111 | |
jiuk | 0:3a60cf1c28ca | 112 | |
jiuk | 0:3a60cf1c28ca | 113 | void debug_m(char *s , ... ){ |
jiuk | 0:3a60cf1c28ca | 114 | #if DEBUG |
jiuk | 0:3a60cf1c28ca | 115 | command.printf(s); //busca errores para depurar en el sistema datos guardados. |
jiuk | 0:3a60cf1c28ca | 116 | #endif |
jiuk | 0:3a60cf1c28ca | 117 | } |