FastLED 3.9.15
Loading...
Searching...
No Matches
FxGfx2Video.ino
Go to the documentation of this file.
1// @filter: (memory is large)
2
15
16#include <FastLED.h>
18#include "fl/fx/fx_engine.h"
19#include "fl/stl/memory.h"
20#include "fl/fx/video.h"
21#include "fl/log/log.h"
22
23#define LED_PIN 2
24#define BRIGHTNESS 96
25#define LED_TYPE WS2811
26#define COLOR_ORDER GRB
27
28#define MATRIX_WIDTH 22
29#define MATRIX_HEIGHT 22
30#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
31
33
34const int BYTES_PER_FRAME = 3 * NUM_LEDS;
35const int NUM_FRAMES = 2;
37
38fl::memorybufPtr memoryStream;
40// Create and initialize Video object
43
44void write_one_frame(fl::memorybufPtr memoryStream) {
45 //memoryStream->seek(0); // Reset to the beginning of the stream
46 uint32_t total_bytes_written = 0;
47 bool toggle = (fl::millis() / 500) % 2 == 0;
48 FL_DBG("Writing frame data, toggle = " << toggle);
49 for (uint32_t i = 0; i < NUM_LEDS; ++i) {
50 fl::CRGB color = (toggle ^ i%2) ? fl::CRGB::Black : fl::CRGB::Red;
51 size_t bytes_written = memoryStream->writeCRGB(&color, 1);
52 if (bytes_written != 1) {
53 FL_DBG("Failed to write frame data, wrote " << bytes_written << " bytes");
54 break;
55 }
56 total_bytes_written += bytes_written;
57 }
58 if (total_bytes_written) {
59 FL_DBG("Frame written, total bytes: " << total_bytes_written);
60 }
61}
62
63void setup() {
64 delay(1000); // sanity delay
66 .setCorrection(TypicalLEDStrip)
67 .setScreenMap(xymap);
68 FastLED.setBrightness(BRIGHTNESS);
69
70 // Create memory-backed file handle for streaming video
72
73 video.begin(memoryStream);
74 // Add the video effect to the FxEngine
75 fxEngine.addFx(video);
76}
77
78void loop() {
80 write_one_frame(memoryStream); // Write next frame data
81 }
82 // write_one_frame(memoryStream); // Write next frame data
83 // Draw the frame
84 fxEngine.draw(fl::millis(), leds);
85 // Show the LEDs
86 FastLED.show();
87 delay(20); // Adjust this delay to control frame rate
88}
#define COLOR_ORDER
#define MATRIX_HEIGHT
fl::FxEngine fxEngine(NUM_LEDS)
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
#define LED_PIN
#define BRIGHTNESS
#define MATRIX_WIDTH
XYMap xymap
bool toggle
Definition Blur.ino:12
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::FxEngine fxEngine(NUM_LEDS)
void setup()
const uint32_t BUFFER_SIZE
fl::Video video(NUM_LEDS, 2.0f)
fl::memorybufPtr memoryStream
fl::XYMap xymap(MATRIX_WIDTH, MATRIX_HEIGHT)
const int BYTES_PER_FRAME
const int NUM_FRAMES
void write_one_frame(fl::memorybufPtr memoryStream)
void loop()
#define LED_TYPE
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:33
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1045
#define FL_DBG
Definition log.h:388
Centralized logging categories for FastLED hardware interfaces and subsystems.
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:622
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38