FastLED 3.9.15
Loading...
Searching...
No Matches
FxGfx2Video.ino
Go to the documentation of this file.
1
10
15
16
17#ifndef COMPILE_VIDEO_STREAM
18#if defined(__AVR__)
19// This has grown too large for the AVR to handle.
20#define COMPILE_VIDEO_STREAM 0
21#else
22#define COMPILE_VIDEO_STREAM 1
23#endif
24#endif // COMPILE_VIDEO_STREAM
25
26#if COMPILE_VIDEO_STREAM
27
28
29#include <FastLED.h>
30#include "fl/bytestreammemory.h"
31#include "fx/fx_engine.h"
32#include "fl/memory.h"
33#include "fx/video.h"
34#include "fl/dbg.h"
35
36using namespace fl;
37
38#define LED_PIN 2
39#define BRIGHTNESS 96
40#define LED_TYPE WS2811
41#define COLOR_ORDER GRB
42
43#define MATRIX_WIDTH 22
44#define MATRIX_HEIGHT 22
45#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
46
48
49const int BYTES_PER_FRAME = 3 * NUM_LEDS;
50const int NUM_FRAMES = 2;
51const uint32_t BUFFER_SIZE = BYTES_PER_FRAME * NUM_FRAMES;
52
53ByteStreamMemoryPtr memoryStream;
55// Create and initialize Video object
57Video video(NUM_LEDS, 2.0f);
58
59void write_one_frame(ByteStreamMemoryPtr memoryStream) {
60 //memoryStream->seek(0); // Reset to the beginning of the stream
61 uint32_t total_bytes_written = 0;
62 bool toggle = (millis() / 500) % 2 == 0;
63 FASTLED_DBG("Writing frame data, toggle = " << toggle);
64 for (uint32_t i = 0; i < NUM_LEDS; ++i) {
65 CRGB color = (toggle ^ i%2) ? CRGB::Black : CRGB::Red;
66 size_t bytes_written = memoryStream->writeCRGB(&color, 1);
67 if (bytes_written != 1) {
68 FASTLED_DBG("Failed to write frame data, wrote " << bytes_written << " bytes");
69 break;
70 }
71 total_bytes_written += bytes_written;
72 }
73 if (total_bytes_written) {
74 FASTLED_DBG("Frame written, total bytes: " << total_bytes_written);
75 }
76}
77
78void setup() {
79 delay(1000); // sanity delay
81 .setCorrection(TypicalLEDStrip)
82 .setScreenMap(xymap);
83 FastLED.setBrightness(BRIGHTNESS);
84
85 // Create and fill the ByteStreamMemory with test data
86 memoryStream = fl::make_shared<ByteStreamMemory>(BUFFER_SIZE*sizeof(CRGB));
87
88 video.beginStream(memoryStream);
89 // Add the video effect to the FxEngine
90 fxEngine.addFx(video);
91}
92
93void loop() {
95 write_one_frame(memoryStream); // Write next frame data
96 }
97 // write_one_frame(memoryStream); // Write next frame data
98 // Draw the frame
99 fxEngine.draw(millis(), leds);
100 // Show the LEDs
101 FastLED.show();
102 delay(20); // Adjust this delay to control frame rate
103}
104#else
105void setup() {}
106void loop() {}
107#endif // COMPILE_VIDEO_STREAM
CRGB leds[NUM_LEDS]
#define NUM_LEDS
void setup()
void loop()
XYMap xymap(WIDTH, HEIGHT, SERPENTINE)
bool toggle
Definition Blur.ino:12
#define BRIGHTNESS
Definition Blur.ino:8
#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
#define LED_TYPE
Definition advanced.h:41
#define LED_PIN
Definition advanced.h:40
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:33
fl::unique_ptr< FxEngine > fxEngine
Definition curr.h:299
#define FASTLED_DBG(X)
Definition dbg.h:61
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1221
shared_ptr< T > make_shared(Args &&... args)
Definition shared_ptr.h:348
IMPORTANT!
Definition crgb.h:20
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:567
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86