In a previous post I explained how to drive the LED matrix LD-1088BS. Many people control these matrixes through a microprocessors like the Arduino. In this post I will show how to control the LED Matrix with an Arduino board.
We will do direct connections from the outputs on the Arduino board to the pins of the Matrix, of course with a resistor in series. That means we will need a total of 16 pins. As a side note, if not enough outputs are available a mux (multiplexer) could be used with pull downs/ups but we will keep it simple.
To make the code easier to read it’s easiest to assign consecutive outputs to the row and column numbers. On my Mega2560 I drive column 1 with output 30, column 2 with output 32, column 3 with output 34, etc and row 1 with output 31, row 2 with output 32, etc. With that I define the following arrays
int rows(30, 32, 34, 36, 38, 40, 42, 44);
int columns(31, 33, 35, 37, 39, 41, 43, 45);
Let’s take another look at the image from the previous post.
Image may be NSFW.
Clik here to view.
Based on this, we connect the output pins to the 8×8 LED matrix as follows:
- row 1: output 30 -> resistor -> pin 9
- row 2: output 32 -> resistor -> pin 14
- row 3: output 34 -> resistor -> pin 8
- row 4: output 36 -> resistor -> pin 12
- row 5: output 38 -> resistor -> pin 1
- row 6: output 40 -> resistor -> pin 7
- row 7: output 42 -> resistor -> pin 2
- row 8: output 44 -> resistor -> pin 5
- column 1: output 31 -> pin 13
- column 1: output 33 -> pin 3
- column 1: output 35 -> pin 4
- column 1: output 37 -> pin 10
- column 1: output 39 -> pin 6
- column 1: output 41 -> pin 11
- column 1: output 43 -> pin 15
- column 1: output 45 -> pin 16
Now we need to configure the modes for the arduino outputs:
void setup()
{
for(int i=0; i<8; i++)
{
pinMode(rows[i], OUTPUT);
pinMode(columns[i], OUTPUT);
}
TurnAllLEDsOff();
}
As you can see, there is also a function that turns all the LEDs off. We now need to define this function. From the previous post we know that we need to set the rows to low and the columns to high. This results in the following function:
void TurnAllLEDsOff()
{
for(int i=0; i<8; i++)
{
digitalWrite(rows[i], LOW);
digitalWrite(columns[i], HIGH);
}
}
Next we need a function to turn one LED on. Again, from the previous post we know that to turn a particular LED on we need to turn the row where the LED is located to high and the column where the LED is to low. Before we do this we will turn off the previous LED that was on by simply calling TurnAllLEDsOff(). If you want to optimize it you can remember the last position and switch the polarity but we want to keep it simple. With that we get the following function:
void TurnLEDOn(int row, int column)
{
TurnAllLEDsOff();
digitalWrite(rows[row], HIGH);
digitalWrite(columns[column], LOW);
}
Finally, let’s loop down the first column. Note that the index is 0 based.
void loop()
{
for(int r=0; r<8; r++)
{
TurnLEDOn(r, 0);
delay(300);
}
}
From here it should be pretty easy to make any other desired pattern.
For reference, here is the complete program.
int rows[] = {30, 32, 34, 36, 38, 40, 42, 44};
int columns[] = {31, 33, 35, 37, 39, 41, 43, 45};
void setup()
{
for(int i=0; i<8; i++)
{
pinMode(rows[i], OUTPUT);
pinMode(columns[i], OUTPUT);
}
TurnAllLEDsOff();
}
void TurnAllLEDsOff()
{
for(int i=0; i<8; i++)
{
digitalWrite(rows[i], LOW);
digitalWrite(columns[i], HIGH);
}
}
void TurnLEDOn(int row, int column)
{
TurnAllLEDsOff();
digitalWrite(rows[row], HIGH);
digitalWrite(columns[column], LOW);
}
void loop()
{
for(int r=0; r<8; r++)
{
TurnLEDOn(r, 0); delay(300);
}
}