1088BS led matrix and 74HC595N

Deeder_M: but it doesn't work

That was not a helpful description of the problem! Say what actually happens. If no leds light, say that.

Post your updated sketch, perhaps i can spot an error.

Try adding

  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

In setup(). This is needed because on that link i gave before, it says

Note

The dataPin and clockPin must already be configured as outputs by a call to pinMode().

The code you deleted out was doing that for you.

PaulRB: That was not a helpful description of the problem! Say what actually happens. If no leds light, say that.

Excuse me, you're right. Leds were not lighting.

PaulRB: Try adding

  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

In setup(). This is needed because on that link i gave before, it says The code you deleted out was doing that for you.

You're right again. It was my forgetfulness, now it works! Thank you so much

Hi to everybody! :smiley:
Using two 74HC595N shift registers and one 1088BS led matrix, I’m trying to light up two static pairs of leds and a single moving led (I’ve bought MAX7219 but I’m still waiting for it…).

Here my code:

//Pin connected to ST_CP of 74HC595
int latchPin = A1;
//Pin connected to SH_CP of 74HC595
int clockPin = A0;
////Pin connected to DS of 74HC595
int dataPin = A2;

int i=0, j=0;
int matrix[8][8];

int r[8]= {1,2,4,8,16,32,64,128}; // 00000001, 00000010, ... , 10000000 
int c[8]={127,191,223,239,247,251,253,254}; // 01111111, 10111111, ... , 11111110

//initial coordinates of the single led
int single_led_x=4;
int single_led_y=7;

void setup() {
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

//all values of the matrix =1
    for(i=0;i<8;i++)
  {
    for(j=0;j<8;j++)
    {
      matrix[i][j]=1;
    }
  }
  //pair of led
  matrix[0][3]=0;
  matrix[0][4]=0;
  //pair of led  
  matrix[7][3]=0;
  matrix[7][4]=0;
  //single led
  matrix[4][7]=0;
}

void loop() 
{
  for(i=0;i<8;i++)
  {
    for(j=0;j<8;j++)
    {
      if(matrix[i][j]==0)
      {
        digitalWrite(latchPin, 0);
        shiftOut(dataPin, clockPin, MSBFIRST, c[j]); 
        shiftOut(dataPin, clockPin, MSBFIRST, r[i]);
        digitalWrite(latchPin, 1);
      }
    }
  }

if(single_led_x!=6)
{
    matrix[single_led_x][single_led_y]=1;
    matrix[single_led_x+1][single_led_y]=0;
    single_led_x=single_led_x+1;
}
      delay(500);
}

I’m trying to move of some position the single led every 500ms while pairs of leds have to be static, but by this way all leds blink (except the last one, matrix[7][4]). If I reduce to 0 the delay, leds light up and don’t blink but of course I cannot see the single led moving.
How could I modify the code in order to solve this blinking problem? :confused:

Thank you in advance!

It's time for you to learn about multiplexing!

The idea is to scan a row or column of leds at once, and repeat this or each row or column, and light each one for equal periods, so they appear the same brightness. You can't use delay() for longer than 2 or 3 milliseconds. Or not use delay() at all, but time the scanning with millis() or micros().

PaulRB:
The idea is to scan a row or column of leds at once, and repeat this or each row or column, and light each one for equal periods, so they appear the same brightness.

Hi, thanks a lot for your support.
I used just one scan as you proposed, I hope it was what you were meaning:

//Pin connected to ST_CP of 74HC595
int latchPin = A1;
//Pin connected to SH_CP of 74HC595
int clockPin = A0;
////Pin connected to DS of 74HC595
int dataPin = A2;

int i=0, j=0;
int matrix[8][8];

int r[8]= {1,2,4,8,16,32,64,128}; // 00000001, 00000010, ... , 10000000 
int array_c=0;

//initial coordinates of the single led
int single_led_x=4;
int single_led_y=7;

void setup() {
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

//all values of the matrix =1
    for(i=0;i<8;i++)
  {
    for(j=0;j<8;j++)
    {
      matrix[i][j]=1;
    }
  }
  //pair of led
  matrix[0][3]=0;
  matrix[0][4]=0;
  //pair of led  
  matrix[7][3]=0;
  matrix[7][4]=0;
  //single led
  matrix[4][7]=0;
}

void loop() 
{

  for(i=0;i<8;i++)
  {
        digitalWrite(latchPin, 0);
        
        //binary to decimal of a single row; this byte will be used for the column
        array_c=(matrix[i][0]*1) + (matrix[i][1]*2) +(matrix[i][2]*4) + (matrix[i][3]*8) + (matrix[i][4]*16) + (matrix[i][5]*32) + (matrix[i][6]*64) + (matrix[i][7]*128); 
        
        shiftOut(dataPin, clockPin, MSBFIRST, array_c); //byte for columns
        shiftOut(dataPin, clockPin, MSBFIRST, r[i]); //byte for rows

        digitalWrite(latchPin, 1);        
  }  
  

if(single_led_x!=6)
{
    matrix[single_led_x][single_led_y]=1;
    matrix[single_led_x+1][single_led_y]=0;
    single_led_x=single_led_x+1;
}
      delay(0);
}

I still don’t see the single led moving (because it’s too fast), so I was supposing to use a for loop in order to repeat the lighting and “delay” the moving time. Something like this:

  for(j=0;j<150; j++)
  {
  for(i=0;i<8;i++)
  {
        digitalWrite(latchPin, 0);
        
        //binary to decimal of a single row; this byte will be used for the column
        array_c=(matrix[i][0]*1) + (matrix[i][1]*2) +(matrix[i][2]*4) + (matrix[i][3]*8) + (matrix[i][4]*16) + (matrix[i][5]*32) + (matrix[i][6]*64) + (matrix[i][7]*128); 
        
        shiftOut(dataPin, clockPin, MSBFIRST, array_c); //byte for columns
        shiftOut(dataPin, clockPin, MSBFIRST, r[i]); //byte for rows

        digitalWrite(latchPin, 1);        
  }  
  }

Can it be a solution, or should I try with another way?

It might work, yes.

But it would be simpler to use millis() to time when to move your "moving led".

PaulRB: It might work, yes.

Yes it works :D

PaulRB: But it would be simpler to use millis() to time when to move your "moving led".

Thank you for this solution, at the beginning of the code I added:

volatile long lastTime = 0;

and before the "moving led code:

  if ((millis() - lastTime) > TimeDelay)
   {
    lastTime= millis();
//here the "moving led" code
}

where TimeDelay is 500ms.

Thank you! :)

It should “unsigned long” not “volatile long” in this case. Well done.

PaulRB:
It should “unsigned long” not “volatile long” in this case. Well done.

Perfect!! :smiley: