Hii, Till now i have been using NUM_LEDS = 50 but now i want

Hii, Till now i have been using NUM_LEDS = 50 but now i want it to control this using a push button i.e initially no of LEDs should be fifty then if i press the button once no of LEDs shoul change to 100 and then to 200 and so on.
I have tried some code that i have mentioned below which gives no compile Error but does net change count for number of LEDs and when i try to replace something or the other it gives Error.

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

#define count 5 //for the count of leds
#define DATA_PIN 6
#define COLOR_ORDER RGB
#define LED_TYPE WS2811
#define NUM_LEDS 50
#define BRIGHTNESS 255
int value=50;
int address = 0;
int i,j;

CRGBPalette16 currentPalette;
TBlendType currentBlending;

struct CRGB leds[NUM_LEDS];

void setup()
{
delay(1000);
pinMode(count, INPUT_PULLUP);
LEDS.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
attachInterrupt(digitalPinToInterrupt(count), increase, FALLING);
value = EEPROM.read(address);
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
FastLED.setBrightness(BRIGHTNESS);
}

void loop()
{
series_asc();
FastLED.show();
}

void increase()
{
if(value==300)
{
value=50;
}
value=value+50;
EEPROM.write(address, value);
}

void series_asc()
{
static uint16_t hue16 = 0;
for(i=0;i<NUM_LEDS;i++)
{leds[i] = CHSV(hue16, 255, 255); FastLED.show(); delay(25); }
hue16 += 32;
}

Using #define sets a value that won’t change. I think this is required for the way FastLED compiles and allocates memory based on the size of NUM_LEDS. But I think** you can cheat this by compiling with the NUM_LEDS equal to the max number of pixels you will use, and then use a second variable that can be changed via your push button. You will of course use up the amount of memory needed for your max NUM_LEDS, even if you don’t ever use that many pixels.

#define NUM_LEDS 300 //Your absolute max
unt16_t NUM_SET 50 //Changes with button press

And then use NUM_SET in your for loops instead of NUM_LEDS.

** I think this can work but I haven’t ever done this. There are a few buried G+ posts here about this and getting it working. I seem to remember something perhaps even more tricky then the above too. Search search search.

@Jason_Coon remember anything?

Okay Thanks I will check

@marmil i didn’t find that particular post u mentioned for my problem but i tried the other way u suggested to use a different variable but that keeps that array to be fixed
CRGB leds[NUM_LEDS]; this statement does not take an integer value it gives an error
( array bound is not an integer constant before ‘]’ token )
can u suggest some other way
Thanks

I don’t think there’s another way without triggering a reset on the board and probably reading the number of LEDs from EEprom. You must have enough memory for the maximum number of LEDs anyway so I’d just do as @marmil ​ first suggested.

@Jeremy_Spencer Okay thanks i will try it again,can u please write in detail what do mean by ‘reading the number of LEDs from EEprom’ as i want to change that using a push button and then store it in EEPROM.

It should be possible to store the number of LEDs you want to use in EEprom and read it in setup before declaring the led array.

I’m not sure how to do a soft reset and as I understand it it varies from board to board. It might not even be possible with some boards

@marmil @Jeremy_Spencer
as u suggested i have written the program accordingly and it works perfectly but when i restart the arduino uno board it does not read the NUM_LED from EEPROM instead it starts again from NUM_LED=50.
please check the code that i have posted below:
#include “FastLED.h”
#include <EEPROM.h>
#define DATA_PIN 5
#define CLOCK_PIN 6
#define COLOR_ORDER RGB
#define count 2 //for the count of leds
#define NUM_SET 300

#define BRIGHTNESS 128
#define FRAMES_PER_SECOND 100
int address = 1;
long debouncing_time = 50; //Debouncing Time in Milliseconds
volatile unsigned long last_micros;
CRGB leds[NUM_SET];
int NUM_LEDS=300;
int i,j;

void setup() {
delay(3000);
FastLED.setBrightness(BRIGHTNESS);
pinMode(count, INPUT_PULLUP);
FastLED.addLeds<WS2811,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
attachInterrupt(digitalPinToInterrupt(count), debounceInterrupt, FALLING);
NUM_LEDS = EEPROM.read(address);
}

void loop() {

series_asc();
FastLED.show();

}

void series_asc()
{
static uint16_t hue16 = 0;
EVERY_N_SECONDS(1){hue16 += 32;}
for(i=0;i<NUM_LEDS;i++){leds[i] = CHSV(hue16, 255, 255); FastLED.show(); delay(25); }
}
void debounceInterrupt() {
if((long)(micros() - last_micros) >= debouncing_time * 1000) {
increase();
last_micros = micros();
}
}
void increase()
{
if(NUM_LEDS==300)
{
NUM_LEDS=50;
}
else
{
NUM_LEDS=NUM_LEDS+50;
}
delay(2000);
EEPROM.write(address, NUM_LEDS);
}

@Prince_Gautam Please post code to http://gist.github.com and share the link.

@marmil @Jeremy_Spencer Here i have added a Link

What happens if you comment out line 15 and uncomment line 21?

Which microcontroller are you using?

@Jeremy_Spencer any how it does not read NUM_LEDS from EEPROM it starts from 50,I am using arduino uno R3 which has atmega328p-pu on it.
here is another link

Okay, a single EEprom address will only hold a number up to 255. You need to use two addresses to go over this…

I can’t see any curse to perform a soft reset either…

@Jeremy_Spencer when i push the button once i.e NUM_LEDS=100;
and then restart the uno it still does not read from EEPROM and NUM_LEDS=50;
Can u tell me how allocate 2 address for NUM_LEDS

@marmil @Jeremy_Spencer Check this program linked below

when i push the button once
i.e NUM_LEDS=100;
and then restart the uno it still does not read from EEPROM and NUM_LEDS=50; EEPROM gets cleared and i don’t now why.
Please Help

I Tried other program that stores value in EEPROM but that do not get erased after restart i.e it gives that saved value

@Prince_Gautam ​ Daniel gave an answer to a similar question here:
https://plus.google.com/106464487179878536274/posts/Kx3Sc9LUTtY

@marmil Thanks