Two For-loops causes errors (infinity problem?) Unsure how to fix.

Thanx to some other friendlies on this forum, i've managed to use a for loop to display LED-pixels on a Matrix in sync with an RTC-clock.

Both for loops work excellent, i've tested them seperatly.

But the problem starts when the two for loops are both introduced. Then the code causes the display to go completely wonky

I think i've got an infinityloop problem, but my code skills are seriously lacking.

I believe i need to introduce a break or some other form of reset in both loops, to keep them both functioning at the same time.

How would I code that?

if (Display_Mode == 3) //This displaymode will display a figure build up from specific LED-pixels - each one representing a specific second or minute.
  {
    Display_Mode_Next = 1;
     
    byte Sec=1;    
    byte Pix_Sec= now.second();
    byte secondRow[] = {16,17,18,18,19,19,20,21,21,22,22,23,24,24,25,25,24,24,23,22,22,21,21,20,19,19,18,18,17,16,15,14,13,13,12,12,11,10,10,9,9,8,7,7,6,6,7,7,8,9,9,10,10,11,12,12,13,13,14,15};
    byte secondColumn[] = {1,1,1,2,2,3,3,3,4,4,5,5,5,6,7,8,9,10,10,10,11,11,12,12,12,13,13,14,14,14,14,14,14,13,13,12,12,12,11,11,10,10,10,9,8,7,6,5,5,5,4,4,3,3,3,2,2,1,1,1};
    byte Min=1;
    byte Pix_Min= now.minute();
    byte minuteRow[] = {16,17,16,17,18,19,20,19,20,21,22,23,22,23,24,24,23,22,23,22,21,20,19,20,19,18,17,16,17,16,15,14,15,14,13,12,11,12,11,10,9,8,9,8,7,7,8,9,8,9,10,11,12,11,12,13,14,15,14,15};
    byte minuteColumn[] = {2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,8,9,9,10,10,10,11,11,12,12,12,13,13,13,13,12,12,12,11,11,10,10,10,9,9,8,8,8,7,7,7,6,6,5,5,5,4,4,3,3,3,2,2,};
    
    matrix.setCursor(0, 0);   // start at top left, with one pixel of spacing
     
    for (Sec=0; Sec<now.second()+1; Sec++) 
    {
    matrix.drawPixel(secondRow[Sec], secondColumn[Sec], matrix.Color333(2, 0, 0));
    }
    
    for (Min=0; Min<now.minute()+1; Min++) 
    {
    matrix.drawPixel(secondRow[Min], secondColumn[Min], matrix.Color333(2, 0, 0));
    }
    
delay(999);
  }
}

The loops are not running at the same time; Atmega's are not mult-threaded. First loop runs and finishes, then second one runs.

Have you really verified that both work alone, ie, by leaving everything else the same and commenting out one of the loops?

byte minuteColumn[] = {2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,8,9,9,10,10,10,11,11,12,12,12,13,13,13,13,12,12,12,11,11,10,10,10,9,9,8,8,8,7,7,7,6,6,5,5,5,4,4,3,3,3,2,2,};

comma at end why?

SecondRow is used for both minutes and seconds. MinuteRow is not used. I suspect this is not what you wanted.

Also, as an aside, you define Pix_min and Pix_sec but never use them.

"The loops are not running at the same time; Atmega's are not mult-threaded. First loop runs and finishes, then second one runs"

So i won't be able to display both the seconds and minutes at the same time using this for-loop method?
I'm programming an Uno.

Good catch on the comma and the inconsistensies in the code....

Yes i've tested both loops seperatly (this time again with the correct syntax)

They still both work, but just not at the same time.

