Google+ Facebook Twitter Pin It Reddit

LED Matrix Kit Code

LED Matrix This page contains sample code for the electronics project Circuit Skills: LED Matrix Kit, by Product Manager, Ryan Winters. First is the code to define the letters to spell JAMECO with a 500ms delay between each letter. Following is some sample code from Arduino Playground which is a publicly-editable wiki about Arduino.


#include "LedControl.h"

LedControl lc=LedControl(12,10,11,1);
unsigned long delaytime=500;

void setup() 
  {
  lc.shutdown(0,false);
  lc.setIntensity(0,8);
  lc.clearDisplay(0);
  }
void writeOnMatrix()
  {
  byte J[5]={B00000110,B00000001,B00000001,B00000001,B11111110};
  byte A[5]={B01111111,B10001000,B10001000,B10001000,B01111111};	
  byte M[5]={B11111100,B01000000,B00100000,B01000000,B11111100};
  byte E[5]={B11111110,B10010010,B10010010,B10010010,B00000000};
  byte C[5]={B01111110,B10000001,B10000001,B10000001,B01000010};
  byte O[5]={B01111110,B10000001,B10000001,B10000001,B01111110};
  /* now display them one by one with a small delay */
  lc.setRow(0,0,J[0]);
  lc.setRow(0,1,J[1]);
  lc.setRow(0,2,J[2]);
  lc.setRow(0,3,J[3]);
  lc.setRow(0,4,J[4]);
  delay(delaytime);
  lc.setRow(0,0,A[0]);
  lc.setRow(0,1,A[1]);
  lc.setRow(0,2,A[2]);
  lc.setRow(0,3,A[3]);
  lc.setRow(0,4,A[4]);
  delay(delaytime);
  lc.setRow(0,0,M[0]);
  lc.setRow(0,1,M[1]);
  lc.setRow(0,2,M[2]);
  lc.setRow(0,3,M[3]);
  lc.setRow(0,4,M[4]);
  delay(delaytime);
  lc.setRow(0,0,E[0]);
  lc.setRow(0,1,E[1]);
  lc.setRow(0,2,E[2]);
  lc.setRow(0,3,E[3]);
  lc.setRow(0,4,E[4]);
  delay(delaytime);
  lc.setRow(0,0,C[0]);
  lc.setRow(0,1,C[1]);
  lc.setRow(0,2,C[2]);
  lc.setRow(0,3,C[3]);
  lc.setRow(0,4,C[4]);
  delay(delaytime);
  lc.setRow(0,0,O[0]);
  lc.setRow(0,1,O[1]);
  lc.setRow(0,2,O[2]);
  lc.setRow(0,3,O[3]);
  lc.setRow(0,4,O[4]);
  delay(delaytime);
  lc.setRow(0,0,0);
  lc.setRow(0,1,0);
  lc.setRow(0,2,0);
  lc.setRow(0,3,0);
  lc.setRow(0,4,0);
  delay(delaytime);
  }

void loop() 
  {
  lc.setIntensity(0,8);
  writeOnMatrix();
  delay(200);
  }

This code contains a complete alphabet of capital letters and a couple other brief methods that demonstrate how to flash specific LEDs for a specified period, and some mesmerizing things you can do with pulsing the brightness of the entire matrix. The code is mostly borrowed from the Arduino Playground which is a publicly-editable wiki about Arduino.


//We always have to include the library
#include "LedControl.h"

/*Now we need a LedControl to work with.
 pin 12 is connected to the DataIn
 pin 10 is connected to the CLK
 pin 11 is connected to LOAD
 We only have a single MAX7219  */

