Could someone clarify my thinking about multiple controller examples?
I perhaps mistakenly assumed that wiring up a matrix using leds[strip][num] (described under the heading “Array of led arrays”) might gain performance via some sort of parallel output… now I’m thinking this isn’t the case since the “One array, many strips” also specifies multiple pins but treats the array as one “thing.”
Am I right that FastLED is figuring out which pin controls any given leds[num] in the background and handles it during FastLED.show()?
Currently I did something like this (“Array of led arrays”):
void setup() {
FastLED.addLeds<NEOPIXEL, 10>(leds[0], NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 11>(leds[1], NUM_LEDS_PER_STRIP);
}
But programming-wise, I think this is simpler (“One array, many strips”):
void setup() {
FastLED.addLeds<NEOPIXEL, 10>(leds, 0, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 11>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
}
I have 16 x 16 ws2812b strips but each set of 4 x 16 leds is joined together so I effectively have 4 pins controlling 64 LEDs each. I used the first variant, and find I need three nested for() loops for some stuff:
for(int strip = 0; strip < 4; strip++)
{
for(int seg = 0; seg < 4; seg++)
for(int pix = 0; pix < 16; pix++)
leds[i][(seg * 16) + pix] = CHSV(255, 255, 255);
}
}
}
Hopefully that makes sense? Since programmatically I’m wanting to “walk” along 16 led strips, I need to know which one I’m on. Rather than calculate this for each physical strip and each “segment”), I could save a for() loop if it were just treated as a long array/strip:
for(int seg = 0; seg < 16; seg++)
{
for(int pix = 0; pix < 16; pix++)
leds[(16*seg) + pix] = CHSV(255, 255, 255);
}
}
I’m assuming some veterans here can let me know if I’m thinking about this the right way, and if there’s any reason for a matrix to not use the second method. Maybe the first (and they way I initially tried) is more for physically separated strips. In that case it would let each do something different, but I’ll always be treating this just as a square 256 matrix.
Thanks!
John
P.S. As an aside on controlling led matrices, my primary programming language is R which discourages for() loops in favor of vectorized operations. Do these exist for Arduino C/C++? For example in R you can do %*% for matrix multiplication without the need for an i/j loop through values…