Skip to content

Commit aeb9e30

Browse files
Merge pull request #43 from adafruit/pb-swirl
Add rainbow() fill function for easy color swirl
2 parents bb1e398 + c4c287d commit aeb9e30

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Adafruit_DotStar.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

Adafruit_DotStar.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ class Adafruit_DotStar {
186186
static uint32_t ColorHSV(uint16_t hue, uint8_t sat = 255, uint8_t val = 255);
187187
static uint32_t gamma32(uint32_t x);
188188

189+
void rainbow(uint16_t first_hue = 0, int8_t reps = 1,
190+
uint8_t saturation = 255, uint8_t brightness = 255,
191+
boolean gammify = true);
192+
189193
private:
190194
uint16_t numLEDs; ///< Number of pixels
191195
uint8_t dataPin; ///< If soft SPI, data pin #

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit DotStar
2-
version=1.1.4
2+
version=1.1.5
33
author=Adafruit
44
maintainer=Adafruit <info@adafruit.com>
55
sentence=Adafruit DotStar LED Library

0 commit comments

Comments
 (0)