@@ -636,3 +636,33 @@ uint32_t Adafruit_DotStar::gamma32(uint32_t x) {
636636 y[i] = gamma8 (y[i]);
637637 return x; // Packed 32-bit return
638638}
639+
640+ /* !
641+ @brief Fill DotStar strip with one or more cycles of hues.
642+ Everyone loves the rainbow swirl so much, now it's canon!
643+ @param first_hue Hue of first pixel, 0-65535, representing one full
644+ cycle of the color wheel. Each subsequent pixel will
645+ be offset to complete one or more cycles over the
646+ length of the strip.
647+ @param reps Number of cycles of the color wheel over the length
648+ of the strip. Default is 1. Negative values can be
649+ used to reverse the hue order.
650+ @param saturation Saturation (optional), 0-255 = gray to pure hue,
651+ default = 255.
652+ @param brightness Brightness/value (optional), 0-255 = off to max,
653+ default = 255. This is distinct and in combination
654+ with any configured global strip brightness.
655+ @param gammify If true (default), apply gamma correction to colors
656+ for better appearance.
657+ */
658+ void Adafruit_DotStar::rainbow (uint16_t first_hue, int8_t reps,
659+ uint8_t saturation, uint8_t brightness,
660+ bool gammify) {
661+ for (uint16_t i = 0 ; i < numLEDs; i++) {
662+ uint16_t hue = first_hue + (i * reps * 65536 ) / numLEDs;
663+ uint32_t color = ColorHSV (hue, saturation, brightness);
664+ if (gammify)
665+ color = gamma32 (color);
666+ setPixelColor (i, color);
667+ }
668+ }
0 commit comments