FastLED 3.9.15
Loading...
Searching...
No Matches
ColorBoost.h
Go to the documentation of this file.
1
11
12// This demo shows use of CRGB::colorBoost() to boost saturation for better LED display, compared to
13// normal colors and colors adjusted with gamma correction.
14// The demo involves animated, ever-changing rainbows (based on Pride2015 by Mark Kriegsman).
15
16#include "FastLED.h"
17#include "fl/math/ease.h"
18
19fl::UITitle title("ColorBoost");
20fl::UIDescription description("CRGB::colorBoost() is a function that boosts the saturation of a color without decimating the color from 8 bit -> gamma -> 8 bit (leaving only 8 colors for each component). Use the dropdown menus to select different easing functions for saturation and luminance. Use legacy gfx mode (?gfx=0) for best results.");
21
22fl::UISlider satSlider("Saturation", 60, 0, 255, 1);
23
24// Create dropdown with descriptive ease function names
26 "None",
27 "In Quad",
28 "Out Quad",
29 "In-Out Quad",
30 "In Cubic",
31 "Out Cubic",
32 "In-Out Cubic",
33 "In Sine",
34 "Out Sine",
35 "In-Out Sine"
36};
39
40// Group related color boost UI elements using UIGroup template multi-argument constructor
42
43#define DATA_PIN 2
44#define LED_TYPE WS2812
45#define COLOR_ORDER GRB
46#define WIDTH 22
47#define HEIGHT 22
48#define NUM_LEDS (WIDTH * HEIGHT)
49#define BRIGHTNESS 150
50
52
53// fl::ScreenMap screenmap(lut.data(), lut.size());
54// fl::ScreenMap screenmap(NUM_LEDS);
57
58void setup() {
59
60 // tell FastLED about the LED strip configuration
62 .setCorrection(TypicalLEDStrip)
63 .setScreenMap(xyMap);
64 // set master brightness control
65 FastLED.setBrightness(BRIGHTNESS);
66
67 // Set default dropdown selections
68 saturationFunction.setSelectedIndex(1); // "In Quad"
69 luminanceFunction.setSelectedIndex(0); // "None"
70}
71
73 switch (value) {
74 case 0: return fl::EaseType::EASE_NONE;
75 case 1: return fl::EaseType::EASE_IN_QUAD;
76 case 2: return fl::EaseType::EASE_OUT_QUAD;
77 case 3: return fl::EaseType::EASE_IN_OUT_QUAD;
78 case 4: return fl::EaseType::EASE_IN_CUBIC;
79 case 5: return fl::EaseType::EASE_OUT_CUBIC;
81 case 7: return fl::EaseType::EASE_IN_SINE;
82 case 8: return fl::EaseType::EASE_OUT_SINE;
83 case 9: return fl::EaseType::EASE_IN_OUT_SINE;
84 }
85 FL_ASSERT(false, "Invalid ease type");
87}
88
89// Animated rainbow wave effect (Pride2015), with matrix divided into three segments to compare:
90// - Normal colors (top)
91// - Colors optimized using colorBoost() (middle)
92// - Colors adjusted using gamma correction (bottom)
94 // Use millis() for consistent timing across different devices
95 // Scale down millis() to get appropriate animation speed
96 uint16_t time = fl::millis() / 16; // Adjust divisor to control wave speed
97 uint8_t hueOffset = fl::millis() / 32; // Adjust divisor to control hue rotation speed
98
99 // Iterate through the entire matrix
100 for (uint16_t y = 0; y < HEIGHT; y++) {
101 for (uint16_t x = 0; x < WIDTH; x++) {
102 // Create a wave pattern using sine function based on position and time
103 uint8_t wave = sin8(time + (x * 8));
104
105 // Calculate hue based on position and time for rainbow effect
106 uint8_t hue = hueOffset + (x * 255 / WIDTH);
107
108 // Use wave for both saturation and brightness variation
109 // uint8_t sat = 255 - (wave / 4); // Subtle saturation variation
110 uint8_t bri = 128 + (wave / 2); // Brightness wave from 128 to 255
111
112 // Create the original color using HSV
113 fl::CRGB original_color = CHSV(hue, satSlider.value(), bri);
114
115 if (y > HEIGHT / 3 * 2) {
116 // Upper third - original colors
117 leds[xyMap(x, y)] = original_color;
118 } else if (y > HEIGHT / 3) {
119 // Middle third - colors transformed with colorBoost()
120 fl::EaseType sat_ease = getEaseType(saturationFunction.as_int());
121 fl::EaseType lum_ease = getEaseType(luminanceFunction.as_int());
122 leds[xyMap(x, y)] = original_color.colorBoost(sat_ease, lum_ease);
123 } else {
124 // Lower third - colors transformed using gamma correction
125 float r = original_color.r / 255.f;
126 float g = original_color.g / 255.f;
127 float b = original_color.b / 255.f;
128
129 r = fl::pow(r, 2.0f);
130 g = fl::pow(g, 2.0f);
131 b = fl::pow(b, 2.0f);
132
133 r = r * 255.f;
134 g = g * 255.f;
135 b = b * 255.f;
136
137 leds[xyMap(x, y)] = fl::CRGB(r, g, b);
138 }
139 }
140 }
141}
142
143void loop() {
144 rainbowWave();
145 FastLED.show();
146}
#define COLOR_ORDER
fl::XYMap xyMap
#define NUM_LEDS
fl::UIDescription description("Demo of the Animatrix effects. @author of fx is StefanPetrick")
fl::UITitle title("Animartrix")
fl::CRGB leds[NUM_LEDS]
#define BRIGHTNESS
int y
Definition simple.h:93
int x
Definition simple.h:92
#define DATA_PIN
Definition ClientReal.h:82
fl::UIDropdown saturationFunction("Saturation Function", easeOptions)
fl::XYMap xyMap
Definition ColorBoost.h:55
fl::string easeOptions[]
Definition ColorBoost.h:25
void rainbowWave()
Definition ColorBoost.h:93
void setup()
Definition ColorBoost.h:58
fl::EaseType getEaseType(int value)
Definition ColorBoost.h:72
fl::UISlider satSlider("Saturation", 60, 0, 255, 1)
fl::UIGroup colorBoostControls("Color Boost", satSlider, saturationFunction, luminanceFunction)
fl::UIDropdown luminanceFunction("Luminance Function", easeOptions)
void loop()
Definition ColorBoost.h:143
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
#define WIDTH
#define LED_TYPE
uint8_t hue
Definition advanced.h:94
#define HEIGHT
#define FL_ASSERT(x, MSG)
Definition assert.h:6
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0) FL_NOEXCEPT
Definition xymap.cpp.hpp:35
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition video.h:15
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
enable_if< is_fixed_point< T >::value, T >::type pow(T base, T exp) FL_NOEXCEPT
EaseType
Definition ease.h:27
@ EASE_IN_OUT_CUBIC
Definition ease.h:34
@ EASE_OUT_QUAD
Definition ease.h:30
@ EASE_IN_QUAD
Definition ease.h:29
@ EASE_NONE
Definition ease.h:28
@ EASE_IN_OUT_QUAD
Definition ease.h:31
@ EASE_IN_CUBIC
Definition ease.h:32
@ EASE_IN_SINE
Definition ease.h:35
@ EASE_OUT_CUBIC
Definition ease.h:33
@ EASE_IN_OUT_SINE
Definition ease.h:37
@ EASE_OUT_SINE
Definition ease.h:36
CRGB colorBoost(EaseType saturation_function=EaseType::EASE_NONE, EaseType luminance_function=EaseType::EASE_NONE) const FL_NOEXCEPT
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38