FastLED 3.9.7
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
74CRGB leds[NUM_LEDS];
75XYMap xyMap = XYMap::constructRectangularGrid(MATRIX_WIDTH, MATRIX_HEIGHT);
76NoisePalette noisePalette = NoisePalette(xyMap);
77
78Title title("FastLED Wasm Demo");
79Description 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");
80
81Slider brightness("Brightness", 255, 0, 255);
82Checkbox isOff("Off", false);
83Slider speed("Noise - Speed", 15, 1, 50);
84Checkbox changePallete("Noise - Auto Palette", true);
85Slider changePalletTime("Noise - Time until next random Palette", 5, 1, 100);
86Slider scale( "Noise - Scale", 20, 1, 100);
87Button changePalette("Noise - Next Palette");
88Button changeFx("Switch between Noise & Animartrix");
89NumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS);
90Slider timeSpeed("Time Speed", 1, -10, 10, .1);
91
92Animartrix animartrix(xyMap, POLAR_WAVES);
93FxEngine fxEngine(NUM_LEDS);
94
95void setup() {
96 Serial.begin(115200);
97 Serial.println("Sketch setup");
98 FastLED.addLeds<WS2811, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
99 .setCorrection(TypicalLEDStrip)
100 .setScreenMap(xyMap);
101 Serial.println("FastLED setup done");
102 FastLED.setBrightness(brightness);
103 //noisePalette.setSpeed(speed);
104 noisePalette.setScale(scale);
105 fxEngine.addFx(animartrix);
106 fxEngine.addFx(noisePalette);
107 Serial.println("Sketch setup done");
108}
109
110void loop() {
111 FastLED.setBrightness(!isOff ? brightness.as<uint8_t>() : 0);
112 noisePalette.setSpeed(speed);
113 noisePalette.setScale(scale);
114 fxEngine.setSpeed(timeSpeed);
115
116 if (changeFx) {
117 fxEngine.nextFx();
118 }
119 static int frame = 0;
120 EVERY_N_MILLISECONDS_DYNAMIC(changePalletTime.as<int>() * 1000) {
121 if (changePallete) {
122 noisePalette.changeToRandomPalette();
123 }
124 }
125
126 if (changePalette) {
127 noisePalette.changeToRandomPalette();
128
129 }
130 static int lastFxIndex = -1;
131 if (fxIndex.value() != lastFxIndex) {
132 lastFxIndex = fxIndex;
133 animartrix.fxSet(fxIndex);
134 }
135
136
137 fxEngine.draw(millis(), leds);
138 FastLED.show();
139 frame++;
140}
141
142
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:45
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:723
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:94
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:79
WS2811 controller class.
Definition FastLED.h:234
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:38
int addFx(FxPtr effect)
Adds a new effect to the engine.
Definition fx_engine.cpp:16
void setSpeed(float scale)
Sets the speed of the fx engine, which will impact the speed of all effects.
Definition fx_engine.h:116
bool nextFx(uint16_t transition_ms=500)
Transitions to the next effect in the sequence.
Definition fx_engine.cpp:35
bool draw(uint32_t now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
Definition fx_engine.cpp:84
@ 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:1323
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:54