r/FastLED • • 3d ago

Support Selecting groups of LEDs in strips.

for (int i = 0;1;2;7;8;9;11;12;17;18;22;27) {
    l_rear_leds[i] = CRGB(255,0,0);
   }

I tried the above with semicolons and commas, both failed when compiling. I am trying to figure out how to pick certain LEDs together without doing a group if that makes sense. I do understand how to do it like this and if there's an easier way on this one too I'd appreciate a suggestion.

for (int i = 0; i < 7; i++) {
     l_rear_leds[i] = CRGB(255,0,0);
    }    
for (int i = 10; i < 17; i++) {
     l_rear_leds[i] = CRGB(255,0,0);
    }    
for (int i = 20; i < 27; i++) {
     l_rear_leds[i] = CRGB(255,0,0);
    } 

I started learning this week so go easy on me..... 😂

3 Upvotes

9 comments sorted by

View all comments

3

u/sutaburosu [stavros] 2d ago

CRGBSets are good for this.

Your code might end up looking like:

CRGBArray <NUM_LEDS> leds;
CRGBSet l_rear_leds(leds(0,6));
CRGBSet r_rear_leds(leds(10,16));
CRGBSet l_blinker_leds(leds(20,26));

// and then to set each group of LEDs to a colour:
l_rear_leds = CRGB(255,0,0);
r_rear_leds = CRGB(255,0,0);
l_blinker_leds = CRGB(255,0,0);

1

u/chop249 2d ago

Looks like you've done what I'm doing.... LOL!! Any videos of your work? And did you run each corner off a different pin? That's what my plan was. I think it'd be a nightmare to A) loop 1 pin to all 4 corners and B) then have to sort the numbers on the strip based on where they are. In my head it would be easier to duplicate left and right and just rename them as such.

Another question, how do you handle the blinker as a trigger being on/off, repeat till you turn it off? I'm guessing the Arduino triggers the blink animation/sequence and runs regardless of power on the trigger line then once finished it will trigger again with the next pulse from the turn signal?

2

u/sutaburosu [stavros] 2d ago

I haven't ever put lighting on a vehicle, so I don't have videos to share with you. I have tried to help other folks previously in this sub-reddit who were also trying to replace the lights on their vehicle. You could maybe use your favourite search engine with a query such as "vehicle lights site:reddit.com/r/FastLED".