FastLED 3.9.3
Loading...
Searching...
No Matches
Gfx2Video.ino
1
5
6
7#ifndef COMPILE_VIDEO_STREAM
8#if defined(__AVR__)
9// This has grown too large for the AVR to handle.
10#define COMPILE_VIDEO_STREAM 0
11#else
12#define COMPILE_VIDEO_STREAM 1
13#endif
14#endif // COMPILE_VIDEO_STREAM
15
16#if COMPILE_VIDEO_STREAM
17
18
19#include <FastLED.h>
20#include "fx/storage/bytestreammemory.h"
21#include "fx/2d/video.hpp"
22#include "fx/fx_engine.h"
23#include "ref.h"
24#include "fx/video.h"
25
26#define LED_PIN 2
27#define BRIGHTNESS 96
28#define LED_TYPE WS2811
29#define COLOR_ORDER GRB
30
31#define MATRIX_WIDTH 22
32#define MATRIX_HEIGHT 22
33#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
34
35CRGB leds[NUM_LEDS];
36
37const int BYTES_PER_FRAME = 3 * NUM_LEDS;
38const int NUM_FRAMES = 2;
39const uint32_t BUFFER_SIZE = BYTES_PER_FRAME * NUM_FRAMES;
40
41ByteStreamMemoryRef memoryStream;
42FxEngine fxEngine(NUM_LEDS);
43// Create and initialize Video fx object
44XYMap xymap(MATRIX_WIDTH, MATRIX_HEIGHT);
45
46void write_one_frame(ByteStreamMemoryRef memoryStream) {
47 //memoryStream->seek(0); // Reset to the beginning of the stream
48 uint32_t total_bytes_written = 0;
49 int toggle = (millis() / 500) % 2;
50 for (uint32_t i = 0; i < NUM_LEDS; ++i) {
51 CRGB color = (i % 2 == toggle) ? CRGB::Black : CRGB::Red;
52 size_t bytes_written = memoryStream->write(color.raw, 3);
53 if (bytes_written != 3) {
54 }
55 total_bytes_written += bytes_written;
56 }
57}
58
59void setup() {
60 delay(1000); // sanity delay
61 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
62 .setCorrection(TypicalLEDStrip)
63 .setScreenMap(xymap);
64 FastLED.setBrightness(BRIGHTNESS);
65
66 // Create and fill the ByteStreamMemory with test data
67 memoryStream = ByteStreamMemoryRef::New(BUFFER_SIZE);
68 write_one_frame(memoryStream); // Write initial frame data
69 Video video(memoryStream, NUM_LEDS, 30.0f, 0);
70 // Add the video effect to the FxEngine
71 fxEngine.addVideo(video, xymap);
72}
73
74void loop() {
75 // Reset the memory stream position before reading
76 //memoryStream->seek(0);
77 write_one_frame(memoryStream); // Write next frame data
78
79 // Draw the frame
80 fxEngine.draw(millis(), leds);
81
82 // Show the LEDs
83 FastLED.show();
84
85 delay(100); // Adjust this delay to control frame rate
86}
87#else
88void setup() {}
89void loop() {}
90#endif // COMPILE_VIDEO_STREAM
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
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:37
int addVideo(Video video, XYMap xymap)
Adds a new video effect to the engine.
Definition fx_engine.h:158
bool draw(uint32_t now, CRGB *outputBuffer)
Renders the current effect or transition to the output buffer.
Definition fx_engine.h:213
Definition video.h:23
Definition xymap.h:39
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
uint8_t raw[3]
Access the red, green, and blue data as an array.
Definition crgb.h:60
@ Black
Definition crgb.h:479
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39