alison castiblanco

Dependencies:   mbed

Fork of 00_01LAB_matrix8x8_fig_tetris1 by Alyson Castiblanco

main.cpp

Committer:
acastiblancoc
Date:
2018-09-12
Revision:
6:2f42f0b53611
Parent:
5:819f043b99a5
Child:
7:0a94835bc6e4

File content as of revision 6:2f42f0b53611:


#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 1000 // ms



uint8_t matrix_act[8]={0,0,0,0,0,0,0,0};
uint8_t matrix_tmp[11]={0b00000000,0b00000000,0b00000000,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 debug_m(char *s , ... ){
    #if DEBUG
    command.printf(s);
    #endif  
}

void printMatrix(uint8_t*  vC)

{
    uint8_t i =0;
    for (i=1;i<9;i++){
        sendSPI(i,*(vC+i-1));
    }
        
    }


void init_display(){
    sendSPI(0x0c,1);
    sendSPI(0x0b,7);
    sendSPI(0x09,0);
    sendSPI(0x0A,0x0E);
    printMatrix(matrix_act);
    int i;
    for (i=0;i<4;i++){
        sendSPI(0x0F,1);
        wait (0.2);
        sendSPI(0x0f,0);
        wait (0.2);
    }
}



 
void act_matrix(uint8_t*  mascara){ 
    for (int i=0; i<8;i++)
        matrix_act[i]=  ( *(mascara+i));
 
 } 
 void copy_matrix(uint8_t*  m2, char col){
  
    for (int i=0; i<11;i++){
        matrix_tmp[i]=  (*(m2+i)>>(col-1));
    }
 } 
void colum(){
    for (int i=0;i<7;i++){
        sendSPI(i-1,0);
        sendSPI(i,temp+i);
        }
    }
    
void new_read(){
    
    char ini=command.getc();
    char tf=command.getc();
    char ang=command.getc();
    char col=command.getc();
    char fin=command.getc();
    if(ini==0x3C && fin==0x3E)
    {
    switch (tf) {
    case  L_TYPE: 
    switch (ang)
         {  case NOVEN:
             switch(col)
             {case 1:
             copy_matrix(FIG_L1,1);
             break;
             case 2:
             copy_matrix(FIG_L1,2);
             break;
             case 3:
             copy_matrix(FIG_L1,3);
             break;
             case 4:
             copy_matrix(FIG_L1,4);
             break;
             case 5:
             copy_matrix(FIG_L1,5);
             break;
             case 6:
             copy_matrix(FIG_L1,6);
             break;
             case 7:
             copy_matrix(FIG_L1,7);
             break;
             case 8:
             copy_matrix(FIG_L1,8);
             break;
            }
            break;
            case ZERO:
            copy_matrix(FIG_L,1);
        break ; 
        case PII:
            copy_matrix(FIG_L2,1);
            break;
            case DOSSE:
            copy_matrix(FIG_L3,1);
            break; 
        }
                break ;     
    case  S_TYPE: 
        switch (ang)
         {  case NOVEN:
            copy_matrix(FIG_S1,1);
            break;
            case ZERO:
            copy_matrix(FIG_S,1);
        break ; 
        case PII:
            copy_matrix(FIG_S2,1);
            break;
            case DOSSE:
            copy_matrix(FIG_S3,1);
            break; 
        }
        break ;     
    case  I_TYPE: 
        switch (ang)
         {  case NOVEN:
            copy_matrix(FIG_I1,1);
            break;
            case ZERO:
            copy_matrix(FIG_I,1);
        break ; 
        case PII:
            copy_matrix(FIG_I2,1);
            break;
            case DOSSE:
            copy_matrix(FIG_I3,1);
            break; 
        }
        break ;     
    case  C_TYPE: 
        copy_matrix(FIG_C,1);
        break ; 
    case  T_TYPE:
         switch (ang)
         {  case NOVEN:
            copy_matrix(FIG_T1,1);
            break;
            case ZERO:
            copy_matrix(FIG_T,1);
        break ; 
        case PII:
            copy_matrix(FIG_T2,1);
            break;
            case DOSSE:
            copy_matrix(FIG_T3,1);
            break; 
        }
        break;
    default: 
        copy_matrix(FIG_NULL,1);
        break;
        }
        }
        else
        {}
}
//desplazamiento horizontal
void desplazar_fila(){
    for (int i=0; i<8;i++)
        matrix_tmp[i]= matrix_tmp[i]>>1;
    
    }


int main() {
    init_display();
    while(1){
       new_read();
           for(int i=0;i<8;i++){
            act_matrix(matrix_tmp);
            printMatrix(matrix_act);
            //desplazar_fila();
            wait_ms(VELOCITY);
       }  
       } 
    }