I wrote a simple function that lights an individual LED on my 8x8 LED matrix (24 pins, as it has both red and green color). This is all working correctly, except when I want to light individual LEDs on shared rows or cols. Please take a look at this photo:
This is the result I get when lighting LEDs (col, row): 4,1 and 5,1 and 4,4. Because 5,1 and 4,4 are already on also LED 5,4 is lit (the one I marked with the arrow).
How can I prevent this so that 5,4 doesn't get lit unless specifically called for? Do I need to use a shift register for this? I tried the code in this example: Arduino Playground - DirectDriveLEDMatrix but couldn't get it too work correctly: rows and cols of LEDs were lit, no individual LEDs. Any information on this is very much appreciated.
You have to scan the matrix, lighting only one row at a time. Setup the lights for that row, turn the row on, turn the row off, repeat for the next row...
When the LED's all share rows and columns you need to light one row (or column) at a time. Usually you would keep an array of bits to represent the LED's and run nested loops to copy the array to the LED's repeatedly:
for (row = 0; row < 8; row ++)
{
for (column = 0; column < 8; column++)
digitalWrite(columnPins[column], pattern[row] & (1<<column)); // Light the columns corresponding to 1 bits
digitalWrite(rowPins[row], HIGH); // Light up the row
delay(4); // Delay longe enough for bright lights but not so long the matrix flickers
digitalWrite(rowPins[row], LOW); // Turn off the row
}