FastLED 3.9.15
Loading...
Searching...
No Matches
ColorBoost.h
Go to the documentation of this file.
1
11
12#include "FastLED.h"
13#include "fl/ease.h"
14
15using namespace fl;
16
17UITitle title("ColorBoost");
18UIDescription description("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.");
19
20UISlider satSlider("Saturation", 60, 0, 255, 1);
21
22// Create dropdown with descriptive ease function names
24 "None",
25 "In Quad",
26 "Out Quad",
27 "In-Out Quad",
28 "In Cubic",
29 "Out Cubic",
30 "In-Out Cubic",
31 "In Sine",
32 "Out Sine",
33 "In-Out Sine"
34};
37
38// Group related color boost UI elements using UIGroup template multi-argument constructor
40
41// Rgb8Video
42// Animated, ever-changing rainbows optimized for video display.
43// Uses CRGB::toVideoRGB_8bit() to boost saturation for better LED display.
44// Based on Pride2015 by Mark Kriegsman
45
46#define DATA_PIN 3
47#define DATA_PIN_2 4 // Second strip for original RGB comparison
48// #define CLK_PIN 4
49#define LED_TYPE WS2811
50#define COLOR_ORDER GRB
51#define NUM_LEDS_PER_STRIP 16
52#define NUM_STRIPS 16 // Changed from 2 to 100 for 100x100 matrix
53#define TOTAL_LEDS (NUM_LEDS_PER_STRIP * NUM_STRIPS) // 100x100 = 10,000 LEDs
54#define BRIGHTNESS 255
55
56// Combined LED array for both strips
58
59// fl::ScreenMap screenmap(lut.data(), lut.size());
60// fl::ScreenMap screenmap(TOTAL_LEDS);
63
64void setup() {
65
66 // tell FastLED about the LED strip configuration
67 // First strip (original RGB) - indices 0-199
68
70 .setCorrection(TypicalLEDStrip)
71 .setScreenMap(xyMap);
72 // set master brightness control
73 FastLED.setBrightness(BRIGHTNESS);
74
75 // Set default dropdown selections
76 saturationFunction.setSelectedIndex(1); // "In Quad"
77 luminanceFunction.setSelectedIndex(0); // "None"
78}
79
81 switch (value) {
82 case 0: return EASE_NONE;
83 case 1: return EASE_IN_QUAD;
84 case 2: return EASE_OUT_QUAD;
85 case 3: return EASE_IN_OUT_QUAD;
86 case 4: return EASE_IN_CUBIC;
87 case 5: return EASE_OUT_CUBIC;
88 case 6: return EASE_IN_OUT_CUBIC;
89 case 7: return EASE_IN_SINE;
90 case 8: return EASE_OUT_SINE;
91 case 9: return EASE_IN_OUT_SINE;
92 }
93 FL_ASSERT(false, "Invalid ease type");
94 return EASE_NONE;
95}
96
97// Animated rainbow wave effect optimized for video display
99 // Use millis() for consistent timing across different devices
100 // Scale down millis() to get appropriate animation speed
101 uint16_t time = millis() / 16; // Adjust divisor to control wave speed
102 uint8_t hueOffset = millis() / 32; // Adjust divisor to control hue rotation speed
103
104 // Iterate through the entire 100x100 matrix
105 for (uint16_t y = 0; y < NUM_STRIPS; y++) {
106 for (uint16_t x = 0; x < NUM_LEDS_PER_STRIP; x++) {
107 // Create a wave pattern using sine function based on position and
108 // time
109 uint8_t wave = sin8(time + (x * 8));
110
111 // Calculate hue based on position and time for rainbow effect
112 uint8_t hue = hueOffset + (x * 255 / NUM_LEDS_PER_STRIP);
113
114 // Use wave for both saturation and brightness variation
115 // uint8_t sat = 255 - (wave / 4); // Subtle saturation variation
116 uint8_t bri = 128 + (wave / 2); // Brightness wave from 128 to 255
117
118 // Create the original color using HSV
119 CRGB original_color = CHSV(hue, satSlider.value(), bri);
120
121 // Upper half (rows 0-49): original colors
122 // Lower half (rows 50-99): transformed colors using
123 // toVideoRGB_8bit()
124 if (y > NUM_STRIPS / 3 * 2) {
125 // Upper half - original colors
126 leds[xyMap(x, y)] = original_color;
127 } else if (y > NUM_STRIPS / 3) {
128 // Middle half - transformed colors
129 EaseType sat_ease = getEaseType(saturationFunction.as_int());
130 EaseType lum_ease = getEaseType(luminanceFunction.as_int());
131 leds[xyMap(x, y)] = original_color.colorBoost(sat_ease, lum_ease);
132 } else {
133 // Lower half - transformed colors
134 float r = original_color.r / 255.f;
135 float g = original_color.g / 255.f;
136 float b = original_color.b / 255.f;
137
138 r = pow(r, 2.0);
139 g = pow(g, 2.0);
140 b = pow(b, 2.0);
141
142 r = r * 255.f;
143 g = g * 255.f;
144 b = b * 255.f;
145
146 leds[xyMap(x, y)] = CRGB(r, g, b);
147 }
148 }
149 }
150}
151
152void loop() {
153 rainbowWave();
154 FastLED.show();
155}
CRGB leds[NUM_LEDS]
uint8_t hue
int y
Definition simple.h:93
int x
Definition simple.h:92
#define BRIGHTNESS
Definition Blur.ino:8
#define TOTAL_LEDS
Definition ColorBoost.h:53
UISlider satSlider("Saturation", 60, 0, 255, 1)
#define NUM_LEDS_PER_STRIP
Definition ColorBoost.h:51
#define NUM_STRIPS
Definition ColorBoost.h:52
fl::XYMap xyMap
Definition ColorBoost.h:61
EaseType getEaseType(int value)
Definition ColorBoost.h:80
#define DATA_PIN_2
Definition ColorBoost.h:47
fl::string easeOptions[]
Definition ColorBoost.h:23
void rainbowWave()
Definition ColorBoost.h:98
void setup()
Definition ColorBoost.h:64
UIGroup colorBoostControls("Color Boost", satSlider, saturationFunction, luminanceFunction)
UIDescription description("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.")
UIDropdown luminanceFunction("Luminance Function", easeOptions)
UIDropdown saturationFunction("Saturation Function", easeOptions)
UITitle title("ColorBoost")
void loop()
Definition ColorBoost.h:152
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:42
#define LED_TYPE
Definition advanced.h:41
#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