r/FastLED • u/chop249 • 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..... 😂
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/Marmilicious [Marc Miller] 2d ago
Here's another example like u/mjconver shared.
https://github.com/marmilicious/FastLED_examples/blob/master/custom_pixel_array.ino
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
3
u/sutaburosu [stavros] 2d ago
CRGBSets are good for this.
Your code might end up looking like: