FastLED 3.9.15
Loading...
Searching...
No Matches
wasm_impl.h
Go to the documentation of this file.
1
10
11
12
13
14#include <FastLED.h>
16#include "fl/stl/json.h"
17#include "fl/stl/span.h"
18#include "fl/fx/fx_engine.h"
19
21#include "fl/ui/ui.h"
22
23
24
25#define LED_PIN 3
26#define BRIGHTNESS 96
27#define COLOR_ORDER GRB
28
29#define MATRIX_WIDTH 32
30#define MATRIX_HEIGHT 32
31#define GRID_SERPENTINE false
32
33#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
34
35// This example combines two features of FastLED to produce a remarkable range
36// of effects from a relatively small amount of code. This example combines
37// FastLED's color palette lookup functions with FastLED's Perlin noise
38// generator, and the combination is extremely powerful.
39//
40// You might want to look at the "ColorPalette" and "Noise" examples separately
41// if this example code seems daunting.
42//
43//
44// The basic setup here is that for each frame, we generate a new fl::array of
45// 'noise' data, and then map it onto the LED matrix through a color palette.
46//
47// Periodically, the color palette is changed, and new noise-generation
48// parameters are chosen at the same time. In this example, specific
49// noise-generation values have been selected to match the given color palettes;
50// some are faster, or slower, or larger, or smaller than others, but there's no
51// reason these parameters can't be freely mixed-and-matched.
52//
53// In addition, this example includes some fast automatic 'data smoothing' at
54// lower noise speeds to help produce smoother animations in those cases.
55//
56// The FastLED built-in color palettes (Forest, Clouds, Lava, Ocean, Party) are
57// used, as well as some 'hand-defined' ones, and some proceedurally generated
58// palettes.
59
60// Scale determines how far apart the pixels in our noise matrix are. Try
61// changing these values around to see how it affects the motion of the display.
62// The higher the value of scale, the more "zoomed out" the noise iwll be. A
63// value of 1 will be so zoomed in, you'll mostly see solid colors.
64#define SCALE 20
65
66// We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
67// use the z-axis for "time". speed determines how fast time moves forward. Try
68// 1 for a very slow moving effect, or 60 for something that ends up looking
69// like water.
70#define SPEED 30
71
72// This is our frame buffer
74
75// We use an fl::XYMap because it will produce the correct fl::ScreenMap for the
76// web display.
79
80fl::UITitle title("FastLED Wasm Demo");
81fl::UIDescription description("This example combines two features of FastLED to produce a remarkable range of effects from a relatively small amount of code. This example combines FastLED's color palette lookup functions with FastLED's Perlin noise generator, and the combination is extremely powerful");
82
83
84// These UI elements are dynamic when using the FastLED web compiler.
85// When deployed to a real device these elements will always be the default value.
86fl::UISlider brightness("Brightness", 255, 0, 255);
87fl::UICheckbox isOff("Off", false);
88fl::UISlider speed("Noise - Speed", 15, 1, 50);
89fl::UICheckbox changePallete("Noise - Auto Palette", true);
90fl::UISlider changePalletTime("Noise - Time until next random Palette", 5, 1, 100);
91fl::UISlider scale( "Noise - Scale", 20, 1, 100);
92fl::UIButton changePalette("Noise - Next Palette");
93fl::UIButton changeFx("Switch between Noise & fl::Animartrix");
94UINumberField fxIndex("fl::Animartrix - index", 0, 0, static_cast<int>(fl::AnimartrixAnim::NUM_ANIMATIONS));
95fl::UISlider timeSpeed("Time Speed", 1, -10, 10, .1);
96
97// Group related UI elements using fl::UIGroup template multi-argument constructor
99fl::UIGroup animartrixControls("fl::Animartrix Controls", fxIndex, changeFx);
101
102// fl::Animartrix is a visualizer.
104
105// fl::FxEngine allows nice things like switching between visualizers.
107
108void setup() {
109 Serial.begin(115200);
110 Serial.println("Sketch setup");
111 FastLED.addLeds<WS2811, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
112 .setCorrection(TypicalLEDStrip)
113 .setScreenMap(xyMap); // This is needed for the web display to work correctly.
114 Serial.println("FastLED setup done");
115 FastLED.setBrightness(brightness);
116 //noisePalette.setSpeed(speed);
117 noisePalette.setScale(scale);
118 fxEngine.addFx(animartrix); // Adding both effects allows us to switch between them.
119 fxEngine.addFx(noisePalette);
120 Serial.println("Sketch setup done");
121}
122
123void loop() {
124 uint32_t now = fl::millis();
125 FastLED.setBrightness(!isOff ? brightness.as<uint8_t>() : 0);
126 noisePalette.setSpeed(speed);
127 noisePalette.setScale(scale);
128 fxEngine.setSpeed(timeSpeed);
129
130 if (changeFx) {
131 fxEngine.nextFx();
132 }
133 // We use the dynamic version here which allows the change time to respond
134 // to changes from the UI element.
136 if (changePallete) {
137 noisePalette.changeToRandomPalette();
138 }
139 }
140
141 if (changePalette) {
142 noisePalette.changeToRandomPalette();
143
144 }
145
146 // Do a change of palette if the button is pressed.
147 static int lastFxIndex = -1;
148 if (fxIndex.value() != lastFxIndex) {
149 lastFxIndex = fxIndex;
150 animartrix.fxSet(fxIndex);
151 }
152
153
154 fxEngine.draw(now, leds);
155 FastLED.show();
156}
#define COLOR_ORDER
#define MATRIX_HEIGHT
fl::XYMap xyMap
fl::FxEngine fxEngine(NUM_LEDS)
#define NUM_LEDS
fl::UIDescription description("Demo of the Animatrix effects. @author of fx is StefanPetrick")
fl::Animartrix animartrix(xyMap, FIRST_ANIMATION)
fl::UITitle title("Animartrix")
fl::CRGB leds[NUM_LEDS]
fl::UIDropdown fxIndex("Animartrix - index", { "RGB_BLOBS5", "RGB_BLOBS4", "RGB_BLOBS3", "RGB_BLOBS2", "RGB_BLOBS", "POLAR_WAVES", "SLOW_FADE", "ZOOM2", "ZOOM", "HOT_BLOB", "SPIRALUS2", "SPIRALUS", "YVES", "SCALEDEMO1", "LAVA1", "CALEIDO3", "CALEIDO2", "CALEIDO1", "DISTANCE_EXPERIMENT", "CENTER_FIELD", "WAVES", "CHASING_SPIRALS", "ROTATING_BLOB", "RINGS", "COMPLEX_KALEIDO", "COMPLEX_KALEIDO_2", "COMPLEX_KALEIDO_3", "COMPLEX_KALEIDO_4", "COMPLEX_KALEIDO_5", "COMPLEX_KALEIDO_6", "WATER", "PARAMETRIC_WATER", "MODULE_EXPERIMENT1", "MODULE_EXPERIMENT2", "MODULE_EXPERIMENT3", "MODULE_EXPERIMENT4", "MODULE_EXPERIMENT5", "MODULE_EXPERIMENT6", "MODULE_EXPERIMENT7", "MODULE_EXPERIMENT8", "MODULE_EXPERIMENT9", "MODULE_EXPERIMENT10", "MODULE_EXPERIMENT_SM1", "MODULE_EXPERIMENT_SM2", "MODULE_EXPERIMENT_SM3", "MODULE_EXPERIMENT_SM4", "MODULE_EXPERIMENT_SM5", "MODULE_EXPERIMENT_SM6", "MODULE_EXPERIMENT_SM8", "MODULE_EXPERIMENT_SM9", "MODULE_EXPERIMENT_SM10", "FLUFFY_BLOBS" })
fl::UISlider timeSpeed("Time Speed", 1, -10, 10,.1)
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
#define LED_PIN
#define MATRIX_WIDTH
fl::UIGroup displayControls("Display", sliderDecay, allWhite)
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::UISlider scale("Scale", 4,.1, 4,.1)
uint16_t speed
Definition Noise.ino:66
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:33
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0) FL_NOEXCEPT
Definition xymap.cpp.hpp:35
fl::CRGBPalette16 noisePalette
Definition curr.h:243
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
#define EVERY_N_MILLISECONDS_DYNAMIC(PERIOD_FUNC)
Checks whether to execute a block of code every N milliseconds, where N is determined dynamically.
Definition lib8tion.h:1050
FastLED's Elegant JSON Library: fl::json
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
Demonstrates how to mix noise generation with color palettes on a 2D LED matrix.
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
#define Serial
Definition serial.h:304
Aggregator header for the fl/ui/ family of per-element UI types.
fl::UICheckbox changePallete("Noise - Auto Palette", true)
fl::UIButton changeFx("Switch between Noise & fl::Animartrix")
fl::UIButton changePalette("Noise - Next Palette")
void setup()
Definition wasm_impl.h:108
fl::UIGroup animartrixControls("fl::Animartrix Controls", fxIndex, changeFx)
fl::UISlider changePalletTime("Noise - Time until next random Palette", 5, 1, 100)
fl::UIGroup noiseControls("Noise Controls", speed, changePallete, changePalletTime, scale, changePalette)
fl::UICheckbox isOff("Off", false)
void loop()
Definition wasm_impl.h:123