FastLED 3.9.3
Loading...
Searching...
No Matches
wasm.ino
1
5
6// printf
7#include <stdio.h>
8#include <string>
9
10#include <FastLED.h>
11#include "fx/2d/noisepalette.hpp"
12#include "json.h"
13#include "slice.h"
14#include "fx/fx_engine.h"
15
16#include "fx/2d/animartrix.hpp"
17#include "ui.h"
18
19
20#define LED_PIN 3
21#define BRIGHTNESS 96
22#define COLOR_ORDER GRB
23
24#define MATRIX_WIDTH 100
25#define MATRIX_HEIGHT 100
26#define GRID_SERPENTINE false
27
28#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
29
30// This example combines two features of FastLED to produce a remarkable range
31// of effects from a relatively small amount of code. This example combines
32// FastLED's color palette lookup functions with FastLED's Perlin noise
33// generator, and the combination is extremely powerful.
34//
35// You might want to look at the "ColorPalette" and "Noise" examples separately
36// if this example code seems daunting.
37//
38//
39// The basic setup here is that for each frame, we generate a new array of
40// 'noise' data, and then map it onto the LED matrix through a color palette.
41//
42// Periodically, the color palette is changed, and new noise-generation
43// parameters are chosen at the same time. In this example, specific
44// noise-generation values have been selected to match the given color palettes;
45// some are faster, or slower, or larger, or smaller than others, but there's no
46// reason these parameters can't be freely mixed-and-matched.
47//
48// In addition, this example includes some fast automatic 'data smoothing' at
49// lower noise speeds to help produce smoother animations in those cases.
50//
51// The FastLED built-in color palettes (Forest, Clouds, Lava, Ocean, Party) are
52// used, as well as some 'hand-defined' ones, and some proceedurally generated
53// palettes.
54
55// Scale determines how far apart the pixels in our noise matrix are. Try
56// changing these values around to see how it affects the motion of the display.
57// The higher the value of scale, the more "zoomed out" the noise iwll be. A
58// value of 1 will be so zoomed in, you'll mostly see solid colors.
59#define SCALE 20
60
61// We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
62// use the z-axis for "time". speed determines how fast time moves forward. Try
63// 1 for a very slow moving effect, or 60 for something that ends up looking
64// like water.
65#define SPEED 30
66
67CRGB leds[NUM_LEDS];
68XYMap xyMap = XYMap::constructRectangularGrid(MATRIX_WIDTH, MATRIX_HEIGHT);
69NoisePalette noisePalette = NoisePalette(xyMap);
70
71Title title("FastLED Wasm Demo");
72Description 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.");
73
74Slider brightness("Brightness", 255, 0, 255);
75Checkbox isOff("Off", false);
76Slider speed("Noise - Speed", 15, 1, 50);
77Checkbox changePallete("Noise - Auto Palette", true);
78Slider changePalletTime("Noise - Time until next random Palette", 5, 1, 100);
79Slider scale( "Noise - Scale", 20, 1, 100);
80Button changePalette("Noise - Next Palette");
81Button changeFx("Switch between Noise & Animartrix");
82NumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS);
83
84Animartrix animartrix(xyMap, POLAR_WAVES);
85FxEngine fxEngine(NUM_LEDS);
86
87void setup() {
88 FastLED.addLeds<WS2811, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
89 .setCorrection(TypicalLEDStrip)
90 .setScreenMap(xyMap);
91 FastLED.setBrightness(brightness);
92 //noisePalette.setSpeed(speed);
93 noisePalette.setScale(scale);
94 fxEngine.addFx(animartrix);
95 fxEngine.addFx(noisePalette);
96}
97
98void loop() {
99 FastLED.setBrightness(!isOff ? brightness.as<uint8_t>() : 0);
100 noisePalette.setSpeed(speed);
101 noisePalette.setScale(scale);
102
103 if (changeFx) {
104 fxEngine.nextFx();
105 }
106 static int frame = 0;
107 EVERY_N_MILLISECONDS_DYNAMIC(changePalletTime.as<int>() * 1000) {
108 if (changePallete) {
109 noisePalette.changeToRandomPalette();
110 }
111 }
112
113 if (changePalette) {
114 noisePalette.changeToRandomPalette();
115
116 }
117 static int lastFxIndex = -1;
118 if (fxIndex.value() != lastFxIndex) {
119 lastFxIndex = fxIndex;
120 animartrix.fxSet(fxIndex);
121 }
122
124 printf("fastled running\r\n");
125 printf("Numberfield: %f\r\n", fxIndex.value());
126 }
127
128
129 fxEngine.draw(millis(), leds);
130 FastLED.show();
131 frame++;
132}
133
134
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:33
central include file for FastLED, defines the CFastLED class/object
Definition ui.h:70
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:722
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:82
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:67
Definition ui.h:83
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:37
int addFx(FxRef effect)
Adds a new effect to the engine.
Definition fx_engine.h:145
bool nextFx(uint16_t transition_ms=500)
Transitions to the next effect in the sequence.
Definition fx_engine.h:164
bool draw(uint32_t now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
Definition fx_engine.h:213
Definition ui.h:40
Definition ui.h:122
WS2811 controller class.
Definition FastLED.h:233
Definition xymap.h:39
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1323
#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:1328
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39