if (Display_Mode == 3) //This displaymode will display a figure build up from specific LED-pixels - each one representing a specific second or minute.
  {
    Display_Mode_Next = 1;
     
    byte Sec=1;    
    byte Pix_Sec= now.second();
    byte secondRow[] = {16,17,18,18,19,19,20,21,21,22,22,23,24,24,25,25,24,24,23,22,22,21,21,20,19,19,18,18,17,16,15,14,13,13,12,12,11,10,10,9,9,8,7,7,6,6,7,7,8,9,9,10,10,11,12,12,13,13,14,15};
    byte secondColumn[] = {1,1,1,2,2,3,3,3,4,4,5,5,5,6,7,8,9,10,10,10,11,11,12,12,12,13,13,14,14,14,14,14,14,13,13,12,12,12,11,11,10,10,10,9,8,7,6,5,5,5,4,4,3,3,3,2,2,1,1,1};
    byte Min=1;
    byte Pix_Min= now.minute();
    byte minuteRow[] = {16,17,16,17,18,19,20,19,20,21,22,23,22,23,24,24,23,22,23,22,21,20,19,20,19,18,17,16,17,16,15,14,15,14,13,12,11,12,11,10,9,8,9,8,7,7,8,9,8,9,10,11,12,11,12,13,14,15,14,15};
    byte minuteColumn[] = {2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,8,9,9,10,10,10,11,11,12,12,12,13,13,13,13,12,12,12,11,11,10,10,10,9,9,8,8,8,7,7,7,6,6,5,5,5,4,4,3,3,3,2,2};
    
    matrix.setCursor(0, 0);   // start at top left, with one pixel of spacing
     
    for (Sec=0; Sec<now.second()+1; Sec++) 
    {
    matrix.drawPixel(secondRow[Sec], secondColumn[Sec], matrix.Color333(2, 0, 0));
    }
    
    // THIS ^^^^^ WORKS But not at the same time as the minute loop that also works.
    
    for (Min=0; Min<now.minute()+1; Min++) 
    {
    matrix.drawPixel(minuteRow[Min], minuteColumn[Min], matrix.Color333(2, 2, 2));
    }
    
delay(999);
  }
}

Could i somehow put the for loops in an if or while statement?

What kind of display is this? Link to its product page or datasheet online?

It looks like you're drawing pixels and I have an expectation that the pixel stays lit after it's drawn. How do they ever turn off?

How about this to draw both at the same time?

    for (byte i=0; i<=60; i++) 
    {
    if(i<=now.second()) 
        {
        matrix.drawPixel(secondRow[Sec], secondColumn[Sec], matrix.Color333(2, 0, 0));
        }
    else 
        {
         //draw "black" to turn off the LEDs which must be off
         }
    if(i<=now.minute()) 
        {
        matrix.drawPixel(minuteRow[Min], minuteColumn[Min], matrix.Color333(2, 2, 2));
    else 
        {
         //draw "black" to turn off the LEDs which must be off
         }
    }
    }

I'm building my prototype with

arduino Uno
Adafruit RGB-LED Matrix 16x32 (Medium 16x32 RGB LED matrix panel - 6mm Pitch : ID 420 : $24.95 : Adafruit Industries, Unique & fun DIY electronics and kits)
A DS1307RTC
and a standard IR receiver

