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;
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.
@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.
@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;
@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
@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
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