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/ease.h"
18
19using namespace fl;
20
21UITitle title("ColorBoost");
22UIDescription 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.");
23
24UISlider satSlider("Saturation", 60, 0, 255, 1);
25
26// Create dropdown with descriptive ease function names
28 "None",
29 "In Quad",
30 "Out Quad",
31 "In-Out Quad",
32 "In Cubic",
33 "Out Cubic",
34 "In-Out Cubic",
35 "In Sine",
36 "Out Sine",
37 "In-Out Sine"
38};
41
42// Group related color boost UI elements using UIGroup template multi-argument constructor
44
45#define DATA_PIN 2
46#define LED_TYPE WS2812
47#define COLOR_ORDER GRB
48#define WIDTH 22
49#define HEIGHT 22
50#define NUM_LEDS (WIDTH * HEIGHT)
51#define BRIGHTNESS 150
52
54
55// fl::ScreenMap screenmap(lut.data(), lut.size());
56// fl::ScreenMap screenmap(NUM_LEDS);
59
60void setup() {
61
62 // tell FastLED about the LED strip configuration
64 .setCorrection(TypicalLEDStrip)
65 .setScreenMap(xyMap);
66 // set master brightness control
67 FastLED.setBrightness(BRIGHTNESS);
68
69 // Set default dropdown selections
70 saturationFunction.setSelectedIndex(1); // "In Quad"
71 luminanceFunction.setSelectedIndex(0); // "None"
72}
73
75 switch (value) {
76 case 0: return EASE_NONE;
77 case 1: return EASE_IN_QUAD;
78 case 2: return EASE_OUT_QUAD;
79 case 3: return EASE_IN_OUT_QUAD;
80 case 4: return EASE_IN_CUBIC;
81 case 5: return EASE_OUT_CUBIC;
82 case 6: return EASE_IN_OUT_CUBIC;
83 case 7: return EASE_IN_SINE;
84 case 8: return EASE_OUT_SINE;
85 case 9: return EASE_IN_OUT_SINE;
86 }
87 FL_ASSERT(false, "Invalid ease type");
88 return EASE_NONE;
89}
90
91// Animated rainbow wave effect (Pride2015), with matrix divided into three segments to compare:
92// - Normal colors (top)
93// - Colors optimized using colorBoost() (middle)
94// - Colors adjusted using gamma correction (bottom)
96 // Use millis() for consistent timing across different devices
97 // Scale down millis() to get appropriate animation speed
98 uint16_t time = millis() / 16; // Adjust divisor to control wave speed
99 uint8_t hueOffset = millis() / 32; // Adjust divisor to control hue rotation speed
100
101 // Iterate through the entire matrix
102 for (uint16_t y = 0; y < HEIGHT; y++) {
103 for (uint16_t x = 0; x < WIDTH; x++) {
104 // Create a wave pattern using sine function based on position and time
105 uint8_t wave = sin8(time + (x * 8));
106
107 // Calculate hue based on position and time for rainbow effect
108 uint8_t hue = hueOffset + (x * 255 / WIDTH);
109
110 // Use wave for both saturation and brightness variation
111 // uint8_t sat = 255 - (wave / 4); // Subtle saturation variation
112 uint8_t bri = 128 + (wave / 2); // Brightness wave from 128 to 255
113
114 // Create the original color using HSV
115 CRGB original_color = CHSV(hue, satSlider.value(), bri);
116
117 if (y > HEIGHT / 3 * 2) {
118 // Upper third - original colors
119 leds[xyMap(x, y)] = original_color;
120 } else if (y > HEIGHT / 3) {
121 // Middle third - colors transformed with colorBoost()
122 EaseType sat_ease = getEaseType(saturationFunction.as_int());
123 EaseType lum_ease = getEaseType(luminanceFunction.as_int());
124 leds[xyMap(x, y)] = original_color.colorBoost(sat_ease, lum_ease);
125 } else {
126 // Lower third - colors transformed using gamma correction
127 float r = original_color.r / 255.f;
128 float g = original_color.g / 255.f;
129 float b = original_color.b / 255.f;
130
131 r = pow(r, 2.0);
132 g = pow(g, 2.0);
133 b = pow(b, 2.0);
134
135 r = r * 255.f;
136 g = g * 255.f;
137 b = b * 255.f;
138
139 leds[xyMap(x, y)] = CRGB(r, g, b);
140 }
141 }
142 }
143}
144
145void loop() {
146 rainbowWave();
147 FastLED.show();
148}
CRGB leds[NUM_LEDS]
#define NUM_LEDS
uint8_t hue
#define DATA_PIN
int y
Definition simple.h:93
int x
Definition simple.h:92
#define BRIGHTNESS
Definition Blur.ino:8
UISlider satSlider("Saturation", 60, 0, 255, 1)
fl::XYMap xyMap
Definition ColorBoost.h:57
EaseType getEaseType(int value)
Definition ColorBoost.h:74
fl::string easeOptions[]
Definition ColorBoost.h:27
void rainbowWave()
Definition ColorBoost.h:95
void setup()
Definition ColorBoost.h:60
UIGroup colorBoostControls("Color Boost", satSlider, saturationFunction, luminanceFunction)
UIDropdown luminanceFunction("Luminance Function", easeOptions)
UIDropdown saturationFunction("Saturation Function", easeOptions)
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.")
UITitle title("ColorBoost")
void loop()
Definition ColorBoost.h:145
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:74
central include file for FastLED, defines the CFastLED class/object
#define COLOR_ORDER
Definition advanced.h:40
#define WIDTH
Definition advanced.h:34
#define LED_TYPE
Definition advanced.h:39
#define HEIGHT
Definition advanced.h:35
#define FL_ASSERT(x, MSG)
Definition assert.h:6
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0)
Definition xymap.cpp:34
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
#define sin8
Platform-independent alias of the fast sin implementation.
Definition trig8.h:230
fl::u32 time()
Universal millisecond timer - returns milliseconds since system startup.
Definition time.cpp:136
EaseType
Definition ease.h:21
@ EASE_OUT_CUBIC
Definition ease.h:27
@ EASE_NONE
Definition ease.h:22
@ EASE_IN_QUAD
Definition ease.h:23
@ EASE_IN_SINE
Definition ease.h:29
@ EASE_OUT_SINE
Definition ease.h:30
@ EASE_IN_CUBIC
Definition ease.h:26
@ EASE_OUT_QUAD
Definition ease.h:24
@ EASE_IN_OUT_CUBIC
Definition ease.h:28
@ EASE_IN_OUT_SINE
Definition ease.h:31
@ EASE_IN_OUT_QUAD
Definition ease.h:25
IMPORTANT!
Definition crgb.h:20
CRGB colorBoost(fl::EaseType saturation_function=fl::EASE_NONE, fl::EaseType luminance_function=fl::EASE_NONE) const
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition hsv.h:15