FastLED 3.9.15
Loading...
Searching...
No Matches

◆ fill_rainbow_circular() [1/2]

void fill_rainbow_circular ( struct CHSV * targetArray,
int numToFill,
uint8_t initialhue,
bool reversed = false )

Fill a range of LEDs with a rainbow of colors, so that the hues are continuous between the end of the strip and the beginning.

The colors making up the rainbow are at full saturation and full value (brightness).

Parameters
targetArraya pointer to the LED array to fill
numToFillthe number of LEDs to fill in the array
initialhuethe starting hue for the rainbow
reversedwhether to progress through the rainbow hues backwards

Definition at line 124 of file colorutils.cpp.

125{
126 if (numToFill == 0) return; // avoiding div/0
127
128 CHSV hsv;
129 hsv.hue = initialhue;
130 hsv.val = 255;
131 hsv.sat = 240;
132
133 const uint16_t hueChange = 65535 / (uint16_t) numToFill; // hue change for each LED, * 256 for precision (256 * 256 - 1)
134 uint16_t hueOffset = 0; // offset for hue value, with precision (*256)
135
136 for (int i = 0; i < numToFill; ++i) {
137 targetArray[i] = hsv;
138 if (reversed) hueOffset -= hueChange;
139 else hueOffset += hueChange;
140 hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit)
141 }
142}
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16