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

◆ fill_rainbow_circular() [2/2]

void fl::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 53 of file fill.cpp.

54 {
55 if (numToFill == 0)
56 return; // avoiding div/0
57
58 CHSV hsv;
59 hsv.hue = initialhue;
60 hsv.val = 255;
61 hsv.sat = 240;
62
63 const uint16_t hueChange =
64 65535 / (uint16_t)numToFill; // hue change for each LED, * 256 for
65 // precision (256 * 256 - 1)
66 uint16_t hueOffset = 0; // offset for hue value, with precision (*256)
67
68 for (int i = 0; i < numToFill; ++i) {
69 targetArray[i] = hsv;
70 if (reversed)
71 hueOffset -= hueChange;
72 else
73 hueOffset += hueChange;
74 hsv.hue = initialhue +
75 (uint8_t)(hueOffset >>
76 8); // assign new hue with precise offset (as 8-bit)
77 }
78}
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16