To demonstrate a proof of concept (persistent vision) I have wired together a 3x3 led matrix as per the schematic below:
To light any particular LED i need to set the corresponding row pin to HIGH and the column pin to LOW
Since at any given time only 1 led will be lit up I will be within the current limits (around 40mA).
What I am trying to do is to light each LED in succession fast enough so that the whole matrix would seem to be lit up to the human eye.
My arduino code is:
//demonstarte POV in led grid 3x3
int pins_rows[3]={7,8,9};
int pins_cols[3]={10,11,12};
void setup()
{
//define row led pins(anodes)
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
//define col led pins(cathodes)
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
void loop()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
ledON(i,j);
delay(100);
ledOFF(i,j);
delay(1000);
}
}
}
void ledON(int row, int col)
{
digitalWrite(pins_rows[row], HIGH);
digitalWrite(pins_cols[col], LOW);
}
void ledOFF(int row, int col)
{
digitalWrite(pins_rows[row], LOW);
digitalWrite(pins_cols[col], LOW);
}
However when I run this on my arduino all i get it the LOAD light on the board (i think that means there is too much current being drawn somewhere?)
Move the resistors to the anodes.
Drive the anodes hi/lo as needed, pull 1 cathode low at a time. Preferably with an NPN transistor.
If you want to use an arduino pin for pulling the cathodes, size the resistors so they only allow 10-12mA each so total current to sink is no more than ~35mA.
CrossRoads:
Move the resistors to the anodes.
Drive the anodes hi/lo as needed, pull 1 cathode low at a time. Preferably with an NPN transistor.
If you want to use an arduino pin for pulling the cathodes, size the resistors so they only allow 10-12mA each so total current to sink is no more than ~35mA.
Why would it make a difference if the resistor is connected to the anode or the cathode ? also since I am only lighting 1 led at any given moment, shouldnt the arduino pin be easily able to sink its current (40mA max as per my led and resistance setting)?
With the resistors on the anodes, you can turn on 3 at a time and all will have the same brightness level.
With the resistors on the cathodes, brightness will vary as the number of LEDs turned on varies.
What is quicker - cycling thru 3 rows, or thru 9 LEDs>? I would suspect 3 rows.
Keep your data to be displayed in a 3x3 array.
drive cathodes off.
Read array row 1, write the outputs, drive cathode 1 on.
drive cathode 1 off.
Read array row 2, write the outputs, drive cathode 2 on.
drive cathode 2 off.
Read array row 3, write the outputs, drive cathode 3 on.
drive cathode 3 off.
Repeat.
Put that in blink-without-delay style loop.
Keep track of which row is being driven.
Every 14mS update the display for the next row.
Do other stuff, like read buttons, receive serial data, update the array, during the rest of the time.