Trying to define mylist[0].mysequence[1].seqdel

I have read Arduino Forum and will try to describe my issue as clearly as possible.

Goal: To create a WS2801 based Christmas LED light show of awesomeness that responds to an IR controller. You press a number on the controller and a different lightshow will appear.

I currently have a lightshow working that is a single set of display sequences. Now, I want to expand it to support multiple sets of display sequences (for the IR controller, which I already have working).

A single sequence could be:

  • move 8 red LED's down the strip
    move 8 green LED's down the strip
    move 8 blue LED's down the strip
    move 8 white LED's down the strip
    have all 32 LED's pulse red 5 times
struct SEQ {
  int seqtype;               // Which sequence we use
  int seqnum;               // Number of times to use it
  int seqdel;                 // Delay between each use
};

SEQ mysequence [] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

void setup() {
  Serial.begin(9600);
  Serial.println(mysequence[1].seqdel);                  // this should return a 6
}

void loop() { }

The above works, but I want to have something that allows me to define multiple sets of sequences, such as:

mylist[0].mysequence[1].seqdel;

I've been Googling and have tried several code variants, but haven't got it yet and would appreciate suggestions.

The above works, but I want to have something that allows me to define multiple sets of sequences, such as:

Code:

mylist[0].mysequence[1].seqdel;

mysequence is an array. What is mylist? It doesn't appear anywhere in your code.

mylist would be another array. Here's a failed attempt to define it:

struct SEQ {
  int seqtype;
  int seqnum;
  int seqdel;
};

struct LIST {
  SEQ myseq[3];
} mylist[3];

mylist[0].myseq[] = {{1,2, 3},{4, 5, 6}, {7, 8, 9} };


void setup() {
  
  Serial.begin(9600);
  Serial.println(mylist[0].myseq[1].seqdel);
}

void loop() {
}
mylist[0].myseq[] = {{1,2, 3},{4, 5, 6}, {7, 8, 9} };

You can't initialize an array this way. You need to either initialize the whole list when it is declared, or initialize each element individually.

Try this:

typedef struct {
  int seqtype;
  int seqnum;
  int seqdel;
} SEQ;

struct LIST{
  SEQ *myseq;
};

SEQ list1[] = {{1,2, 3},{4, 5, 6}, {7, 8, 9} }; //Initialise each list seperately
SEQ list2[] = {{11,12, 13},{14, 15, 16}, {17, 18, 19} };
SEQ list3[] = {{21,22, 23},{24, 25, 26}, {27, 28, 29} };
LIST mylist[3] = {list1,list2,list3}; //Merge them all together

void setup() {
  Serial.begin(9600);
  Serial.println(mylist[0].myseq[1].seqdel);
  Serial.println(mylist[1].myseq[2].seqdel); //Print out some random ones to check
  Serial.println(mylist[2].myseq[0].seqdel);
}

void loop() {
}

But part of me wonders why in this situation you don't just do this:

typedef struct {
  int seqtype;
  int seqnum;
  int seqdel;
} SEQ;

//Two dimensional arrays are allowed :)
SEQ myseq[3][3] = {{{1,2, 3},{4, 5, 6}, {7, 8, 9} },{{11,12, 13},{14, 15, 16}, {17, 18, 19} },{{21,22, 23},{24, 25, 26}, {27, 28, 29} }};


void setup() {
  Serial.begin(9600);
  Serial.println(myseq[0][1].seqdel);
  Serial.println(myseq[1][2].seqdel);
  Serial.println(myseq[2][0].seqdel);
}

void loop() {
}

Thanks gents!!

Then when you are finished, you can use your arrays to calculate the eigenfunctions of your Christmas tree lights! :smiley:

LOL. Not quite at the eigenfunctions yet, but Tom's suggestion worked like a charm and I can now select which light sequence I want to display with an IR remote.

Now, I just need to come up with some more sequence ideas.