hi,
using the following code, i don't seem to get the result i'm looking for.
state is a variable, which is set outside this code. for this example, state is set to 1, which refers to the first line is sideState (4, 6, 2, 5) these are linked to addressable leds in segments of 2, numbers, (6,7) (10,11) (2,3) (8,9)
int sideLeds[NUM_LEDS_IN_SEGMENT * NUM_SIDES];
initialisation of the led array, this is based on static variables... in my current case its 2*4=8
sideLeds[k] = sideState[state - 1][i] * NUM_LEDS_IN_SEGMENT + (j - 2);
sideState [ x ] [ y ] refers to the 2D array, x is the state, y is the led cluster
#define NUM_LEDS_IN_SEGMENT 2
#define NUM_SIDES 4
int sideLeds[NUM_LEDS_IN_SEGMENT * NUM_SIDES];
byte sideState[6][4] = {
{4, 6, 2, 5}, // 1 0,1
{5, 1, 6, 3}, // 2 2,3
{5, 2, 6, 4}, // 3 4,5
{3, 6, 1, 5}, // 4 6,7
{4, 1, 2, 3}, // 5 8,9
{3, 2, 1, 4} // 6 10,11
};
int state = 1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // start serial for output
}
void loop() {
// put your main code here, to run repeatedly:
for (int k = 0; k < NUM_LEDS_IN_SEGMENT * NUM_SIDES; k++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < NUM_LEDS_IN_SEGMENT; j++) {
sideLeds[k] = sideState[state - 1][i] * NUM_LEDS_IN_SEGMENT + (j - 2);
Serial.print(sideLeds[k]);
}
}
}
Serial.println();
}
my PERCEIVED output, for this instance, where the variables are shown as values
sideLeds[8] = {6,7,10,11,2,3,8,9); and the output on the serial monitor should be 6710112389
but the actual output is;
67101123896710112389671011238967101123896710112389671011238967101123896710112389
which is correct, except its repeated 8 times.
i can see why the code is repeated as the overlying for loop K repeats 8 times,
but i don't know how to input 8 single variables into the array, without it outputting the whole array 8 times.