Multiple led sequence over time

[Mod edit:
This question is closely related to: Powering Arduino Mega with 9V power supply ]

I have a project containing 60 leds. Each led have its own pattern for be either in on state or off state.

at second 0: led 8,13,16 are on for one second.
at second 1: led 9 & 14 are on for one second.
at second 2: led 15 & 21 are on for one second etc etc

how can I make this happen in arduino? In total I will have 60 leds and around 15 minutes of sequence. Can someone please direct me?
Thanks!

Are these addressable LEDs? Or you drive them with individual GPIO pins?

The most memory efficient way is to create a pattern buffer, with individual bits representing an on/off state

uint8_t patterns[8][] = {
{ 0b00100010, 0b11100011, ... },
{ 0b00111010, 0b10000011, ... },
};

8 byte rows will hold 64 LED states. You can write up a separate sketch or program to generate the tables, too. From a spreadsheet, for example.

You can put the pattern buffer in flash memory where there is a lot more space available. What board or processor are you using?

those are individual GPIO pins

That could be a disaster. Can we see a schematic please?

I'm using arduino MEGA

can you explain more about the code you wrote?
what the firt row represent? ```
{ 0b00100010, 0b11100011, ... },

What do you mean by schematics?

If you're not a native English speaker you can Google translate. Also I have a habit. If some question was left unanswered, I stop until that question is answered.

I'm using arduino Mega. I have 10mm green led connected via the Anode leg to each arduino digital pins between D2 to D62 with 1k resistor to ground via Cathode leg. I have no schematics to show.
I would like to control each led of those 60 individual leds independently .
I was thinking to write an array of pattern for each led but it will be very long array for 60 leds and 15 minute sequence.

here is an example of 16 leds and 29 seconds:

#define N_LEDS 16   //number of LEDs
#define N_STATES 29 //number of pattern states
bool pattern[N_LEDS][N_STATES] = 
{ //required display pattern
  
  {1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0}, //LED01
  {0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0}, //LED02
  {0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0}, //LED03
  {0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0}, //LED04
  {0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0}, //LED05
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0}, //LED06
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0}, //LED07
  {0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0}, //LED08
  {1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1}, //LED09
  {0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,}, //LED10
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0}, //LED11
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0}, //LED12
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0}, //LED13
  {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1}, //LED14
  {0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}, //LED15
  {0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0}  //LED16
};
const int LED_PIN[16] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18}; /

void setup() {
  for(int i=0; i<N_LEDS; ++i)
    pinMode(LED_PIN[i], OUTPUT);
}


void loop() 
{
  for(int pattern_state=0; pattern_state<N_STATES; ++pattern_state)
  {
    for(int j=0; j<N_LEDS; ++j) 
    {
      digitalWrite(LED_PIN[j], pattern[j][pattern_state]);
    }
    delay(1000);
  }

Okay, won't you run out of memory soon, with that approach? What about the maximum supply current to the Mega processor, with all those LEDs driven from I/O pins? There is a limit.

You can write a matrix with only the LEDs on for each step, then you read each raw of the matrix until the end: for the n raw, you have to turn off LEDs in n-1 raw and turn on LEDs in n raw.
`

bool pattern

You are wasting 7 bits out of every boolean. Use bit values as previously suggested

Each led is drewing around 4mA and no more then 10-15 leds will be on at any given moment so I think in term of current drew from arduino I will be fine

You would need 15x60x60 = 54,000 bytes to represent it in bool type. 6750 bytes, if you pack the bits.

Any recommendations? I really not sure what to do...

Okay, 4mA x 15 = 60mA. You can't safely turn on more than 200mA/4mA = 50.

I gave you a good recommendation. To pick individual bits, use the BV() macro. Or 'bitRead()' if I'm not mistaken.

You could represent the state of 8 LEDs as

bool leds[] = {0,1,0,1,0,1,0,1];  //8 bytes

or

leds = 0b01010101;  //1 byte

See post #3

