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