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
77
78UITitle title("FastLED Wasm Demo");
79UIDescription 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
81UISlider brightness("Brightness", 255, 0, 255);
82UICheckbox isOff("Off", false);
83UISlider speed("Noise - Speed", 15, 1, 50);
84UICheckbox changePallete("Noise - Auto Palette", true);
85UISlider changePalletTime("Noise - Time until next random Palette", 5, 1, 100);
86UISlider scale( "Noise - Scale", 20, 1, 100);
87UIButton changePalette("Noise - Next Palette");
88UIButton changeFx("Switch between Noise & Animartrix");
89UINumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS);
90UISlider timeSpeed("Time Speed", 1, -10, 10, .1);
91
94
95void setup() {
96 Serial.begin(115200);
97 Serial.println("Sketch setup");
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;
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
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
#define COLOR_ORDER
#define LED_PIN
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:58
central include file for FastLED, defines the CFastLED class/object
UIDescription description("This Fire demo wraps around the cylinder. It uses Perlin noise to create a fire effect.")
XYMap xyMap(HEIGHT, WIDTH, SERPENTINE)
UISlider brightness("Brightness", 255, 0, 255, 1)
UISlider timeSpeed("Time Speed", 1, -10, 10,.1)
#define MATRIX_HEIGHT
FxEngine fxEngine(NUM_LEDS)
Animartrix animartrix(xyMap, FIRST_ANIMATION)
UINumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS - 1)
#define MATRIX_WIDTH
UISlider scale("Scale", 4,.1, 4,.1)
uint16_t speed
Definition Noise.ino:63
NoisePalette noisePalette(xyMap)
WS2811 controller class.
Definition FastLED.h:241
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:38
static XYMap constructRectangularGrid(uint16_t width, uint16_t height, uint16_t offset=0)
Definition xymap.cpp:35
@ 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:1364
@ 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:54
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:95
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)
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:110