FastLED 3.9.3
Loading...
Searching...
No Matches
NoisePlusPalette.ino
Go to the documentation of this file.
1
5
6#ifndef COMPILE_NOISEPLUSPALETTE
7#if defined(__AVR__)
8// This has grown too large for the AVR to handle.
9#define COMPILE_NOISEPLUSPALETTE 0
10#else
11#define COMPILE_NOISEPLUSPALETTE 1
12#endif
13#endif // COMPILE_NOISEPLUSPALETTE
14
15#if COMPILE_NOISEPLUSPALETTE
16
17#include <FastLED.h>
18#include "fx/2d/noisepalette.hpp"
19#include "ui.h"
20
21#define LED_PIN 3
22#define BRIGHTNESS 96
23#define LED_TYPE WS2811
24#define COLOR_ORDER GRB
25
26#define MATRIX_WIDTH 16
27#define MATRIX_HEIGHT 16
28
29#if __EMSCRIPTEN__
30#define GRID_SERPENTINE 0
31#else
32#define GRID_SERPENTINE 1
33#endif
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
67Slider SCALE("SCALE", 20, 1, 100, 1);
68
69// We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
70// use the z-axis for "time". speed determines how fast time moves forward. Try
71// 1 for a very slow moving effect, or 60 for something that ends up looking
72// like water.
73Slider SPEED("SPEED", 30, 1, 60, 1);
74
75CRGB leds[NUM_LEDS];
76XYMap xyMap(MATRIX_WIDTH, MATRIX_HEIGHT, GRID_SERPENTINE);
77NoisePaletteRef noisePalette = NoisePaletteRef::New(xyMap);
78
79void setup() {
80 delay(1000); // sanity delay
81 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
82 .setCorrection(TypicalLEDStrip);
84 noisePalette->lazyInit();
85 noisePalette->setSpeed(SPEED);
86 noisePalette->setScale(SCALE);
87}
88
89void loop() {
90 noisePalette->setSpeed(SPEED);
91 noisePalette->setScale(SCALE);
92 EVERY_N_MILLISECONDS(5000) { noisePalette->changeToRandomPalette(); }
93
94 noisePalette->draw(Fx::DrawContext(millis(), leds));
95 FastLED.show();
96}
97
98#else
99void setup() {}
100void loop() {}
101#endif // COMPILE_NOISEPLUSPALETTE
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:33
central include file for FastLED, defines the CFastLED class/object
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
void draw(DrawContext context) override
Definition ui.h:40
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
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39