I’d like to piggy back on this topic, not with a new question, but with an answer.
Like the original poster, I have struggled to find a way to address multiple NeoPixel strings. My puzzlement was deepened by the fact that when the declaration of multiple strings - like…
static Adafruit_NeoPixel leds1(20, S1_PIXEL_PIN,WS2812);
static Adafruit_NeoPixel leds2(10, S2_PIXEL_PIN, WS2812);
static Adafruit_NeoPixel leds3(10, S3_PIXEL_PIN, WS2812);
/*
is followed by code something like...
*/
void setup() {
leds1.begin();
leds1.show();
}
void loop() {
turnThemOn(leds1);
delay(1000);
leds1.clear();
leds1.show();
}
void turnThemOn(Adafruit_NeoPixel themLeds) {
for (int lp=0 ;lp < themLeds.numPixels(); lp++) {
themLeds.setPixelColor(lp,64,64,0); // Go yellow-ish
}
themLeds.show();
}
it does kind of work… the leds go on to yellow-ish as expected, but then nothing else happens. the clear() back in the main loop never happens and the cycle does not repeat as expected.
I had mentally discounted the possibility that the cause might be to do with the LED string reference, cos - well it works once - how can it be wrong? …and so I wasted a few hours looking elsewhere for my problem. WRONG!
Turns out that, although the method above works that initial time, it trashes the NEOPIXEL data object on the way out…and it never works again until a reset. To be honest, my knowledge of the various possible methods of passing parameters to functions is sketchy, so I can’t explain this issue in detail - perhaps someone more steeped in that can help me out there?
But anyway, having eliminated all other avenues I came back to wondering if that method was wrong. I googled and googled and google and…anyway you get the idea! Eventually having framed the right question (always the trick, right?), I found the answer within the Adafruit support site.
Below is how the code should (roughly) look to work properly. You pass an address pointer (&) to your string and within the function de-reference code that works on the neopixel string “->” When you do that, all is sweetness. Hope this helps someone else not waste time on this problem. Oddly, this particular “how to” is not even mentioned in the usually reliable Uber-guide to NeoPixels from Adafruit. I have emailed this article to them in case they want to include something.
DECLARATIONS OF NEOPIXEL STRINGS REMAIN UNCHANGED…
…
void setup() {
leds1.begin();
leds1.show();
}
void loop() {
turnThemOn(&leds1);
delay(1000);
leds1.clear();
leds1.show();
}
void turnThemOn(Adafruit_NeoPixel *themLeds) {
for (int lp=0; lp< themLeds->numPixels();lp++) {
themLeds->setPixelColor(lp,64,64,0); // Go yellow-ish
}
}
Best regards
Alan T