Primer codigo

Dependencies:   MAX7219 mbed

main.cpp

Committer:
djinn77
Date:
2018-09-09
Revision:
5:3f4a420fd9b1
Parent:
4:5b4114791035

File content as of revision 5:3f4a420fd9b1:

#include "mbed.h"
#include "max7219.h"
//#define DEBUG 1

Serial pc(USBTX,USBRX);

    
Max7219 deviceM(PB_15, PB_14, PB_13, PB_12);
int matriz[8]={0};

void debuging(char*s,...){
    
    #if DEBUG
    pc.printf(s);
    #endif
    
    }


 void imprimir(){
    // Sele aplica corrmiento a las posiciones del vecteor para facilitar selecccion de la posicion. 
  
         for(int i=0;i<=12;i++)
         {
        for (int j= 1; j<=8; j++){
            
        deviceM.write_digit(1,j,matriz[j-1]>>i);           
            }                 
        wait(1.0);                        
         }
      
    }
 
int main() {
    
    max7219_configuration_t cfg = {
    .device_number = 1,
    .decode_mode = 0,
    .intensity = Max7219::MAX7219_INTENSITY_8,
    .scan_limit = Max7219::MAX7219_SCAN_8
};
   
    deviceM.init_device(cfg);
    
    deviceM.enable_device(1);
   
    deviceM.set_display_test();
    wait(1);   
    deviceM.clear_display_test();
    wait(1);
        
        
    while(1){
         
         pc.baud(38400);
         char pos= 0;
         char figura= 0;
         char giro= 0;
         debuging("\n Ingrese el posicion. ");
         pos=pc.getc();
         debuging("\n Seleccione la Figura. ");
         figura=pc.getc();
         debuging("\n Seleccione la rotacion. ");
         giro=pc.getc();
         
         
         switch(figura){
             case 1:
              // Cuadrado
             switch(giro){
             case 1: case 2: case 3: case 4:
             matriz[pos]=  0b11000000000;
             matriz[pos+1]=0b11000000000;
             imprimir();
             break;
             }
             break;
             case 2:
             //T
             switch(giro){
                 case 1:
                 matriz[pos]=  0b10000000000;
                 matriz[pos+1]=0b11000000000;
                 matriz[pos+2]=0b10000000000;
                 imprimir();
                 break;
                 case 2:
                 matriz[pos]=  0b01000000000;
                 matriz[pos+1]=0b11100000000;
                 imprimir();
                 break;
                 case 3:
                 matriz[pos]=  0b11100000000;
                 matriz[pos+1]=0b01000000000;
                 imprimir();
                 break;
                 case 4:
                 matriz[pos]=  0b01000000000;
                 matriz[pos+1]=0b11000000000;
                 matriz[pos+2]=0b01000000000;
                 imprimir();
                 break;
                 }
        
             break;
             case 3:
             //L
             switch(giro){
                 case 1:
                 matriz[pos]=  0b11000000000;
                 matriz[pos+1]=0b10000000000;
                 matriz[pos+2]=0b10000000000;
                 imprimir();
                 break;
                 case 2:
                 matriz[pos]=  0b111000000000;
                 matriz[pos+1]=0b001000000000;
                 imprimir();
                 break;
                 case 3:
                 matriz[pos]=  0b01000000000;
                 matriz[pos+1]=0b01000000000;
                 matriz[pos+2]=0b11000000000;
                 imprimir();
                 break;
                 case 4:
                 matriz[pos]=  0b10000000000;
                 matriz[pos+1]=0b11100000000;
                 imprimir();
                 break;
                 }
             break;
             case 4:
             //Z
             switch(giro){
                 case 1: case 3:
                 matriz[pos]=  0b01000000000;
                 matriz[pos+1]=0b11000000000;
                 matriz[pos+2]=0b10000000000;
                 imprimir();
                 break;
                 case 2: case 4:
                 matriz[pos]=  0b11000000000;
                 matriz[pos+1]=0b01100000000;
                 imprimir();
                 break;
    
                 }
             break;
             case 5:
             switch(giro){
                 case 1: case 3:
                 matriz[pos]=  0b10000000000;
                 matriz[pos+1]=0b10000000000;
                 matriz[pos+2]=0b10000000000;
                 imprimir();
                 break;
                 case 2: case 4:
                 matriz[pos]=  0b11100000000;
                 imprimir();
                 break;
                 }
             
             break;
             
             
             
             
             
             }
        matriz[0]=0;
        matriz[1]=0;
        matriz[2]=0;
        matriz[3]=0;
        matriz[4]=0;
        matriz[5]=0;
        matriz[6]=0;
        matriz[7]=0;
        
        }
        
       
        
     
}