Multiple led sequence over time

My code at it best should be a loop of 10-15 minutes that wil run for a few hours.
I see that the option to run it on Arduino memory alone with my skills it is almost impossible in the time frame I have.

Another solution that I was think of and found very good one is to use Max/MSP 'Maxuino' to communicate between the Max msp programme and the Arduino. With Max I can make a 10 - 15 minute long sequence and blink the led pretty easy. of course, that is mean I will must have a computer next to the arduino, which I am not sure yet I could.
The best would be to manage and programs it on the Arduino alone but I think I will must add the Max/msp programme along.

What are your thoughts about reply #36?

I'm afraid I will not be able to get it in time.. I do have that prodact for playing mp3 files:

Do you think in any way I could use that to read a .CSV file ?

a pattern with 60 LEDs will take 60 bits per Seconds. Let's put it into 8 one byte variables --> you need 8 bytes per Second
One minute ... 60 x 8 Byte = 480 Byte
10 minutes ... 10 x 60 x 8byte = 4800 Byte

this shouldn't be a problem for a Mega when you use the hints you have already got in this thread.

how should I loop over that 2d array?

uint8_t patterns[8][2] = {
{ 0b00100010, 0b11100011},
{ 0b00111010, 0b10000011},
};
void setup()
{
  Serial.begin(9600);
  for (int i = 2; i < 62; i++)
  {
     pinMode(i, OUTPUT);
  }
}

void loop() {


for (int i = 0; i < 2; i ++)
{
  for (int j = 0 j < 8; j++)
  {
    digitalWrite(j,HIGH)
  }
}
}

No, I do not believe so.

you missed to check if a bit is set or not set.

let's start with a simple example using one simple array:

// Light LEDs in a specific order/pattern
// "Thermometer" Style LED Blinking 2018-09-26; http://forum.arduino.cc/index.php?topic=570493.msg0#new
// Lauflicht in zwei Richtungen rund um den 2018-07-19, http://forum.arduino.cc/index.php?topic=558863.0
// Ähnlich dem Muster von http://forum.arduino.cc/index.php?topic=518131.0
// https://forum.arduino.cc/index.php?topic=711402.0
// by noiasca
// Version 2020-10-30

/* ***************************
    Configuration/Konfiguraton
 * ************************* */

//                                5432109876543210           // das Muster, einfach als Bitfolge in einem 2-Byte dann kann man es einfach in der IDE "hinmalen"
const uint16_t     pattern[] = {0b0000000000000000,          // Led 0 und 11 sollen leuchten
                                0b0000000000000001,
                                0b0000000000000011,
                                0b0000000000000111,
                                0b0000000000001111,
                                0b0000000000011111,
                                0b0000000000001111,
                                0b0000000000000111,
                                0b0000000000000011,
                                0b0000000000000001
                               };

//const uint8_t ledPin[] = {13, 12, 2, 11, 3, 10, 4, 9, 5, 8, 6, 7}; // maximal 16 Pins - vorsicht der erster PIN ist Index 0 - und das ist im Bit-Muster/Pattern die letzte Stelle!!!
const uint8_t ledPin[] = {2, 3, 4, 5, 6, 7};     // maximal 16 Pins! - auf meinem Board
const uint16_t myIntervall = 100;                            // Hinweis: falls weniger als 254ms gewünscht sind, kann man auch auf uint8_t umstellen
#define DEBUG_UART 1                                         // Debugausgaben auf Serieller Schnittstelle falls man keine LEDs hat: 0 nein / 1 ja 

/* ***************************
    Globals / Variablen für den Sketch
 * ************************* */

uint32_t lastMillis = 0;                                  // wann wurde das letzte mal ein Update der LEDs gemacht
uint8_t  actualPattern = 0;                               // welches Muster soll aktuell ausgegeben werden
const size_t totalNoPattern = sizeof(pattern) / sizeof(pattern[0]);   // Ermittlung wie viele Pattern definiert wurden, ich mach das zur Laufzeit, weil ich mir das abzählen sparen wollte.
const size_t totalNoPins = sizeof(ledPin) / sizeof(ledPin[0]);        // Ermittlung wie viele Pins definiert wurden um die Konfiguration zu vereinfachen

/* ***************************
    Setup
 * ************************* */

void setup() {
#if DEBUG_UART
  Serial.begin(115200);
  Serial.println(F("\nLED Lauflicht in 2 Richtungen"));
#endif

  for (uint8_t i = 0; i < totalNoPins; i++) {
    pinMode(ledPin[i], OUTPUT);
  }
}

/* ***************************
    Main - Loop
 * ************************* */

void loop() {
  if (millis() - lastMillis >= myIntervall)
  {
    actualPattern++;
    if (actualPattern >= totalNoPattern) actualPattern = 0;
    for (uint8_t i = 0; i < totalNoPins; i++)                      // von der Vorgabe her reichen die 10 - werden alle 16 Leds benötigt müsste man auch im setup() mehr initialisieren
    {
      if (pattern[actualPattern] & (1 << i)) {
#if DEBUG_UART
        Serial.print(F("X"));
#endif
        digitalWrite(ledPin[i], HIGH);
      }
      else {
#if DEBUG_UART
        Serial.print(F(" "));
#endif
        digitalWrite(ledPin[i], LOW);
      }
    }
#if DEBUG_UART
    Serial.print(F(" - "));
    Serial.println(actualPattern);
#endif
    lastMillis = millis();
  }
  // do what ever you want to do unblocked here
}

try to follow the code.
For test purposes you can see the output also on Serial.

If 16bit are not enough, we will see how we can expand this to 32 or 64 bit (but the necessary changes are obvious anyway)

