Lighting individual LEDs on a shared col/row in a LED matrix

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...

I tried doing this by iterating between:

on(4,1); on(4,4);

But then a very clear flicker is visible. What am I missing?

Perhaps your "on" function take a lot longer than it should for some reason.

How is "on()" implemented?

Got it! I had a debug message being printed via Serial.println(); Thank you very much, it's working like a charm now :slight_smile:

Just for learning purposes: this is the best/only way to do this? Or would there be a 'better' solution?

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

Forgive me my ignorance, but I don't understand this part entirely:

digitalWrite(columnPins[column], pattern[row] & (1<<column));

What would pattern hold? A byte array? What happens on this line?