Multiple CRGB objects question..

Multiple CRGB objects question… I’ve got 3 pins, with a different number of LEDs on each pin. I want to be able to control them separately or together. I want to be able to run the same animations (more or less) on each strip. I’ve got each one set up as its own CRGB object, but I can’t figure out how to make the CRGB object into a variable.

I feel like there must be some “int” or “const” or “string” or something I could use for this. Thanks for your help!

#include “SoftwareSerial.h”
#include <FastLED.h>

#define NUM_LEDS 5 // Number of Pixies in the fiber optics
#define NUM_PIXIES 2 // number of pixies in the underglow
#define NUM_CROWN 60 //number of pixies in the crown
#define PIXIEPIN 12
#define FIBERPIN 6
#define CROWNPIN 9

CRGB leds[NUM_LEDS]; //is this the right way to do this?
CRGB strip[NUM_PIXIES];
CRGB crown[NUM_CROWN];

void setup()
{
Serial.begin(9600);
LEDS.addLeds<PIXIE,FIBERPIN,RGB>(leds, NUM_LEDS).setDither(30);
LEDS.addLeds<PIXIE,PIXIEPIN,RGB>(strip, NUM_LEDS).setDither(0);
FastLED.addLeds<NEOPIXEL, CROWNPIN>(crown, NUM_LEDS);
}
//------------------MAIN LOOP----------------
void loop() {
{
fill_solid(leds, NUM_LEDS, CHSV(HUE, SATURATION, BRIGHTNESS)); // Can I change “leds” in this line with a variable of some kind? So I can use this function on the crown or underglow lines?

FastLED.show();
delay(20);
}

Here are two ways to approach it: first, using an explicit “pointer to ‘which’ led array”, and a companion int that says how many pixels in that array. Here, a “selector” variable controls which place the color goes to. This is probably not what you want, but it’s a good starting point:

CRGB* whichLeds; // pointer to SOME array of LEDs
int arrayLength; // how long is that array?

uint8_t selector = random8(3); // just for example

if( selector == 0) {
whichLeds = leds;
arrayLength = NUM_LEDS;
} else if (selector == 1) {
whichLeds = strip;
arrayLength = NUM_PIXIES;
} else { // selector == 2
whichLeds = crown;
arrayLength = NUM_CROWN;
}

fill_solid( whichLeds, arrayLength, CHSV(h,s,v) );

Here’s the second way: using a function that does the filling, and takes parameters about where to draw:

void helpDraw( CRGB* whichLeds, int arrayLength, CRGB color)
{
// draws a pattern into ‘whichLeds’,
// of given length ‘arrayLength’
fill_solid( whichLeds, arrayLength, color);

// here’s how to address whatever array
// is passed in. Example: adding glitter.
if( random8(100) < 10) {
int pos = random16( arrayLength);
whichLeds[ pos ] = CRGB::White;
}
}

…and then here’s how to call that routine, passing in one of the three LED arrays you defined. Note that in each case, you also pass in the length of that array.

uint8_t selector = random8(3); // just for example

if( selector == 0) {
helpDraw( leds, NUM_LEDS, CHSV(h,s,v));
} else if (selector == 1) {
helpDraw( strip, NUM_PIXIES, CHSV(h,s,v));
} else { // selector == 2
helpDraw( crown, NUM_CROWN, CHSV(h,s,v));
}

Hope this helps get things started!

(Happy Thanksgiving! I’m thankful that I get to be able to help!)

PS. When you do the “addLeds” setup line for each pin, make sure to pass in the correct number of LEDs that are actually connected to that pin, e.g., NUM_LEDS, NUM_PIXIES, and NUM_CROWN – not “NUM_LEDS” for all three, I think.

thanks so much Mark!!

Check out the code I wrote to do that: https://github.com/shaynevanasperen/LEDs

That’s super helpful too Shayne. Thank you!