LedControl lc=LedControl(12,10,11,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=500;
void setup()
{
  /* The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call  */
  lc.shutdown(0,false);   //* Set the brightness to a medium values */
  lc.setIntensity(0,8);    //* and clear the display */
  lc.clearDisplay(0);
}

void loop() 
{
  lc.setIntensity(0,8);
  writeOnMatrix();       //This bit of code spells out JAMECO
  delay(200);
  writeOnMatrix();
  delay(200);

  rows();             
  lc.clearDisplay(0);

  columns();
  lc.clearDisplay(0);

  single();
  for (int n=0; n<5; n++)
  {
    for (int z=0; z<16; z++)
    {
      lc.setIntensity(0,z);
      delay(100);
    }
    for (int z=15; z>-1; --z)
    {
      lc.setIntensity(0,z);
      delay(100);
    }
  }
  lc.clearDisplay(0);
}

/*This method will display the characters for the word "JAMECO" one after the other
on the matrix. (you need at least 5x7 leds to see the whole chars)*/ void writeOnMatrix() { /* here is the data for the characters */ byte A[5]={ B01111111,B10001000,B10001000,B10001000,B01111111 }; byte B[5]={ B11111111,B01001001,B01001001,B00110110,B00000000 }; byte C[5]={ B01111110,B10000001,B10000001,B10000001,B01000010 }; byte D[5]={ B01111111,B01000001,B01000001,B00111110,B00000000 }; byte E[5]={ B11111110,B10010010,B10010010,B10010010,B00000000 }; byte F[5]={ B01111111,B01001000,B01001000,B01001000,B00000000 }; byte G[5]={ B01111110,B10000001,B10001001,B10001001,B01001110 }; byte H[5]={ B01111111,B00001000,B00001000,B00001000,B01111111 }; byte I[5]={ B00100001,B00100001,B00111111,B00100001,B00100001 }; byte J[5]={ B00000110,B00000001,B00000001,B00000001,B11111110 }; byte K[5]={ B11111111,B00011000,B00100100,B01000010,B10000001 }; byte L[5]={ B11111111,B00000001,B00000001,B00000001,B00000001 }; byte M[5]={ B11111100,B01000000,B00100000,B01000000,B11111100 }; byte N[5]={ B00111111,B00010000,B00001000,B00000010,B00111111 }; byte O[5]={ B01111110,B10000001,B10000001,B10000001,B01111110 }; byte P[5]={ B11111111,B10001000,B10001000,B10001000,B01110000 }; byte Q[5]={ B01111100,B10000010,B10000010,B10000011,B01111101 }; byte R[5]={ B11111111,B10001000,B10001100,B10001010,B01110001 }; byte S[5]={ B00110001,B01001001,B01001001,B01001001,B01000110 }; byte T[5]={ B00100000,B00100000,B00111111,B00100000,B00100000 }; byte U[5]={ B00111110,B00000001,B00000001,B00000001,B00111110 }; byte V[5]={ B00111100,B00000010,B00000001,B00000010,B00111100 }; byte W[5]={ B00111111,B00000010,B00000100,B00000010,B00111111 }; byte X[5]={ B00010001,B00001010,B00000100,B00001010,B00010001 }; byte Y[5]={ B11100000,B00010000,B00001111,B00010000,B11100000 }; byte Z[5]={ B00010001,B00010011,B00010101,B00011001,B00010001 }; byte r[5]={ B00111110,B00010000,B00100000,B00100000,B00010000 }; /* now display them one by one with a small delay */ lc.setRow(0,0,J[0]); lc.setRow(0,1,J[1]); lc.setRow(0,2,J[2]); lc.setRow(0,3,J[3]); lc.setRow(0,4,J[4]); delay(delaytime); lc.setRow(0,0,A[0]); lc.setRow(0,1,A[1]); lc.setRow(0,2,A[2]); lc.setRow(0,3,A[3]); lc.setRow(0,4,A[4]); delay(delaytime); lc.setRow(0,0,M[0]); lc.setRow(0,1,M[1]); lc.setRow(0,2,M[2]); lc.setRow(0,3,M[3]); lc.setRow(0,4,M[4]); delay(delaytime); lc.setRow(0,0,E[0]); lc.setRow(0,1,E[1]); lc.setRow(0,2,E[2]); lc.setRow(0,3,E[3]); lc.setRow(0,4,E[4]); delay(delaytime); lc.setRow(0,0,C[0]); lc.setRow(0,1,C[1]); lc.setRow(0,2,C[2]); lc.setRow(0,3,C[3]); lc.setRow(0,4,C[4]); delay(delaytime); lc.setRow(0,0,O[0]); lc.setRow(0,1,O[1]); lc.setRow(0,2,O[2]); lc.setRow(0,3,O[3]); lc.setRow(0,4,O[4]); delay(delaytime); lc.setRow(0,0,0); lc.setRow(0,1,0); lc.setRow(0,2,0); lc.setRow(0,3,0); lc.setRow(0,4,0); delay(delaytime); } /* This function lights up a some Leds in a row.
The pattern will be repeated on every row. The pattern will blink along with the row-number.
row number 4 (index==3) will blink 4 times etc. */ void rows() { for(int row=0;row<8;row++) { delay(50); lc.setRow(0,row,B10100000); delay(50); lc.setRow(0,row,(byte)0); for(int i=0;i<row;i++) { delay(50); lc.setRow(0,row,B10100000); delay(50); lc.setRow(0,row,(byte)0); } } } /* This function lights up a some Leds in a column. The pattern will be
repeated on every column.The pattern will blink along with the column-number.
column number 4 (index==3) will blink 4 times etc. */ void columns() { for(int col=0;col<8;col++) { delay(50); lc.setColumn(0,col,B10100000); delay(50); lc.setColumn(0,col,(byte)0); for(int i=0;i<col;i++) { delay(50); lc.setColumn(0,col,B10100000); delay(50); lc.setColumn(0,col,(byte)0); } } } /* This function will light up every Led on the matrix. The led will blink along with
the row-number. row number 4 (index==3) will blink 4 times etc. */ void single() { for(int row=0;row<8;row++) { for(int col=0;col<8;col++) { delay(50); lc.setLed(0,row,col,true); delay(50); for(int i=0;i<col;i++) { lc.setLed(0,row,col,false); delay(50); lc.setLed(0,row,col,true); delay(50); } } } }