FastLED 3.9.15
Loading...
Searching...
No Matches
EaseInOut.h
Go to the documentation of this file.
1
10
11#include <FastLED.h>
12#include "fl/ease.h"
13#include "fl/leds.h"
14
15using namespace fl;
16
17// Matrix configuration
18#define MATRIX_WIDTH 100
19#define MATRIX_HEIGHT 100
20#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
21#define DATA_PIN 3
22#define LED_TYPE WS2812B
23#define COLOR_ORDER GRB
24#define BRIGHTNESS 255
25
26
27#define MATRIX_SERPENTINE true
28
29// Use LedsXY for splat rendering instead of regular CRGB array
31
32// Create XYMap for serpentine 100x100 matrix
34
35UITitle title("EaseInOut");
36UIDescription description("Use the xPosition slider to see the ease function curve. Use the Ease Type dropdown to select different easing functions. Use the 16-bit checkbox to toggle between 16-bit (checked) and 8-bit (unchecked) precision.");
37
38// UI Controls
39UISlider xPosition("xPosition", 0.0f, 0.0f, 1.0f, 0.01f);
40
41// Create dropdown with descriptive ease function names
43 "None",
44 "In Quad",
45 "Out Quad",
46 "In-Out Quad",
47 "In Cubic",
48 "Out Cubic",
49 "In-Out Cubic",
50 "In Sine",
51 "Out Sine",
52 "In-Out Sine"
53};
55
56UICheckbox use16Bit("16-bit", true); // Default checked for 16-bit precision
57
59 switch (value) {
60 case 0: return EASE_NONE;
61 case 1: return EASE_IN_QUAD;
62 case 2: return EASE_OUT_QUAD;
63 case 3: return EASE_IN_OUT_QUAD;
64 case 4: return EASE_IN_CUBIC;
65 case 5: return EASE_OUT_CUBIC;
66 case 6: return EASE_IN_OUT_CUBIC;
67 case 7: return EASE_IN_SINE;
68 case 8: return EASE_OUT_SINE;
69 case 9: return EASE_IN_OUT_SINE;
70 }
71 FL_ASSERT(false, "Invalid ease type");
72 return EASE_IN_OUT_QUAD;
73}
74
75void setup() {
76 Serial.begin(115200);
77 Serial.println("FastLED Ease16InOutQuad Demo - Simple Curve Visualization");
78
79 // Add LEDs and set screen map
80 auto *controller =
82
83 // Convert XYMap to ScreenMap and set it on the controller
84 fl::ScreenMap screenMap = xyMap.toScreenMap();
85 screenMap.setDiameter(.5); // Set LED diameter for visualization
86 controller->setScreenMap(screenMap);
87
88 // Configure FastLED
89 FastLED.setBrightness(BRIGHTNESS);
90 FastLED.setCorrection(TypicalLEDStrip);
91 FastLED.setDither(BRIGHTNESS < 255);
92
93 // Set default dropdown selection to "In-Out Quad" (index 3)
94 easeTypeDropdown.setSelectedIndex(3);
95}
96
97void loop() {
98 // Clear the matrix using fl::clear for LedsXY
100
101 // Get the current slider value (0.0 to 1.0)
102 float sliderValue = xPosition.value();
103
104 // Map slider value to X coordinate (0 to width-1)
105 uint8_t x = map(sliderValue * 1000, 0, 1000, 0, MATRIX_WIDTH - 1);
106
107 // Get the selected ease type using the dropdown index
108 EaseType selectedEaseType = getEaseType(easeTypeDropdown.as_int());
109
110 uint8_t y;
111 if (use16Bit.value()) {
112 // Use 16-bit precision
113 uint16_t easeInput = map(sliderValue * 1000, 0, 1000, 0, 65535);
114 uint16_t easeOutput = ease16(selectedEaseType, easeInput);
115 y = map(easeOutput, 0, 65535, 0, MATRIX_HEIGHT - 1);
116 } else {
117 // Use 8-bit precision
118 uint8_t easeInput = map(sliderValue * 1000, 0, 1000, 0, 255);
119 uint8_t easeOutput = ease8(selectedEaseType, easeInput);
120 y = map(easeOutput, 0, 255, 0, MATRIX_HEIGHT - 1);
121 }
122
123 // Draw white dot at the calculated position using splat rendering
124 if (x < MATRIX_WIDTH && y < MATRIX_HEIGHT) {
125 leds(x, y) = CRGB::White;
126 }
127
128 FastLED.show();
129}
CRGB leds[NUM_LEDS]
#define NUM_LEDS
#define DATA_PIN
int y
Definition simple.h:93
int x
Definition simple.h:92
#define BRIGHTNESS
Definition Blur.ino:8
fl::XYMap xyMap
Definition ColorBoost.h:61
fl::string easeOptions[]
Definition ColorBoost.h:23
#define MATRIX_HEIGHT
Definition EaseInOut.h:19
EaseType getEaseType(int value)
Definition EaseInOut.h:58
void setup()
Definition EaseInOut.h:75
LedsXY< MATRIX_WIDTH, MATRIX_HEIGHT > leds
Definition EaseInOut.h:30
UITitle title("EaseInOut")
UIDropdown easeTypeDropdown("Ease Type", easeOptions)
UIDescription description("Use the xPosition slider to see the ease function curve. Use the Ease Type dropdown to select different easing functions. Use the 16-bit checkbox to toggle between 16-bit (checked) and 8-bit (unchecked) precision.")
UICheckbox use16Bit("16-bit", true)
UISlider xPosition("xPosition", 0.0f, 0.0f, 1.0f, 0.01f)
#define MATRIX_WIDTH
Definition EaseInOut.h:18
void loop()
Definition EaseInOut.h:97
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
CLEDController * controller
#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 constructSerpentine(u16 width, u16 height, u16 offset=0)
Definition xymap.cpp:52
fl::ScreenMap screenMap
Definition Corkscrew.h:103
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
void clear(CRGB(&arr)[N])
Definition clear.h:13
u16 ease16(EaseType type, u16 i)
Definition ease.h:126
u8 ease8(EaseType type, u8 i)
Definition ease.h:202
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
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:703