I have a question which may easy for advanced users.

I have a question which may easy for advanced users.

My setup includes 100 LEDs. They are connected in a circle/loop. What I want to know is how I use ‘gradient_fill’ but start and stop at a different location of the circle each. For example, these would be 4 iterations:

  • 0 --> 99
  • 25 --> 99, 0 --> 24
  • 50 --> 99, 0 --> 49
  • 75 --> 99, 0 --> 74

I guess I need to redefine the array indexes or something. But I’m not sure how!? I have figured how to do this on my own with other shapes (like zig/zag strip) and my own coded for-loop, but not when using a defined function.

Thanks, any help is appreciated!!

fill_gradient (leds, 42, CHSV(0,255,255), 99, CHSV(96,255,255), SHORTEST_HUES);

42 = the starting pixel.
CHSV(0,255,255) = the gradient start color.
99 = the ending pixel.
CHSV(96,255,255) = the gradient end color.

SHORTEST_HUES = The hue is a value on a color wheel.  There are always two directions you can go to get from one place on a wheel to another (one hue value to another hue value).  FastLED lets you pick the direction you want to go.  SHORTEST_HUES is the shortest distance between the two values (the most common choice), LONGEST_HUES is the longest way around.  FORWARD_HUES always moves clockwise.  BACKWARD_HUES always moves counter-clockwise.

In the above example, pixels 42-99 will start as red at 42 and transition to green by 99.

Experiment with making the start and end pixel position variables!

Note, instead of HSV you can also use RGB format if you prefer:
fill_gradient_RGB (leds, 42, CRGB(255,0,0), 99, CRGB(0,255,0) );

----------------------------------

Another idea is to create a temporary working array such as:
CRGB leds_temp[NUM_LEDS];
Operate on the temp array as normal:
fill_gradient (leds_temp, CHSV(0,255,255), CHSV(96,255,255) )

and then before calling FastLED.show() shift everything over by a certain amount:

// Copy leds_temp to leds while shifting everything over.
uint8_t shiftBy = 30;
for(int i = 0; i < NUM_LEDS; i++) {
leds[(i + shiftBy) % NUM_LEDS] = leds_temp[i];
}

Ha, I just remembered I have an example that animates the grad start end points.

Thanks Marc! I will try tonight, I can’t wait. The example looks to do exactly what I wanted and will open up some more possibilities! I’ll comment again after I try.

Thanks! After looking at the example code I was able to add the effect I was looking for. Thanks so much. I’ll post a video in a few days.