# Arrays in Arrays?

Hi all;

I am trying to figure out how to call array groups(led groups) within arrays. To test it i have colored leds grouped in arrays. Then I try to call a particular group. Here is the code:

``````int reds[] = {0,3,9,12};
int greens[] = {1,4,7,10};
int blues[] = {2,5,8,11};

int row1[] = {(reds[0], reds[1]), (greens[0], greens[1])};

void setup(){
}

void loop(){
digitalWrite(row1[0], HIGH);
}
``````

The problem is the last led in the group is turned on not both.

I realize for code this simple you would do this a different way but im trying to test calling arrays in arrays.

Any help is much appreciated!!

``````int row1[] = {(reds[0], reds[1]), (greens[0], greens[1])};
``````

Why are you using parentheses? Why are you abusing the comma operator that way?

Dont the commas create a group within the array so you could call a whole group instead of just one thing in an array?

Dont the commas create a group within the array so you could call a whole group instead of just one thing in an array?

The commas separate items in a list. You have two items - (reds[0], reds[1]) and (greens[0], greens[1]).

Within those items, the comma operator does something that is not what you are expecting.

List the values that you expect to see in row1, and we'll explain how to get them there.

To my knowning there is no such thing as a group in c. But there is nothing that prevents you from creating one.
I believe this is what you are trying to do:

``````byte reds[] = {0,3,9,12};
byte greens[] = {1,4,7,10};
byte blues[] = {2,5,8,11};

struct group {
byte *first;
byte *last;
};//group

group row1[] = {{&reds[0], &reds[1]}, {&greens[0], &greens[1]}};

void setup(){
Serial.begin(115200);
writeGroup(row1, sizeof(row1)/sizeof(row1[0]));
}

void loop(){
//  digitalWrite(row1[0], HIGH);
}

void writeGroup(struct group *g, byte no){
for(int i = 0; i<no; i++){//all groups
Serial.print("group: ");
Serial.print(i);
int f = *g[i].first;//value of first item in group
Serial.print("\tfirst: ");
Serial.print(f);
int l = *g[i].last;//value of last item in group
Serial.print("\tlast: ");
Serial.println(l);
int j = 0;
byte k = *(g[i].first+j);
while(k<=l){//repeat if current item is less than last
Serial.print(k);
Serial.print('\t');
j++;
k = *(g[i].first+j);//get next item
}//while
Serial.println();
}//for i
}//writeGroup()
``````

But for this particular problem you would be better off with bit bashing

Sorry that was a typo i meant to say parenthesis not comma. This is what i meant to say:

Dont the parenthesis create a group within the array so you could call a whole group instead of just one thing in an array?

In C/C++, the comma is a binary operator. It “evaluates” bot of its operands, and it’s value is whatever the value of the second one was.

So

``````int x = (1 + 2 + 3);
int y = (1 , 2, 3);
``````

Will set x equal to 6 and y equal to 3.

In this case

``````int reds[] = {0,3,9,12};
int greens[] = {1,4,7,10};
int blues[] = {2,5,8,11};

int row1[] = {(reds[0], reds[1]), (greens[0], greens[1])};
``````

row1 will wind up being an array of 2 ints, initialised to {3, 4}.