-
Arduino controlled LED matrix
Being bored one Winter day, I soldered some LEDs onto small circular breadboard.
Here is what the matrix looks like. The anodes of LEDs were wired in rows and the cathodes in columns. Thus, to turn on an LED, the proper row and column had to be set to high and low voltages. The next task was to hook this up to an Arduino board and create messages by flashing one character at a time. I drew out the characters on paper and then created binary numbers where the digit ’1′ represented an illuminated LED and ’0′ one that was turned off. A full character would look something like this.‘B00100′
‘B01010′
‘B11111′
‘B10001′
‘B10001′
In this case, this is the letter ‘A.’
/*
*
* ABCs – Flash a message by displaying one character at a time on a 5 x 5 LED matrix.
*
* Designed for a homebrew LED matrix. LED cathodes are tied together in horizontal rows.
* Anodes are tied together in vertical columns.
*
*/#define numChars 3 // How many character patterns defined.
#define numMsgChars 3 // How many characters in the message.// The ledDuration and dispCharRepeat control the total time a character is displayed.
// Up to a point, increasing the ledDuration makes the display brighter.
// The tradeoff is more flicker. Adjust both to get a suitable duration with acceptable flicker.
#define rowDuration 750 // How many microseconds to keep a row of LEDs lit.
#define dispCharRepeat 100 // Loop counter for number of times to loop through character display.#define msgDelay 3000 // How many milliseconds to delay before repeating message.
// Each row of bytes are the LED patterns for each row. Digit ’1′ indicates the LED is on; ’0,’ off.
// Left to right corresponds to top to bottom.
// Here is the character ‘A,’ for example.
//
// row 0: 0 0 1 0 0
// row 1: 0 1 0 1 0
// row 2: 1 1 1 1 1 Squint hard enough, you might see the character pattern.
// row 3: 1 0 0 0 1
// row 4: 1 0 0 0 1
byte pinData[numChars][5] = {
{B00100,B01010,B11111,B10001,B10001}, // A
{B11110,B10001,B11110,B10001,B11110}, // B
{B01110,B10001,B10000,B10001,B01110}, // C
};byte mask = B10000;
int ledPin[5] = {7,6,5,4,3}; // Arduino pins assigned to cathodes.
int rowPin[5] = {12,11,10,9,8}; // Arduino pins assigned to anodes.
int dispChar[numMsgChars] = {0,1,2}; // Show the above character in this order.void setup()
{
int i;
for(i=0;i<5;i++) // Loop through rowPin and ledPin to set modes and initial values to keep all LEDs off.
{
pinMode(ledPin[i], OUTPUT);
pinMode(rowPin[i], OUTPUT);
// Since these are LEDs, they will only glow when the rowPin is LOW and the ledPin is HIGH.
// Start with every row and LED turned "off".
digitalWrite(rowPin[i], HIGH);
digitalWrite(ledPin[i], LOW);
}
}void loop()
{
int i; // Letter repetition counter.
int dispCharNum; // Letter array counter.
int pinVal;for(dispCharNum=0;dispCharNum<numMsgChars;dispCharNum++) // Loop through each character in the message.
{
for(i=0;i<dispCharRepeat;i++) // Display character for a while.
{
showLetter(dispCharNum);
}
}
delay(msgDelay);
}void showLetter(int dispCharNum) {
int i; // LED position pin counter.
int j; // LED row counter.
int pinVal;for(j=0;j<5;j++) // for each row
{
for(i=0;i<5;i++) // Loop through each LED in the row.
{
pinVal = ((mask>>i) & pinData[dispChar[dispCharNum]][j]) ? HIGH : LOW; // Bit shift mask and bitwise AND to pinData.
digitalWrite(ledPin[i], pinVal); // if pinVal is 1, LED will be ON; if 0, OFF.
}digitalWrite(rowPin[j], LOW); // Set the rowPin to LOW so it can be the "ground" pin for the LED.
delayMicroseconds(rowDuration); // Keep the LED on long enough to be bright without flickering.
digitalWrite(rowPin[j], HIGH); // Set rowPin HIGH so it is no longer a ground pin.
for(i=0;i<5;i++) // Loop through each LED in the row.
{
digitalWrite(ledPin[i], LOW); // Turn off the LED.
}
}}


