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