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

◆ fill_rainbow_circular() [2/2]

void fill_rainbow_circular ( struct CRGB * 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 104 of file colorutils.cpp.

105{
106 if (numToFill == 0) return; // avoiding div/0
107
108 CHSV hsv;
109 hsv.hue = initialhue;
110 hsv.val = 255;
111 hsv.sat = 240;
112
113 const uint16_t hueChange = 65535 / (uint16_t)numToFill; // hue change for each LED, * 256 for precision (256 * 256 - 1)
114 uint16_t hueOffset = 0; // offset for hue value, with precision (*256)
115
116 for (int i = 0; i < numToFill; ++i) {
117 targetArray[i] = hsv;
118 if (reversed) hueOffset -= hueChange;
119 else hueOffset += hueChange;
120 hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit)
121 }
122}
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16