If you pack the bits, you might fit it in the Mega's RAM, so a "normal" sketch. But any other way, you would have to use flash, and pray that it would fit there.

someine on reddit shared with me that code:

// background LED blinker example
#define MAX_BLINKERS 40 // maximum simultaneous background blinkers
struct  // background blinker control data
{ uint8_t  led_index; // 0..254, 255=not used indicator
  uint16_t count;     // number of blink cycles
  uint16_t msec;      // cycle time
  uint32_t delay_ms;  // delay before starting
  uint16_t halfcycs;  // count remaining
  uint32_t tm;        // half cycle timer
} bb[MAX_BLINKERS];

void setup() 
{
  for (uint8_t i=0; i < MAX_BLINKERS; i++) bb[i].led_index = 255; // mark not used
  for (uint8_t i=2; i <= 12; i++) pinMode( i, OUTPUT ); // LED output pins
}

// control the LED hardware
void setLED( uint8_t led_index, boolean on_off )
{
  digitalWrite( 2+led_index, on_off ); // LEDs are on consecutive pins from pin 2...
}

// start a background blinker
void backgndBlink( uint8_t led_index, uint16_t cycles, uint16_t cycle_msec, uint16_t initial_delay_msec )
{
  // find unused entry
  uint8_t i;
  for (i=0; i < MAX_BLINKERS; i++) if (bb[i].led_index == 255) break;
  if (i >= MAX_BLINKERS) return; // no space left, ignore blinker request
  // copyin control parms
  bb[i].led_index = led_index;
  bb[i].count     = cycles;
  bb[i].msec      = cycle_msec/2; // 50% duty cycle
  bb[i].delay_ms  = initial_delay_msec;
  // init blinker state
  bb[i].tm        = millis();
  bb[i].halfcycs  = cycles*2;
  if (bb[i].delay_ms == 0) setLED(led_index,true); // start blink'n
}

// run the background blinkers
boolean backgndYield() // returns true if any blinkers are active
{  
  boolean blink_active = false;
  for (uint8_t i=0; i < MAX_BLINKERS; i++)
    if (bb[i].led_index != 255) // blinker active?
    { blink_active = true;
      if (bb[i].delay_ms) // in initial delay period?
      { if (millis() - bb[i].tm >= bb[i].delay_ms)
        { bb[i].delay_ms = 0;  // end delay period
          bb[i].tm = millis();
          setLED(bb[i].led_index,true); // start blink'n
        }
      }
      else if (millis() - bb[i].tm >= (uint32_t)(bb[i].msec))
        if (--bb[i].halfcycs == 0)
          bb[i].led_index = 255; // end blinker
        else // blink
        { bb[i].tm = millis();
          setLED( bb[i].led_index, !(bb[i].halfcycs & 1) );
        }
    }
  return blink_active;        
}

// use this instead of delay() to run the backgnd blinkers
void backgndDelay( uint16_t msec )
{
  for (uint32_t tm = millis(); millis() - tm < (uint32_t)msec; ) backgndYield();
}

void loop()
{
  // start group of blinkers
  backgndBlink( 0, 10, 1000, 0    ); // 10 cycles at 1 Hz rate
  backgndBlink( 1, 20,  500, 4000 ); // 20 cycles at 2 Hz after 4 seconds
  backgndBlink( 2, 10, 1000, 7000 ); // 10 cycles at 1 Hz rate 3 seconds later

  backgndDelay( 5000 ); // delay 5 seconds
  
  // start another group of blinkers
  backgndBlink( 3, 10, 1000, 0    ); // 10 cycles at 1 Hz rate
  backgndBlink( 4, 20,  500, 2000 ); // 20 cycles at 2 Hz after 2 seconds
  backgndBlink( 5, 10, 1000, 8000 ); // 10 cycles at 1 Hz rate 6 seconds later

  while (backgndYield()); // wait for all blinkers to end  
}

it worked very fine until I had too many lines and it stopped to work. Can someone see if I can use that code for my needs?