FastLED 3.9.15
Loading...
Searching...
No Matches
Animartrix.ino
Go to the documentation of this file.
1
14
15/*
16This demo is best viewed using the FastLED compiler.
17
18Windows/MacOS binaries: https://github.com/FastLED/FastLED/releases
19
20Python
21
22Install: pip install fastled
23Run: fastled <this sketch directory>
24This will compile and preview the sketch in the browser, and enable
25all the UI elements you see below.
26
27
28
29OVERVIEW:
30This is the famouse Animartrix demo by Stefan Petrick. The effects are generated
31using polor polar coordinates. The effects are very complex and powerful.
32*/
33
34#define FL_ANIMARTRIX_USES_FAST_MATH 1
35
36/*
37Performence notes @64x64:
38 * ESP32-S3:
39 * FL_ANIMARTRIX_USES_FAST_MATH 0: 143ms
40 * FL_ANIMARTRIX_USES_FAST_MATH 1: 90ms
41*/
42
43#include "FastLED.h"
44
45#if !SKETCH_HAS_LOTS_OF_MEMORY
46// Platform does not have enough memory
47void setup() {}
48void loop() {}
49#else
50
51
52// DRAW TIME: 7ms
53
54
55#include <FastLED.h>
56#include "fl/json.h"
57#include "fl/slice.h"
58#include "fx/fx_engine.h"
59
60#include "fx/2d/animartrix.hpp"
61#include "fl/ui.h"
62
63using namespace fl;
64
65
66#define LED_PIN 3
67#define BRIGHTNESS 32
68#define COLOR_ORDER GRB
69
70#define MATRIX_WIDTH 64
71#define MATRIX_HEIGHT 64
72
73#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
74
75#define FIRST_ANIMATION POLAR_WAVES
76
77// This is purely use for the web compiler to display the animartrix effects.
78// This small led was chosen because otherwise the bloom effect is too strong.
79#define LED_DIAMETER 0.15 // .15 cm or 1.5mm
80
81
82#define POWER_LIMITER_ACTIVE
83#define POWER_VOLTS 5
84#define POWER_MILLIAMPS 2000
85
86
89
90
91UITitle title("Animartrix");
92UIDescription description("Demo of the Animatrix effects. @author of fx is StefanPetrick");
93
94UISlider brightness("Brightness", BRIGHTNESS, 0, 255);
95UINumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS - 1);
96UINumberField colorOrder("Color Order", 0, 0, 5);
97UISlider timeSpeed("Time Speed", 1, -10, 10, .1);
98
99
100
101Animartrix animartrix(xyMap, FIRST_ANIMATION);
103
104const bool kPowerLimiterActive = false;
105
106void setup_max_power() {
107 if (kPowerLimiterActive) {
108 FastLED.setMaxPowerInVoltsAndMilliamps(POWER_VOLTS, POWER_MILLIAMPS); // Set max power to 2 amps
109 }
110}
111
112
113void setup() {
114 Serial.begin(115200);
115 FL_WARN("*** SETUP ***");
116
117 auto screen_map = xyMap.toScreenMap();
118 screen_map.setDiameter(LED_DIAMETER);
120 .setCorrection(TypicalLEDStrip)
121 .setScreenMap(screen_map);
122 FastLED.setBrightness(brightness);
123 setup_max_power();
124 fxEngine.addFx(animartrix);
125
126 colorOrder.onChanged([](int value) {
127 switch(value) {
128 case 0: value = RGB; break;
129 case 1: value = RBG; break;
130 case 2: value = GRB; break;
131 case 3: value = GBR; break;
132 case 4: value = BRG; break;
133 case 5: value = BGR; break;
134 }
135 animartrix.setColorOrder(static_cast<EOrder>(value));
136 });
137}
138
139void loop() {
140 FL_WARN("*** LOOP ***");
141 uint32_t start = millis();
142 FastLED.setBrightness(brightness);
143 fxEngine.setSpeed(timeSpeed);
144 static int lastFxIndex = -1;
145 if (fxIndex.value() != lastFxIndex) {
146 lastFxIndex = fxIndex;
147 animartrix.fxSet(fxIndex);
148 }
149 fxEngine.draw(millis(), leds);
150 uint32_t end = millis();
151 FL_WARN("*** DRAW TIME: " << int(end - start) << "ms");
152 FastLED.show();
153 uint32_t end2 = millis();
154 FL_WARN("*** SHOW + DRAW TIME: " << int(end2 - start) << "ms");
155}
156
157
158#endif // __AVR__
CRGB leds[NUM_LEDS]
#define NUM_LEDS
void setup()
void loop()
#define BRIGHTNESS
Definition Blur.ino:8
fl::XYMap xyMap
Definition ColorBoost.h:61
#define MATRIX_HEIGHT
Definition EaseInOut.h:19
#define MATRIX_WIDTH
Definition EaseInOut.h:18
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:74
central include file for FastLED, defines the CFastLED class/object
#define COLOR_ORDER
Definition advanced.h:42
UITitle title("Audio Reactive Visualizations")
UIDescription description("Real-time audio visualizations with beat detection and multiple modes")
UISlider brightness("Brightness", 128, 0, 255, 1)
#define LED_PIN
Definition advanced.h:40
WS2811 controller class.
Definition FastLED.h:266
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:33
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0)
Definition xymap.cpp:34
fl::unique_ptr< Animartrix > animartrix
Definition curr.h:298
fl::unique_ptr< FxEngine > fxEngine
Definition curr.h:299
@ RBG
Red, Blue, Green (0021)
Definition eorder.h:15
@ BGR
Blue, Green, Red (0210)
Definition eorder.h:19
@ GBR
Green, Blue, Red (0120)
Definition eorder.h:17
fl::EOrder EOrder
Definition eorder.h:9
@ GRB
Green, Red, Blue (0102)
Definition eorder.h:16
@ BRG
Blue, Red, Green (0201)
Definition eorder.h:18
@ RGB
Red, Green, Blue (0012)
Definition eorder.h:14
FastLED's Elegant JSON Library: fl::Json
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
@ NUM_ANIMATIONS
constexpr T * end(T(&array)[N]) noexcept
IMPORTANT!
Definition crgb.h:20
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
#define FL_WARN
Definition warn.h:12
UINumberField fxIndex("Animartrix - index", 0, 0, NUM_ANIMATIONS)
UISlider timeSpeed("Time Speed", 1, -10, 10,.1)