8×8 LED Matrix MAX7219 Display for Arduino

I've been experimenting with MAX7219 display. This device can be used to show characters.

To make it easier to compose the set of numbers that correspond to a particular pattern, I've created a utility.

There are lots of this type of utility available on the internet. This utility shows both numbers that correspond to columns as well as rows.

http://www.jlion.com/tools/fontmatrix.htm


/* CharData is a two dimensional constant array that holds the 8-bit column values of
   individual rows for ASCII characters that are to be displayed on a 8x8 matrix format.
*/
const byte LET_BLANK[8] ={0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000};
const byte LET_COLON[8]={B00000000,B01100110,B01100110,B00000000,B00000000,B00000000,B00000000,B00000000};
const byte LET_PERIOD[8]={0,0,0,0,0,0,0,0};
const byte LET_COMMA[8]={0,0,0,0,0,0,0,0};
const byte LET_DOLLAR[8]={0,0,0,0,0,0,0,0};
const byte LET_A[8]={B00000000,B01111111,B11111111,B10001000,B10001000,B11111111,B01111111,B00000000};
const byte LET_B[8]={B00000000,B01100110,B11111111,B10010001,B10010001,B11111111,B11111111,B00000000};
const byte LET_C[8]={B00000000,B01000010,B11000011,B10000001,B10000001,B11111111,B01111110,B00000000};
const byte LET_D[8]={B00000000,B00111100,B01111110,B11000011,B10000001,B11111111,B11111111,B00000000};
const byte LET_E[8]={B00000000,B10000001,B10010001,B10010001,B10010001,B11111111,B11111111,B00000000};
const byte LET_F[8]={B00000000,B10000000,B10010000,B10010000,B10010000,B11111111,B11111111,B00000000};
const byte LET_G[8]={B00000000,B01001111,B11001111,B10001001,B10001001,B11111111,B01111110,B00000000};
const byte LET_H[8]={B00000000,B01111111,B01111111,B00001000,B00001000,B01111111,B01111111,B00000000};
const byte LET_I[8]={B00000000,B00000000,B00000000,B10000001,B11111111,B11111111,B10000001,B00000000};
const byte LET_J[8]={B00000000,B10000000,B11111110,B11111111,B10000001,B00000111,B00000110,B00000000};
const byte LET_K[8]={B00000000,B01000001,B01100011,B00110110,B00011100,B11111111,B11111111,B00000000};
const byte LET_L[8]={B00000000,B00000001,B00000001,B00000001,B00000001,B11111111,B11111111,B00000000};
const byte LET_M[8]={B00000000,B11111111,B11000000,B01110000,B01110000,B11000000,B11111111,B00000000};
const byte LET_N[8]={B00000000,B11111111,B11111111,B00011100,B00111000,B11111111,B11111111,B00000000};
const byte LET_O[8]={B00000000,B01111110,B10000001,B10000001,B10000001,B10000001,B01111110,B00000000};
const byte LET_P[8]={B00000000,B01100000,B11110000,B10010000,B10010000,B11111111,B11111111,B00000000};
const byte LET_Q[8]={B00000000,B01111101,B11111111,B10000010,B10000010,B11111110,B01111100,B00000000};
const byte LET_R[8]={B00000000,B01110001,B10001011,B10000110,B10000100,B11111111,B11111111,B00000000};
const byte LET_S[8]={B00000000,B01000110,B11001111,B10001001,B10001001,B11111011,B00110010,B00000000};
const byte LET_T[8]={B00000000,B10000000,B10000000,B11111111,B11111111,B10000000,B10000000,B00000000};
const byte LET_U[8]={B00000000,B11111110,B11111111,B00000001,B00000001,B11111111,B11111110,B00000000};
const byte LET_V[8]={B00000000,B11111100,B11111110,B00000011,B00000011,B11111110,B11111100,B00000000};
const byte LET_W[8]={B00000000,B11111100,B00000011,B00001110,B00001110,B00000011,B11111100,B00000000};
const byte LET_X[8]={B00000000,B11000011,B11100111,B00011000,B00011000,B11100111,B11000011,B00000000};
const byte LET_Y[8]={B00000000,B11100000,B11110000,B00011111,B00011111,B11110000,B11100000,B00000000};
const byte LET_Z[8]={B00000000,B11100011,B11110011,B11010011,B11001011,B11001111,B11000111,B00000000};
const byte LET_0[8]={B00000000,B01111110,B10000011,B10001101,B10110001,B11000001,B01111110,B00000000};
const byte LET_1[8]={B00000000,B00000000,B00000001,B11111111,B11111111,B01100001,B00100000,B00000000};
const byte LET_2[8]={B00000000,B01110001,B10011001,B10001001,B10001101,B10000111,B01100011,B00000000};
const byte LET_3[8]={B00000000,B01100110,B11111111,B10010001,B10010001,B11000011,B01000010,B00000000};
const byte LET_4[8]={B00000000,B00000100,B11111111,B11111111,B10000100,B01100100,B00011100,B00000000};
const byte LET_5[8]={B00000000,B10001110,B10011111,B10010001,B10010001,B11110001,B11110001,B00000000};
const byte LET_6[8]={B00000000,B10000110,B10001111,B10001001,B11001001,B01111111,B00011110,B00000000};
const byte LET_7[8]={B00000000,B11000000,B11100000,B10110000,B10011111,B10001111,B10000000,B00000000};
const byte LET_8[8]={B00000000,B01100110,B11111111,B10010001,B10010001,B11111111,B01100110,B00000000};
const byte LET_9[8]={B00000000,B01111000,B11111100,B10010110,B10010011,B11110001,B01100000,B00000000};


  #include 
  const int LED_CLOCK=11;  //white
  const int LED_CS=10;     //black
  const int LED_DIN=12;    //purple
  LedControl _mtx=LedControl(LED_DIN,LED_CLOCK,LED_CS,8);

  //32 columns translates into 8 characters of 9 columns each (9*8=72)
  byte _buffer[72]={0,0,0,0,0,0,0,0,0,
                    0,0,0,0,0,0,0,0,0,
                    0,0,0,0,0,0,0,0,0,
                    0,0,0,0,0,0,0,0,0,
                    0,0,0,0,0,0,0,0,0,
                    0,0,0,0,0,0,0,0,0,
                    0,0,0,0,0,0,0,0,0,                                        
                    0,0,0,0,0,0,0,0,0};

  int _cursorPos=0; //current pixel index at which next character will be written.
  
  void setup()
  {
    Serial.begin(9600);              //  setup serial

    for (int id=0; id<8; id++)
      InitMatrix(id);
           
    WriteWord('5');
    WriteWord('2');
    WriteWord(':');
    WriteWord('5');
    WriteWord(' ');
    WriteWord('E');
    WriteWord('O');
    WriteWord('J');
  }

  void loop()
  {
    while (true)
    {
      for (int offset=0;offset<=sizeof(_buffer);offset++)
      {
        Serial.print(" offset: ");
        Serial.println(offset);
              
        ShowBuffer(offset);
      }
    }
  } 

  void InitMatrix(byte id)
  {
    _mtx.shutdown(id,false);
    _mtx.setIntensity(id,8);
    _mtx.clearDisplay(id); 
  }
  
  void ShowBuffer(int offset)
  {
      int maxSize=sizeof(_buffer);

      for (int pos=0;possizeof(_buffer))
      return;
      
    byte charToWrite[8];
    int byteLen=8;
    
    //get bits of character
    switch(val)
    {
      case 'A':
        memcpy( charToWrite, LET_A, 8*sizeof(byte) );
        break;

      case 'B':
        memcpy( charToWrite, LET_B, 8*sizeof(byte) );
        break;

      case 'C':
        memcpy( charToWrite, LET_C, 8*sizeof(byte) );
        break;

      case 'D':
        memcpy( charToWrite, LET_D, 8*sizeof(byte) );
        break;

      case 'E':
        memcpy( charToWrite, LET_E, 8*sizeof(byte) );
        break;

      case 'F':
        memcpy( charToWrite, LET_F, 8*sizeof(byte) );
        break;

      case 'G':
        memcpy( charToWrite, LET_G, 8*sizeof(byte) );
        break;

      case 'H':
        memcpy( charToWrite, LET_H, 8*sizeof(byte) );
        break;

      case 'I':
        memcpy( charToWrite, LET_I, 8*sizeof(byte) );
        break;

      case 'J':
        memcpy( charToWrite, LET_J, 8*sizeof(byte) );
        break;        
        
      case 'K':
        memcpy( charToWrite, LET_K, 8*sizeof(byte) );
        break;         
        
      case 'L':
        memcpy( charToWrite, LET_L, 8*sizeof(byte) );
        break; 
        
      case 'M':
        memcpy( charToWrite, LET_M, 8*sizeof(byte) );
        break;     
        
      case 'N':
        memcpy( charToWrite, LET_N, 8*sizeof(byte) );
        break;       
          
      case 'O':
        memcpy( charToWrite, LET_O, 8*sizeof(byte) );
        break;   
        
      case 'P':
        memcpy( charToWrite, LET_P, 8*sizeof(byte) );
        break;   
        
      case 'Q':
        memcpy( charToWrite, LET_Q, 8*sizeof(byte) );
        break;  
        
      case 'R':
        memcpy( charToWrite, LET_R, 8*sizeof(byte) );
        break;  
        
      case 'S':
        memcpy( charToWrite, LET_S, 8*sizeof(byte) );
        break;  
        
      case 'T':
        memcpy( charToWrite, LET_T, 8*sizeof(byte) );
        break;  
        
      case 'U':
        memcpy( charToWrite, LET_U, 8*sizeof(byte) );
        break;     
                     
      case 'V':
        memcpy( charToWrite, LET_V, 8*sizeof(byte) );
        break;                   
        
      case 'W':
        memcpy( charToWrite, LET_W, 8*sizeof(byte) );
        break;       

      case 'X':
        memcpy( charToWrite, LET_X, 8*sizeof(byte) );
        break;       

      case 'Y':
        memcpy( charToWrite, LET_Y, 8*sizeof(byte) );
        break;       

      case 'Z':
        memcpy( charToWrite, LET_Z, 8*sizeof(byte) );
        break;                                       

      case '0':
        memcpy( charToWrite, LET_0, 8*sizeof(byte) );
        break;       

      case '1':
        memcpy( charToWrite, LET_1, 8*sizeof(byte) );
        break;  

      case '2':
        memcpy( charToWrite, LET_2, 8*sizeof(byte) );
        break;  

      case '3':
        memcpy( charToWrite, LET_3, 8*sizeof(byte) );
        break;  

      case '4':
        memcpy( charToWrite, LET_4, 8*sizeof(byte) );
        break;  

      case '5':
        memcpy( charToWrite, LET_5, 8*sizeof(byte) );
        break;  

      case '6':
        memcpy( charToWrite, LET_6, 8*sizeof(byte) );
        break;  

      case '7':
        memcpy( charToWrite, LET_7, 8*sizeof(byte) );
        break;  

      case '8':
        memcpy( charToWrite, LET_8, 8*sizeof(byte) );
        break;  

      case '9':
        memcpy( charToWrite, LET_9, 8*sizeof(byte) );
        break;   

      case ':':
        byteLen=4;
        memcpy( charToWrite, LET_COLON, 8*sizeof(byte) );
        break;  

      case '.':
        memcpy( charToWrite, LET_PERIOD, 8*sizeof(byte) );
        break;  

      case ',':
        memcpy( charToWrite, LET_COMMA, 8*sizeof(byte) );
        break;  

      case '$':
        memcpy( charToWrite, LET_DOLLAR, 8*sizeof(byte) );
        break;  
                                                                                                                     
      default:
        memcpy( charToWrite, LET_BLANK, 8*sizeof(byte) );
        break;
    }

    //put character in buffer at position
    int startPos=_cursorPos;

    byte *oneColumn = &_buffer[startPos]; // Holds the address of the 1st element. 
    for(byte curCol=0;curCol<8;curCol++)    
    {
      *oneColumn=charToWrite[curCol];
      oneColumn++;
    }  

    _cursorPos+=byteLen;
  }