Being relatively new to Arduino I am trying to come to grips with the coding side of things. With regard to the following code
#include "LedControl.h"
int timer = 50;
LedControl lc=LedControl(12,11,10,1);
void setup()
{
lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
}
void down()
{
for(int row = 0; row < 8 ; row ++)
{
for(int col = 0; col < 8; col ++)
{
lc.setLed(0,row,col,true);
delay(timer);
}
}
}
void up ()
{
for(int row = 7; row >=0; row --)
{
for(int col = 7; col >=0; col --)
{
lc.setLed(0,row,col,false);
delay(timer);
}
}
}
void loop ()
{
down ();
// lc.clearDisplay(0);
up ();
}
Which as I am sure you can see is to control an 8 x 8 LED matrix with a Max 7219 progressively lighting the LED's from position (0, 0) to LED at position (7, 7) the top row of the matrix being LED (0, 0) TO LED (0,7) and then once all 64 LED's are on, turning them off one by one back to the starting position.
With regard to the first two for loops, in the void down () function, presumably in the first for loop, int row = 0; initialises the row counter variable as zero, then row < 8 ; is the test condition which is true, so the code moves to the second for loop and goes through the same procedure for the columns and if this test is also true then the code lc.setLed(0,row,col,true); is executed lighting the LED at position (0, 0) then implementing delay(timer);
What I am having trouble understanding is why the code for the columns, increments from column 0 to column 7, before the first for loop then does it's first increment from the initialised row 0 to row 1, prior to the second for loop again incrementing through columns 0 to 7.
I think I understand the basic sequence of events in one for loop but two nested like this is confusing me. Can anyone please take a few minutes to try and explain the sequence of decisions that this code executes.
Thanks for reading and I hope my rambling description makes sense,
Pedro.