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>
15#include "fx/2d/noisepalette.h"
16#include "fl/json.h"
17#include "fl/slice.h"
18#include "fx/fx_engine.h"
19
20#include "fx/2d/animartrix.hpp"
21#include "fl/ui.h"
22
23using namespace fl;
24
25
26#define LED_PIN 3
27#define BRIGHTNESS 96
28#define COLOR_ORDER GRB
29
30#define MATRIX_WIDTH 100
31#define MATRIX_HEIGHT 100
32#define GRID_SERPENTINE false
33
34#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
35
36// This example combines two features of FastLED to produce a remarkable range
37// of effects from a relatively small amount of code. This example combines
38// FastLED's color palette lookup functions with FastLED's Perlin noise
39// generator, and the combination is extremely powerful.
40//
41// You might want to look at the "ColorPalette" and "Noise" examples separately
42// if this example code seems daunting.
43//
44//
45// The basic setup here is that for each frame, we generate a new array of
46// 'noise' data, and then map it onto the LED matrix through a color palette.
47//
48// Periodically, the color palette is changed, and new noise-generation
49// parameters are chosen at the same time. In this example, specific
50// noise-generation values have been selected to match the given color palettes;
51// some are faster, or slower, or larger, or smaller than others, but there's no
52// reason these parameters can't be freely mixed-and-matched.
53//
54// In addition, this example includes some fast automatic 'data smoothing' at
55// lower noise speeds to help produce smoother animations in those cases.
56//
57// The FastLED built-in color palettes (Forest, Clouds, Lava, Ocean, Party) are
58// used, as well as some 'hand-defined' ones, and some proceedurally generated
59// palettes.
60
61// Scale determines how far apart the pixels in our noise matrix are. Try
62// changing these values around to see how it affects the motion of the display.
63// The higher the value of scale, the more "zoomed out" the noise iwll be. A
64// value of 1 will be so zoomed in, you'll mostly see solid colors.
65#define SCALE 20
66
67// We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
68// use the z-axis for "time". speed determines how fast time moves forward. Try
69// 1 for a very slow moving effect, or 60 for something that ends up looking
70// like water.
71#define SPEED 30
72
73// This is our frame buffer
75
76// We use an XYMap because it will produce the correct ScreenMap for the
77// web display.
80
81UITitle title("FastLED Wasm Demo");
82UIDescription 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");
83
84
85// These UI elements are dynamic when using the FastLED web compiler.
86// When deployed to a real device these elements will always be the default value.
87UISlider brightness("Brightness", 255, 0, 255);
88UICheckbox isOff("Off", false);
89UISlider speed("Noise - Speed", 15, 1, 50);
90UICheckbox changePallete("Noise - Auto Palette", true);
91UISlider changePalletTime("Noise - Time until next random Palette", 5, 1, 100);
92UISlider scale( "Noise - Scale", 20, 1, 100);
93UIButton changePalette("Noise - Next Palette");
94UIButton changeFx("Switch between Noise & Animartrix");
95UINumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS);
96UISlider timeSpeed("Time Speed", 1, -10, 10, .1);
97
98// Group related UI elements using UIGroup template multi-argument constructor
102
103// Animartrix is a visualizer.
105
106// FxEngine allows nice things like switching between visualizers.
108
109void setup() {
110 Serial.begin(115200);
111 Serial.println("Sketch setup");
113 .setCorrection(TypicalLEDStrip)
114 .setScreenMap(xyMap); // This is needed for the web display to work correctly.
115 Serial.println("FastLED setup done");
116 FastLED.setBrightness(brightness);
117 //noisePalette.setSpeed(speed);
118 noisePalette.setScale(scale);
119 fxEngine.addFx(animartrix); // Adding both effects allows us to switch between them.
120 fxEngine.addFx(noisePalette);
121 Serial.println("Sketch setup done");
122}
123
124void loop() {
125 uint32_t now = millis();
126 FastLED.setBrightness(!isOff ? brightness.as<uint8_t>() : 0);
127 noisePalette.setSpeed(speed);
128 noisePalette.setScale(scale);
129 fxEngine.setSpeed(timeSpeed);
130
131 if (changeFx) {
132 fxEngine.nextFx();
133 }
134 // We use the dynamic version here which allows the change time to respond
135 // to changes from the UI element.
137 if (changePallete) {
138 noisePalette.changeToRandomPalette();
139 }
140 }
141
142 if (changePalette) {
143 noisePalette.changeToRandomPalette();
144
145 }
146
147 // Do a change of palette if the button is pressed.
148 static int lastFxIndex = -1;
149 if (fxIndex.value() != lastFxIndex) {
150 lastFxIndex = fxIndex;
151 animartrix.fxSet(fxIndex);
152 }
153
154
155 fxEngine.draw(now, leds);
156 FastLED.show();
157}
CRGB leds[NUM_LEDS]
#define NUM_LEDS
fl::XYMap xyMap
Definition ColorBoost.h:61
#define MATRIX_HEIGHT
Definition EaseInOut.h:19
#define MATRIX_WIDTH
Definition EaseInOut.h:18
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
uint16_t speed
Definition Noise.ino:63
uint16_t scale
Definition Noise.ino:74
#define COLOR_ORDER
Definition advanced.h:42
UISlider brightness("Brightness", 128, 0, 255, 1)
#define LED_PIN
Definition advanced.h:40
WS2811 controller class.
Definition FastLED.h:266
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)
Definition xymap.cpp:34
fl::unique_ptr< Animartrix > animartrix
Definition curr.h:298
fl::unique_ptr< FxEngine > fxEngine
Definition curr.h:299
CRGBPalette16 noisePalette
Definition curr.h:255
FastLED's Elegant JSON Library: fl::Json
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
#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:1226
@ POLAR_WAVES
@ NUM_ANIMATIONS
IMPORTANT!
Definition crgb.h:20
Demonstrates how to mix noise generation with color palettes on a 2D LED matrix.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
UIGroup animartrixControls("Animartrix Controls", fxIndex, changeFx)
UIButton changeFx("Switch between Noise & Animartrix")
UIGroup displayControls("Display Controls", brightness, isOff, timeSpeed)
UINumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS)
UISlider timeSpeed("Time Speed", 1, -10, 10,.1)
void setup()
Definition wasm_impl.h:109
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")
UICheckbox isOff("Off", false)
UISlider changePalletTime("Noise - Time until next random Palette", 5, 1, 100)
UISlider brightness("Brightness", 255, 0, 255)
UITitle title("FastLED Wasm Demo")
UICheckbox changePallete("Noise - Auto Palette", true)
UIButton changePalette("Noise - Next Palette")
UIGroup noiseControls("Noise Controls", speed, changePallete, changePalletTime, scale, changePalette)
void loop()
Definition wasm_impl.h:124