8x8 Led matrix programing issue?

Hi there,

I have started this project, and I thin i have a problem with the programing part.
So belove you can check out my code. The problem is when I put a little delay(e.g. 1 to 10) the LEDs brightness is low, and they start to blink at one point. Also if the value is high like in this code, the brightness is ok, but of course i don't have the continuos "flow" to get for example the letter A. My goal is to display a letter with no blinking and good brightness.
(The pins are correctly mounted, i checked several times, also i have a basic setup 8x8 Led matrix, with comon catodhe setup, each anode coloumn beeing protected by a 220 ohm resistor)

/*
8x8 Led Matrix using Arduino
*/

int i=0, j=0;
int l_col=8;
int l_row=8;
int col[8] = {13,12,11,10,9,8,7,6};
int row[8] = {19,18,17,16,5,4,3,2};

int pattern[8][8] = {
  {0,1,1,1,1,1,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,1,1,1,1,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
};

void setup() {
  for(i=0; i<l_col; i++)
  {
    pinMode(col[i], OUTPUT);
    digitalWrite(col[i], LOW);
  }
  for(i=0; i<l_row; i++)
  {
    pinMode(row[i], OUTPUT);
    digitalWrite(row[i], HIGH);
  }
}

void draw(){
  for(i=0; i<l_row; i++)
  for(j=0; j<l_col; j++)
  {
    if(pattern[i][j])
    {
      digitalWrite(col[j], HIGH);
      digitalWrite(row[i], LOW);
      delay(500);
      digitalWrite(col[j], LOW);
      digitalWrite(row[i], HIGH);
    }
  }
}

void loop() {
  draw();
}

Do you remember putting italics in your code?
No, I thought not.
Please read this

"delay()" is the devil's function. You need to exorcise it from the code.

int pattern[8][8] = {
  {0,1,1,1,1,1,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,1,1,1,1,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
};

Using 128 bytes of precious RAM to store eight bytes-worth of data is not a good use of resources.

I changed it to 'byte'. What can I use instead of delay() ?

byte pattern[8][8] = {
  {0,1,1,1,1,1,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,1,1,1,1,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
  {0,1,0,0,0,0,1,0},
};

I changed it to 'byte'.

So down from a 16x overhead to only an 8x overhead.
Keep going.

What can I use instead of delay() ?

Have a look at the blink without delay example, provided with the IDE.

I don't know how to use that example for my 8x8 led matrix..yet. Turn on an led, wait, turn off that led, wait, turn the next led...something like this?
Without delay, the brightness will be ok?:slight_smile:

I need help, please :slight_smile:

So to do your 64 outputs, with half a second delay for each one, will take 32 second per cycle.
That's never going to work.

If I was going to drive leds that way, I'd try something like this

int n_on ;
int ons[8] ;
for ( int k=0 ; k<8 ; k++ ) 
{
    ons[k]=0 ;
}

for ( int j=0 ; j<8 ; j++ )
{
    for ( int i=0 ; i<8 ; i++ )
    {
        if ( pattern[i][j] )
        {
            ons[n_on]=i ;
            n_on++ ;
            digitalWrite( row[i], HIGH );
        }
    }
    if ( n_on > 0 )
    {
        digitalWrite( col[j], LOW );
        delay(15) ;
        digitalWrite( col[j], HIGH );
        for ( int m=0 ; m<n_on ; m++ )
        {
            digitalWrite( row[ons[m]], LOW );
        }
        n_on=0 ;
    }
}

The code is working, I can see the pattern but the brightness is low again..how can I fix the brightness problem? With 'delay(150)' the brightness is ok.. :~

Someone can help me? I just made a GUI in processing to control the leds. I can't figure it out this brightness problem..

Increase the cycle time, and decrease the current limit resistor. Thus you cycle thru the LEDs faster, but they are brighter when they are on. Check the datasheet for the part, see how long each can be on when pulsed, and what the pulse current can be.