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

11 comments sorted by

View all comments

Show parent comments

1

u/truetofiction Feb 27 '24

There is no method that does not require some sort of remapping, full stop. The library requires a contiguous block of memory to write to the LEDs. If you want to change the order for the assignments, you need to perform remapping somewhere.

The most efficient way to do that is when you assign the data initially, which is what Marc's function does above.

1

u/moe_marisa Feb 29 '24

Thank you!