Hi Folks, first post in the group, I have a question,

Hi Folks, first post in the group, I have a question, I would like to set the num_leds dynamically from a dip switch block, I am working on a project that lets me daisy chain blocks of 30LED’s at a time and my arduino is in a project box, a set of dip switches would allow me to select how many strips I’m using rather than having to upload a different sketch each time, is this even possible?

Actually, literally, dynamically reallocating the LED string configuration on an Arduino is a big pain. But there are often other ways to achieve what you want that are totally doable.

Different people have different ways to achieve similar goals. One thing that I’ve done myself is this: program the Arduino AS IF all of the possible LEDs were connected (eg NUM_LEDS = 400!), and then I just connect and disconnect the actual LED strings as needed. If only 100 are connected, everything still works fine. Since communication with the LED strings is all one-way (Arduino sends data to them and doesn’t get even one bit back in response), the Arduino doesn’t care one whit whether the purported LED strings are actually there or not, or connected or not. Just connect and disconnect the LEDs.

A related approach would be to configure the Arduino code (again) to have NUM_LEDS set to the maximum you’ll support, and have the code read the dip switches to adjust the animation patterns, using only N x 30 pixels ‘actively’, and leaving the rest (which aren’t hooked up anyway!) dark.

Can you share some more details about your project that might help people here suggest ideas?

What he said. I would set NUM_LEDS to a high value, then use the dip switch to adjust the data being sent.

Thank you, that’s much more concise, Ashley.

this is what i’m doing, problem is the strips are sometimes next to each other so the animation is spread out according to the length (zig zag fashion)

You can also sidestep using the FastLED object and instantiate LED controllers directly - one of the pieces we’re doing for 2.1 is to make that a bit easier to do - but the direct LED controllers have a show function that just takes an array of CRGB objects and the number of objects in that array to show.

You can even do this with FastLED 2 - though the class names involved are going to be changing with 2.1 (and i’m making some other changes to hopefully make this easier for advanced users to do):

WS2811Controller<DATA_PIN> MyLeds();

setup() {
MyLeds.init();
}

loop() {
…. etc…
MyLeds.show(someLeds, someCountOfLeds);
}

Take a look in controller.h for the methods that exist directly on a controller. (And for 2.1, at least one of the examples will show off using controllers directly, rather than the FastLED object as a manager).

how does the dip switch work? is it through resistance? maybe you can set up an array referencing the analog input of the dip switch?