# Max7219 for Linear LED display 150428

Hello Arduino forum

Working on an LED display that will have 320
lights driven by a Max7219 chip.

Right now just running the first eight

by listing in the loop() function

lc.setLed(0,0,0,true);
delay(200);
lc.setLed(0,0,0,false);
delay(200);
lc.setLed(0,0,1,true);
delay(200);
lc.setLed(0,0,1,false);
delay(200);
lc.setLed(0,0,2,true);
delay(200);

and so on to

lc.setLed(0,0,7,false);
delay(200);

But would like to make the code more efficient
by using an If statement with an index.
So for the loop function I tried

``````void loop() {

int indexCol;
int indexRow;

for(int indexCol=0; indexCol<=7; indexCol++)

lc.setLed(0,0,indexCol,true);
delay(200);
lc.setLed(0,0,indexCol,false);
delay(200);
}
``````

But this blinks the first LED and turns
the remaining seven lights
on and does not turn the seven off.

Tried several variations on this but no joy.

Started small just doing the first row
of eight LEDs so
some success could be achieved before
getting the rows and columns working
together. But may need some guidance
in getting the row digit to stay the same while
the columns digit increments seven times,
then increment the row once, increment
the cols seven times, increment the
rows again, increment the cols seven
times and so on.

On top of that the first digit in the lc.setLed
statement will have to hold 64 times
before it moves up one integer and do that
three more time because the system
is meant to operate 320 LEDs which
will take 5 IC 7219s.

If I could get some adult supervision on the
syntax of the For statement it would be much
appreciated.

Thanks.

Allen in Dallas

`````` int indexCol;
int indexRow;

for(int indexCol=0; indexCol<=7; indexCol++)
``````

You have two indexCol variables there. I suggest you lose one of them. Plus put the appropriate stuff in brackets, like this:

``````for(int indexCol=0; indexCol<=7; indexCol++)
{
lc.setLed(0,0,indexCol,true);
delay(200);
lc.setLed(0,0,indexCol,false);
delay(200);
}
``````

Hello Nick and the Arduino forum,

Thanks for the tip on the brackets

The sketch now
works well and runs thru the first eight lights.

Copied below is a sketch called
LEDControl_simple_150427_b.ino
that runs thru sixteen lights
This is the effect sought.

Working to use the for(indexAddr, indexRow, indexCol)
syntax so all 320 addresses don’t have to be
written individually.

Also attached is a sketch called
LEDControl_simple_150427_c.ino
with

void loop() {
int indexCol;
int indexRow;
for(int indexCol=0; indexCol<=7; indexCol++)
{
lc.setLed(0,0,indexCol,true);
delay(200);
lc.setLed(0,0,indexCol,false);
delay(200);
lc.setLed(0,1,indexCol,true);
delay(200);
lc.setLed(0,1,indexCol,false);
delay(200);
}
}

This was done just to see if I could hardwire
the row address because I don’t know how to
write a For statement with two, leave alone,
three arguments. (Eventually when the 65th
LED is reached a third indexAddr argument will be needed.)

But 150427_C lights up the LEDs in this sequence:
0.0, 1.0, 0.1, 1.1, 0.2, 1.2, 0.3, 1.3 etc.
when the sequence sought after is:
0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 1.0, 1.1, 1.2, 1.4 etc.

How does one write a For statement with more than
one argument?
Can it be done?

Thanks.

Allen Pitts, Dallas Texas

PS I guess I could rewire the breadboard so the
LEDs go in the right sequence but then what
to do when I get past 64?

``````// LEDControl_simple_150427_b.ino

//We always have to include the library
#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;

void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

void loop() {

{
lc.setLed(0,0,0,true);
delay(200);
lc.setLed(0,0,1,true);
delay(200);
lc.setLed(0,0,2,false);
delay(200);
lc.setLed(0,0,3,true);
delay(200);
lc.setLed(0,0,4,false);
delay(200);
lc.setLed(0,0,5,true);
delay(200);
lc.setLed(0,0,6,false);
delay(200);
lc.setLed(0,0,7,true);
delay(200);
lc.setLed(0,1,0,false);
delay(200);
lc.setLed(0,1,1,true);
delay(200);
lc.setLed(0,1,2,false);
delay(200);
lc.setLed(0,1,3,true);
delay(200);
lc.setLed(0,1,4,false);
delay(200);
lc.setLed(0,1,5,true);
delay(200);
lc.setLed(0,1,6,false);
delay(200);
lc.setLed(0,1,7,true);
delay(200);
}
}
``````
``````// LEDControl_simple_150427_C.ino

//We always have to include the library
#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;

void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

void loop() {

int indexCol;
int indexRow;

for(int indexCol=0; indexCol<=7; indexCol++)
{
lc.setLed(0,0,indexCol,true);
delay(200);
lc.setLed(0,0,indexCol,false);
delay(200);
lc.setLed(0,1,indexCol,true);
delay(200);
lc.setLed(0,1,indexCol,false);
delay(200);

}
}
``````

Half the post in code tags, and half not. Novel.

How does one write a For statement with more than one argument?
Can it be done?

Argument? Functions take arguments. A “for” loop can do anything you want. eg.

``````for (i = 0, j = 0; i < 10 && j < 20; i++)
{
if (<something>)
j += 10;

}
``````

This is C++. If you aren’t sure how to use “for” loops Google “for loop C” or similar. You don’t need the Arduino experts to tell you that.