FastLED Mirror Strip


So I am having some issues with wrapping my head around what could potentially be a relatively simple problem to fix and was looking for some guidance.

What am I trying to accomplish?
I have a 144LED/m strip that I would like to create a rainbow pattern on, EXCEPT that instead of filling the whole strip from led 0 to 143, I need it to fill the first half of the strip and then be mirrored over to the 2nd half of the strip. This is so that it looks like the colours are "spawning" in the middle of the strip and moving out towards the ends.

I have successfully managed to fill only the first half of the strip (leds 0 - 71) with my moving rainbow pattern but now I have no idea how to copy/mirror this over to the 2nd half of the strip (leds 72-143).

Unfortunately I cant just wire the 2 halves of the strip form the middle on the same data pin as this is only one of many effects that I will have stored and accessed by a bluetooth app. Not all of the patterns require it to be mirrored from the centre of the strip.

Here are some details about the project:
Board Type: ESP32 (Node MCU ESP-32s v11.10)
LED Type: WS2812B
Total LED Count: 144 (on a 1m strip)

And here is my current code.

#include "FastLED.h"
#define DATA_PIN 2    
#define LED_TYPE WS2812B
#define NUM_LEDS 144  // Total number of pixels in strip
#define BRIGHTNESS 128


void setup() {
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

void loop()
  Rainbow_halfStrip(); // draw Rainbow data to half strip; // display leds

uint8_t hue = 0;

void Rainbow_halfStrip() {

  for (int i = 0; i < NUM_LEDS/2; i++) {
    leds[i] = CHSV(hue + (i* 1), 255, 55);


Is what I have so far going down the wrong path?

If any anyone could steer me in the right direction or has any useful links with how to go about achieving this "rainbow form the centre of the strip" look that im after it would be greatly appreciated as I really am stuck with this one.

Thanks in advance!

71 - 72
70 - 73
69 - 74
68 - 75

Note how the second value is 143 minus the first value. Use 143 - first LED number as the index to the second LED and you will get a mirror effect

Hi Helibob, thanks for the reply!

Im sorry but I forgot to mention that im somewhat of a noob when it comes to programming. I feel like I understand what you are saying but im not sure how to go about implementing it. Please could you elaborate further.

Thanks again!

Do you know how to write your required pattern to LEDs 71 to 0 in that order ?

No, I only ever worked out how to write them from 0-71, not the other way around

You have for loops like this

  for (int i = 0; i < NUM_LEDS / 2; i++)

You could use

  for (int i = NUM_LEDS / 2; i >=0 ; i--)

HeliBob thank you so much, I have managed to get it to work and now I look at it it makes a lot of sense.

I had a weird thing where the 2 sides of the strip seemed out of sync in terms of colour position but subtracting 30 from the hue value on the 2nd side of the strip seems to have brought them back into sync. Weird!

Just in case anyone else needs to know how to do this in future here is the code below:

uint8_t hue = 0;

void loop()
  //FIRST HALF OF STRIP--------------------------
  for (int k = NUM_LEDS/2; k < NUM_LEDS; k++){
    leds[k] = CHSV(hue - (k*2), 255, 55);
  //SECOND HALF OF STRIP--------------------------
  for (int i = NUM_LEDS / 2 - 1; i >=0 ; i--) {
    leds[i] = CHSV(hue - 30 +(i*2), 255, 55);

Thanks again for the guidance.

You don't need 2 for loops, you can do it with one

for (int k = NUM_LEDS / 2; k < NUM_LEDS; k++)
  leds[k] = CHSV(hue - (k * 2), 255, 55);
  leds[71 - k] = CHSV(hue - 30 + (k * 2), 255, 55);

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.