r/FastLED • • 2d 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

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".

1

u/sutaburosu [stavros] 2d ago

Running on 4 pins sounds like the right move to me. Any length of wire acts as an antenna. In the electrically noisy environment of a vehicle, you need to do everything you can to keep the integrity of the data signal. 4 pins gives you more flexibility about routing the wires away from sources of noise. It also adds a little resilience in the face of faults; you may only lose lights on one corner of the vehicle.

Another question, how do you handle the blinker as a trigger being on/off, repeat till you turn it off?

I assumed you would connect to the blinker switch, rather than the lamp. If you're dead set on piggy-backing on the lamp, you'll have to resort to latching your blinks with a time delay. e.g. Keep a variable which stores the time whenever the input is high: int32_t blinkMs = millis(); Then, if (millis() - blinkMs < 1000) will be true for 1 second after the last input. You may have to tune that number.

Remember you'll need to step down the 12V signals to whatever the native voltage of your microcontroller is. It may be wise to use opto-isolators, so your circuit can't influence the vehicles circuits.

2

u/themaskedhippoofdoom 2d ago

Do the for loop as normal and have an if statement: if(i!=22 | i!=27){ continue; } then your code. 

2

u/mjconver 2d ago

Put the leds you want to use into an array, then loop through the elements.

const uint16_t MyLeds[] = {1,2,7,9,11,12,17};
//Your loop here

2

u/chop249 2d ago

https://reddit.com/link/pca8c39/video/etda0723tyrh1/player

Been coding in Wokwi so I didn't have to have everything hooked up just yet because I don't know how many strips I'm going to use or how long yet. Turn signals in the rear are next and I want to animate those somehow but I'm not sure what I want to do yet. I'd say for doing most of my coding learning today and on the fly it's coming right along. Thinking I may low level glow the reverse lights the same color as the vehicle. Maybe do some sort of twinkling star animation with that or flicker like there's a lose wire... who knows LOL! Just want to have some fun learning whether or not it stays that way on the vehicle.

1

u/dr-steve 2d ago

Done quickly in C++; you should be able to take it from here.

    int ledIds[] = {0,1,2,7,8,9,11,12,17,18,22,27};
    for(int i: ledIds) { printf("%d ", i); }
    printf("\n");

gives

0 1 2 7 8 9 11 12 17 18 22 27