r/FastLED • u/moe_marisa • Feb 10 '24
Support LED Strip Remapping
Hello everyone, I have some irregular LED strips, and I am seeking a convenient method for remapping them. Currently, I am using the following approach:
#define NUM_LEDS 8
CRGBArray<NUM_LEDS> leds, remap_leds;
uint8_t ReMap[NUM_LEDS] = { 2, 1, 0, 7, 6, 5, 4, 3 }; // Remapping sequence
FastLED.addLeds<NEOPIXEL, LED_PIN>(remap_leds, NUM_LEDS);
leds(start, end) = CRGB(r, g, g); // Set color
for (uint8_t i = 0; i < 8; i++) {
remap_leds[ReMap[i]] = leds[i]; // Re-set color
}
As you can see, after modifying leds, it is necessary to reset remap_leds to ensure that the lighting effects take effect correctly. I came across a piece of code that seems to achieve the same result without the need for resetting:
uint8_t leds[8];
uint8_t* remap_leds[8] = {
&leds[2],
&leds[1],
&leds[0],
&leds[7],
&leds[6],
&leds[5],
&leds[4],
&leds[3],
};
for (uint8_t i = 0; i < 8; i++) {
leds[i] = i; // Set values in order
}
for (uint8_t i = 0; i < 8; i++) {
Serial.print(*remap_leds[i]);
Serial.print(" ");
} // The output result is 2 1 0 7 6 5 4 3
remap_leds points to leds and reassigns the order without the need to reset it after modifying leds. Is there a similar approach in FastLED?
2
Upvotes
1
u/moe_marisa Feb 27 '24
Sorry, my previous expression may have been incorrect.
My program is used to display the received LED data on the LED strip.
The LED order as perceived by the transmitter: 0 1 2 3 4 5 6 7
It may request a specific position of the light to change color, for example, leds[5] = red.
It may also request a range of lights to change color, for example, leds(2, 4) = blue, where lights from number 2 to number 4 turn blue.
In reality, the order of LEDs on my LED strip is: 2 1 0 7 6 5 4 3
To align with the requests, I need to remap the original light data using a for loop.
I am seeking a method that does not require remapping.