Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Madison <dmadison@users.noreply.github.com>2021-08-09 23:26:24 +0300
committerDavid Madison <dmadison@users.noreply.github.com>2021-08-09 23:26:24 +0300
commit12127ccdacb46bf30167785070732c347694fb8a (patch)
treeef081877c0e94d656e36aca0b4ed306631a337d1
parent5cc17b2be88982eb34b1998de22b83fee56d4f07 (diff)
Add fill_rainbow_endless util functions
For filling a rainbow pattern that's continuous in hue between the end of the strip and the beginning. Useful for out-of-the-box rainbow animations on looped strips and LED rings.
-rw-r--r--keywords.txt1
-rw-r--r--src/colorutils.cpp39
-rw-r--r--src/colorutils.h15
3 files changed, 55 insertions, 0 deletions
diff --git a/keywords.txt b/keywords.txt
index 75df500c..91e7b3b1 100644
--- a/keywords.txt
+++ b/keywords.txt
@@ -131,6 +131,7 @@ fill_gradient KEYWORD2
fill_gradient_RGB KEYWORD2
fill_palette KEYWORD2
fill_rainbow KEYWORD2
+fill_rainbow_endless KEYWORD2
fill_solid KEYWORD2
map_data_into_colors_through_palette KEYWORD2
nblend KEYWORD2
diff --git a/src/colorutils.cpp b/src/colorutils.cpp
index a1acaa5a..d1f45bd9 100644
--- a/src/colorutils.cpp
+++ b/src/colorutils.cpp
@@ -62,6 +62,45 @@ void fill_rainbow( struct CHSV * targetArray, int numToFill,
}
+void fill_rainbow_endless(struct CRGB* targetArray, int numToFill, uint8_t initialhue)
+{
+ if (numToFill == 0) return; // avoiding div/0
+
+ CHSV hsv;
+ hsv.hue = initialhue;
+ hsv.val = 255;
+ hsv.sat = 240;
+
+ const uint16_t hueChange = 65536 / (uint16_t)numToFill; // hue change for each LED, * 256 for precision
+ uint16_t hueOffset = 0; // offset for hue value, with precision (*256)
+
+ for (int i = 0; i < numToFill; ++i) {
+ targetArray[i] = hsv;
+ hueOffset += hueChange; // increase precise offset
+ hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit)
+ }
+}
+
+void fill_rainbow_endless(struct CHSV* targetArray, int numToFill, uint8_t initialhue)
+{
+ if (numToFill == 0) return; // avoiding div/0
+
+ CHSV hsv;
+ hsv.hue = initialhue;
+ hsv.val = 255;
+ hsv.sat = 240;
+
+ const uint16_t hueChange = 65536 / (uint16_t)numToFill; // hue change for each LED, * 256 for precision
+ uint16_t hueOffset = 0; // offset for hue value, with precision (*256)
+
+ for (int i = 0; i < numToFill; ++i) {
+ targetArray[i] = hsv;
+ hueOffset += hueChange; // increase precise offset
+ hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit)
+ }
+}
+
+
void fill_gradient_RGB( CRGB* leds,
uint16_t startpos, CRGB startcolor,
uint16_t endpos, CRGB endcolor )
diff --git a/src/colorutils.h b/src/colorutils.h
index f09d525f..237e9400 100644
--- a/src/colorutils.h
+++ b/src/colorutils.h
@@ -37,6 +37,21 @@ void fill_rainbow( struct CHSV * targetArray, int numToFill,
uint8_t deltahue = 5);
+/// fill_rainbow_endless - fill a range of LEDs with a rainbow of colors, at
+/// full saturation and full value (brightness),
+/// so that the hues are continuous between the end
+/// of the strip and the beginning
+void fill_rainbow_endless(struct CRGB* targetArray, int numToFill,
+ uint8_t initialhue);
+
+/// fill_rainbow_endless - fill a range of LEDs with a rainbow of colors, at
+/// full saturation and full value (brightness),
+/// so that the hues are continuous between the end
+/// of the strip and the beginning
+void fill_rainbow_endless(struct CHSV* targetArray, int numToFill,
+ uint8_t initialhue);
+
+
// fill_gradient - fill an array of colors with a smooth HSV gradient
// between two specified HSV colors.
// Since 'hue' is a value around a color wheel,