FastLED 3.9.15
Loading...
Searching...
No Matches
Wave.ino
Go to the documentation of this file.
1
2/*
3
4This is a 1D wave simluation!
5
6This demo is best viewed using the FastLED compiler.
7
8Windows/MacOS binaries: https://github.com/FastLED/FastLED/releases
9
10Python
11
12Install: pip install fastled
13Run: fastled <this sketch directory>
14This will compile and preview the sketch in the browser, and enable
15all the UI elements you see below.
16*/
17
18#include "fl/math_macros.h"
19#include "fl/ui.h"
20#include "fl/wave_simulation.h"
21#include <Arduino.h>
22#include <FastLED.h>
23
24using namespace fl;
25
26#define NUM_LEDS 100
27#define IS_SERPINTINE true // Type of matrix display, you probably have this.
28
30
31UITitle title("Wave Demo");
32UIDescription description("Shows the use of the Wave1D effect.");
33
34UIButton button("Trigger");
36
37UISlider slider("Speed", 0.18f, 0.0f, 1.0f);
38UISlider extraFrames("Extra Frames", 1.0f, 0.0f, 8.0f, 1.0f);
39UISlider dampening("Dampening", 6.0f, 0.0f, 10.0f, 0.1f);
40UICheckbox halfDuplex("Half Duplex", false);
41UISlider superSample("SuperSampleExponent", 0.f, 0.f, 3.f, 1.f);
42
43void setup() {
44 Serial.begin(115200);
45 // No ScreenMap necessary for strips.
46 FastLED.addLeds<NEOPIXEL, 2>(leds, NUM_LEDS);
47}
48
50
51 for (int i = x - 1; i <= x + 1; i++) {
52 if (i < 0 || i >= NUM_LEDS)
53 continue;
54 waveSim.setf(i, -1.f);
55 }
56}
57
58// Wave simulation looks better when you render at a higher resolution then
59// downscale the result to the display resolution.
61 switch (int(superSample)) {
62 case 0:
64 case 1:
66 case 2:
68 case 3:
70 default:
72 }
73}
74
75void loop() {
76 // Allow the waveSimulator to respond to the current slider value each frame.
77 waveSim.setSpeed(slider);
78 waveSim.setDampening(dampening);
79 // Pretty much you always want half duplex to be true, otherwise you get a gray
80 // wave effect that doesn't look good.
81 waveSim.setHalfDuplex(halfDuplex);
82 waveSim.setSuperSample(getSuperSample());
83 static int x = 0;
84 if (button.clicked()) {
85 // If button click then select a random position in the wave.
86 x = random() % NUM_LEDS;
87 }
88 if (button.isPressed()) {
89 FASTLED_WARN("Button is pressed at " << x);
91 }
92 waveSim.update();
93 for (int i = 0; i < extraFrames.value(); i++) {
94 waveSim.update();
95 }
96 for (int x = 0; x < NUM_LEDS; x++) {
97 // float value = waveSim.get(x);
98 uint8_t value8 = waveSim.getu8(x);
99 leds[x] = CRGB(value8, value8, value8);
100 }
101 FastLED.show();
102}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
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
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:82
UISlider slider("Speed", 0.18f, 0.0f, 1.0f)
UISlider dampening("Dampening", 6.0f, 0.0f, 10.0f, 0.1f)
UICheckbox halfDuplex("Half Duplex", false)
UITitle title("Wave Demo")
void setup()
Definition Wave.ino:43
UIButton button("Trigger")
UISlider superSample("SuperSampleExponent", 0.f, 0.f, 3.f, 1.f)
UIDescription description("Shows the use of the Wave1D effect.")
SuperSample getSuperSample()
Definition Wave.ino:60
WaveSimulation1D waveSim(NUM_LEDS, SuperSample::SUPER_SAMPLE_2X)
UISlider extraFrames("Extra Frames", 1.0f, 0.0f, 8.0f, 1.0f)
void loop()
Definition Wave.ino:75
LED controller for WS2812 LEDs with GRB color order.
Definition FastLED.h:155
SuperSample
Definition supersample.h:4
@ SUPER_SAMPLE_8X
Definition supersample.h:8
@ SUPER_SAMPLE_2X
Definition supersample.h:6
@ SUPER_SAMPLE_4X
Definition supersample.h:7
@ SUPER_SAMPLE_NONE
Definition supersample.h:5
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55
#define FASTLED_WARN
Definition warn.h:7
UIButton button("Trigger")
void triggerRipple()
Definition wavefx.cpp:147
UISlider superSample("SuperSampleExponent", 1.f, 0.f, 3.f, 1.f)