Number of LEDs may change. Constants help

I want to be able to change the number of LEDs per strip. In my project there will always be 8 zones, but the number of LEDs in each zone may change. I’m using (will be using) bluetooth to change various settings in the program, but I need you help.

//includes
#include <SoftwareSerial.h>
#include <FastLED.h>

SoftwareSerial BLE_Shield(4,5);

int knobPositions[6];
int switchPositions[3];


//define Zone pins
const int ZONES[8] = {6,7,8,9,10,11,12,13};
int numLEDsPerZone[8];
CRGB zoneLEDS[]={};

//define utility/led pins
int status_led = 2;


void setup() {
  BLE_Shield.begin(9600);

  //setup zones
  for (int i=0; i < sizeof(ZONES); i++){
   CRGB zoneLEDS[numLEDsPerZone[i]];
   pinMode(ZONES[i],OUTPUT);
   FastLED.addLeds<NEOPIXEL, ZONES[i]>(zoneLEDS, numLEDsPerZone[i]); 
  }
}

void loop() {
  //read from the BLE Board, somehow... :/

  /*if (BLE_Shield.available() >= 9) // this will only be true if there are at least 9 bytes to read
 {
   for (int i=0; i <=8 ; i++)
   {
    array[i] = BLE_Shield.read(); 
   }
 }*/

 }

I get the error :

'ZONES' cannot appear in a constant-expression

What I’m trying to do is set the number of LEDs per zone and the pattern to display per zone. And then once i get the hang of that I want to be able to Serially feed other settings.

Any suggestions out there?

Thanks!
Keith

I get the error :

That is not the complete error message. The complete error message includes a line number.

CRGB zoneLEDS[]={};

A zero element array seems pretty pointless.

A link to the FastLED library would be useful.

Thanks for the reply paul

The error comes from the line where i declare FastLED.addleds and try to user ZONES
Here is a link to the FastLED Library:
GitHub - FastLED/FastLED: The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues" just for tracking library bugs / enhancements.
thanks for all your help.
Keith

I looked at the library. I see several addLeds methods. The only one that makes sense, with the number of arguments you are supplying is:

	template<ESPIChipsets CHIPSET, EOrder RGB_ORDER> static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
return addLeds<CHIPSET, SPI_DATA, SPI_CLOCK, RGB_ORDER>(data, nLedsOrOffset, nLedsIfOffset);
}

But, I can’t figure out where EOrder is defined, and I can’t see that the array element you are specifying is an EOrder.

You can’t use a loop variable to index your array when using it as a template parameter.

FastLED.addLeds<NEOPIXEL, ZONES[i]>(zoneLEDS, numLEDsPerZone[i]);

The value of ‘i’ isn’t constant.

The value of 'i' isn't constant.

But ZONES[ i ] is.

PaulS:
But ZONES[ i ] is.

This is why i dont get it.

Paul the value you are referencing is the Data pin number. I'm not sure how that library is defining it

PaulS:
But ZONES[ i ] is.

This constness of the resulting expression is irrelevant, the full expression as presented is not.

'i' is created and incremented by the loop. You need to loop at compile time or simply hand write each call using actual constants (unroll the loop).

Ok. So, unroll the loop - understood.

Back to one of my original questions; How do i set the number of LED per strip dynamically?

How do i set the number of LED per strip dynamically?

I think that that depends on what you mean by dynamically. Does that mean that the number of LEDs in a strip is going to change while the Arduino is running? How is that possible? Are you waving a soldering iron around wiring with voltage applied?

PaulS:
I think that that depends on what you mean by dynamically. Does that mean that the number of LEDs in a strip is going to change while the Arduino is running? How is that possible? Are you waving a soldering iron around wiring with voltage applied?

LOL!

No, basically i printed a board. I want to use it eventually with multiple projects, fiddling with the LED design.

So, 2 months down the line i may want LEDs in my living room, rather than my office and the space may require more or less strips of leds...

Should i just setup the board with the max number of LEDs per zone (i dont know what that would be) and set trailing LEDs (ghost LEDs) black and if they are trailing LEDs ignore them...is that efficient?

Thanks
Keith

is my calculation accurate if i have 5m of 144LEDs/m per zone (x8) [5,760 LEDS]- the draw is about 1.7A?

EEPROM would be a good place to store the number of LEDs.

aarg:
EEPROM would be a good place to store the number of LEDs.

I was just looking into that! Thanks aarg!

Couldn't you add an SD card that has configuration data?

The function you are using expects to know how many LEDs there are AT RUN TIME. That doesn't have to be a constant (known at compile time).

You could read the configuration file, and use malloc() to allocate memory, and populate the resulting "array" (you actually get a pointer back from malloc()), then pass the pointer to the addLeds() function.

PaulS:
Couldn't you add an SD card that has configuration data?

The function you are using expects to know how many LEDs there are AT RUN TIME. That doesn't have to be a constant (known at compile time).

You could read the configuration file, and use malloc() to allocate memory, and populate the resulting "array" (you actually get a pointer back from malloc()), then pass the pointer to the addLeds() function.

I have my prototype board printed already and i didnt think of that...

i didnt think of that...

Well, that's a bummer.

yeah...plus i find the reading and writing to sd to be intimidating.

I'm reading through the EEPROM docs and do you know why i would want to update and address rather than reWrite to it?

THanks

I’m reading through the EEPROM docs and do you know why i would want to update and address rather than reWrite to it?

Suppose you write with a pen on paper. Then, you try to erase what you wrote, using an appropriate eraser. There is damage to the paper, right? Well, writing to EEPROM involves erasing what was there, first, with some amount of damage. Only erasing what needs to be erased, so that it can be replaced with a new value, minimizes that wear.

ok so once set i would want to use update. BUT I think in my case i will want to use "avr/eeprom.h" so that i can save structs or data structures per zone, right?