Thanks! so if I understand it right the first column from the right to the left represented the led number and the rows from top to button represented the led state. if I would like to make the sequence longer then 9 seconds I should add more rows. and If I would like to add more leds I should add more columns?

so indeed after the 16 step the sequence is stopped.
How can I expand it?

I will need a sequence of minimum 5 minutes so it will be 300 steps for 60 leds. this even a possible with the Arduino Mega memory?

const uint16_t     pattern[] = {0b100000000000000000000011,          // Led 0 und 11 sollen leuchten
                                0b000000000000000000000110,
                                0b000000000000000000001100,
                                0b000000000000000000011000,
                                0b000000000000000000110000,
                                0b000000000000000001100000,
                                0b000000000000000011000000,
                                0b000000000000000110000000,
                                0b000000000000001100000000,
                                0b000000000000011000000000,
                                0b000000000000110000000000,
                                0b000000000001100000000000,
                                0b000000000011000000000000,
                                0b000000000110000000000000,
                                0b000000001100000000000000,
                                0b000000011000000000000000,
                                0b000000110000000000000000,
                                0b000001100000000000000000,
                                0b000011000000000000000000,
                                0b000110000000000000000000,
                                0b001100000000000000000000,
                                0b011000000000000000000000,
                                0b110000000000000000000000,
                                
                                };
                                

//const uint8_t ledPin[] = {13, 12, 2, 11, 3, 10, 4, 9, 5, 8, 6, 7}; // maximal 16 Pins - vorsicht der erster PIN ist Index 0 - und das ist im Bit-Muster/Pattern die letzte Stelle!!!
const uint8_t ledPin[] = {2, 3, 4, 5, 6, 7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};     // maximal 16 Pins! - auf meinem Board
const uint16_t myIntervall = 200;  

yes.

if you compile the sketch you will see something like

Sketch uses 2318 bytes (7%) of program storage space. Maximum is 32256 bytes.
Global variables use 219 bytes (10%) of dynamic memory, leaving 1829 bytes for local variables. Maximum is 2048 bytes.

for each additional pattern you will need the bytes of your pattern size. Additional 300 steps with 2 byte (16bit) will add 600 bytes to flash and SRAM.

Therefore the next steps are:

  • expand it to 64bit and
  • use PROGMEM

first one is simple (but needs more than just the change from uint16_t to uint64_t, pay attention to the bitshift also!)
For PROGMEM first read the Arduino description how to access data in PROGMEM.

PS: the sequence shouldn't stop after the last pattern, but start from new, hence this row

if (actualPattern >= totalNoPattern) actualPattern = 0;

what about the Sparkfun SD-MMC ?

if I manage to have it - can I use that to store my .scv file and loop over it? will I be able to read 60 different led states at the same frame/second?

Thank you very much for try to help! I'm afraid this is over my knowledge for the moment, especially in the time frame I have.
I might use maxuino (Max/MSP) to sequence the leds or I will try to get a sd card reader so I can use inly the arduino and the card reader with no need for a computer (Max/MSP solution)

I suspect no. Look for shield explicitely stating that it will work for UNO/Mega 5V with level shifters. The part you've linked seems to be for 3.3V only.

I'm not sure if the way to use SD card or other components will make it any easier for you. You could read the SD Card linewise, and then? You have to split the incoming stream more or less in a similar way to get each flag for each LED.

Just did da test, updated the sketch for 64bit, added 300 lines pattern, switched over to an Arduino Mega and got

Sketch uses 5528 bytes (2%) of program storage space. Maximum is 253952 bytes.
Global variables use 2592 bytes (31%) of dynamic memory, leaving 5600 bytes for local variables. Maximum is 8192 bytes.

300 lines with 64bit are "just" 2400 bytes ... no problem for the Mega.
and this is still without the optimzation with PROGMEM.

how should I calculate the memory of 60 leds with 5 minutes pattern? what is the calculation you made?

lets recap:
1 pattern per second
1 second needs a 64bit variable - these are --> 8 byte
60 seconds * 8 byte = 480 byte ---> for one minute
5 Minutes x 480 = 2400 byte --> for 5 minutes

or in other words
5 Minutes are 300 seconds
one 64bit variable per second

So I should be able to run a 5 minute sequence of 60 leds, jut in term of writing it it will be a nightmare?

I see you have your sequence in a table, write some code around it and generate the output.
But in the end you just need these lines of zero and ones...

I'd suggest that you use whatever scripting language your spreadsheet software has to spit out the patterns in a form that can be pasted into the code. Much easier to read and maintain there and you're bound to want to change/fix it a few times.

by the way this are 300 patterns - 64bit with PROGMEM on a UNO

Sketch uses 4920 bytes (15%) of program storage space. Maximum is 32256 bytes.
Global variables use 258 bytes (12%) of dynamic memory, leaving 1790 bytes for local variables. Maximum is 2048 bytes.

so the limitation isn't the RAM or Flash ... only the available Hardware pins :wink:
Will need some cleanup than I can provide the code during nighttime (CET).
You could prepare a meaningfull 64bit array in the meantime ...

typedef uint64_t patternSize;                                // use uint_8, uint16_t, uint32_t or uint64_6 according to the needed LEDs

const patternSize pattern[] PROGMEM {
//  7654321076543210765432107654321076543210765432107654321076543210    // the LED pattern to be displayed, each bit defines one LED state, "paint" your pattern/sequence
  0b0000000000000000000000000000000000000000000000000000000000000000,   // all off
  0b0000000000000000000000000000000000000000000000000000000000000001,   // LED 0 is on
  0b1111111111111111111111111111111111111111111111111111111111111111,   // all LEDs are on