Right now i'm trying the suggestion. But i'm a bit slow in comprehending this

    if (Display_Mode == 3) //This displaymode will display a figure build up from specific LED-pixels - each one representing a specific second or minute.
  {
    Display_Mode_Next = 1;
    
    byte Sec=1;    
    byte Pix_Sec= now.second();
    byte secondRow[] = {16,17,18,18,19,19,20,21,21,22,22,23,24,24,25,25,24,24,23,22,22,21,21,20,19,19,18,18,17,16,15,14,13,13,12,12,11,10,10,9,9,8,7,7,6,6,7,7,8,9,9,10,10,11,12,12,13,13,14,15};
    byte secondColumn[] = {1,1,1,2,2,3,3,3,4,4,5,5,5,6,7,8,9,10,10,10,11,11,12,12,12,13,13,14,14,14,14,14,14,13,13,12,12,12,11,11,10,10,10,9,8,7,6,5,5,5,4,4,3,3,3,2,2,1,1,1};
    byte Min=1;
    byte Pix_Min= now.minute();
    byte minuteRow[] = {16,17,16,17,18,19,20,19,20,21,22,23,22,23,24,24,23,22,23,22,21,20,19,20,19,18,17,16,17,16,15,14,15,14,13,12,11,12,11,10,9,8,9,8,7,7,8,9,8,9,10,11,12,11,12,13,14,15,14,15};
    byte minuteColumn[] = {2,2,3,3,3,4,4,5,5,5,6,6,7,7,7,8,8,8,9,9,10,10,10,11,11,12,12,12,13,13,13,13,12,12,12,11,11,10,10,10,9,9,8,8,8,7,7,7,6,6,5,5,5,4,4,3,3,3,2,2};
    
    matrix.setCursor(0, 0);   // start at top left, with one pixel of spacing
     
    for (byte i=0; i<=60; i++)
    {
    if(i<=now.second())
        {
        matrix.drawPixel(secondRow[i], secondColumn[i], matrix.Color333(2, 0, 0));
        }
    else
        {
        matrix.drawPixel(16, 1, matrix.Color333(2, 0, 0)); // 0 sec RESET TO BLACK + first SECOND RED
        matrix.drawPixel(17, 1, matrix.Color333(0, 0, 0)); // 1 sec
        matrix.drawPixel(18, 1, matrix.Color333(0, 0, 0)); // 2 sec
        matrix.drawPixel(18, 2, matrix.Color333(0, 0, 0)); // 3 sec 
        matrix.drawPixel(19, 2, matrix.Color333(0, 0, 0)); // 4 sec
        matrix.drawPixel(19, 3, matrix.Color333(0, 0, 0)); // 5 sec
        matrix.drawPixel(20, 3, matrix.Color333(0, 0, 0)); // 6 sec
        matrix.drawPixel(21, 3, matrix.Color333(0, 0, 0)); // 7 sec
        matrix.drawPixel(21, 4, matrix.Color333(0, 0, 0)); // 8 sec   
        matrix.drawPixel(22, 4, matrix.Color333(0, 0, 0)); // 9 sec
        matrix.drawPixel(22, 5, matrix.Color333(0, 0, 0)); // 10 sec
        matrix.drawPixel(23, 5, matrix.Color333(0, 0, 0)); // 11 sec
               
etc.. etc. etc....

        matrix.drawPixel(15, 1, matrix.Color333(0, 0, 0)); // 59 sec
         }
    if(i<=now.minute())
        {
        matrix.drawPixel(minuteRow[i], minuteColumn[i], matrix.Color333(2, 2, 0));
        }
    else
        {
        matrix.drawPixel(16, 2, matrix.Color333(2, 2, 0)); // 0 min RESET TO BLACk + first minute orange
        matrix.drawPixel(17, 2, matrix.Color333(0, 0, 0)); // 1 min
        matrix.drawPixel(16, 3, matrix.Color333(0, 0, 0)); // 2 min  
        matrix.drawPixel(17, 3, matrix.Color333(0, 0, 0)); // 3 min 
        matrix.drawPixel(18, 3, matrix.Color333(0, 0, 0)); // 4 min
        matrix.drawPixel(19, 4, matrix.Color333(0, 0, 0)); // 5 min
        matrix.drawPixel(20, 4, matrix.Color333(0, 0, 0)); // 6 min
        matrix.drawPixel(19, 5, matrix.Color333(0, 0, 0)); // 7 min
        matrix.drawPixel(20, 5, matrix.Color333(0, 0, 0)); // 8 min   
        matrix.drawPixel(21, 5, matrix.Color333(0, 0, 0)); // 9 min
        matrix.drawPixel(22, 6, matrix.Color333(0, 0, 0)); // 10 min
        matrix.drawPixel(23, 6, matrix.Color333(0, 0, 0)); // 11 min
        matrix.drawPixel(22, 7, matrix.Color333(0, 0, 0)); // 12 min
        matrix.drawPixel(23, 7, matrix.Color333(0, 0, 0)); // 13 min
       
etc.. etc. etc....

        matrix.drawPixel(15, 2, matrix.Color333(0, 0, 0)); // 59 min
}
    delay(999);
  }
  }
}

This also give errors. I'm just not smart enough about this whole loop thing i guess..

I can post the complete code if necessary.

Thanks anyway