FastLED 3.9.7
Loading...
Searching...
No Matches
Gfx2Video.ino
Go to the documentation of this file.
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 "fl/bytestreammemory.h"
21#include "fx/fx_engine.h"
22#include "fl/ptr.h"
23#include "fx/video.h"
24#include "fl/dbg.h"
25
26using namespace fl;
27
28#define LED_PIN 2
29#define BRIGHTNESS 96
30#define LED_TYPE WS2811
31#define COLOR_ORDER GRB
32
33#define MATRIX_WIDTH 22
34#define MATRIX_HEIGHT 22
35#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
36
37CRGB leds[NUM_LEDS];
38
39const int BYTES_PER_FRAME = 3 * NUM_LEDS;
40const int NUM_FRAMES = 2;
41const uint32_t BUFFER_SIZE = BYTES_PER_FRAME * NUM_FRAMES;
42
43ByteStreamMemoryPtr memoryStream;
44FxEngine fxEngine(NUM_LEDS);
45// Create and initialize Video object
46XYMap xymap(MATRIX_WIDTH, MATRIX_HEIGHT);
47Video video(NUM_LEDS, 2.0f);
48
49void write_one_frame(ByteStreamMemoryPtr memoryStream) {
50 //memoryStream->seek(0); // Reset to the beginning of the stream
51 uint32_t total_bytes_written = 0;
52 bool toggle = (millis() / 500) % 2 == 0;
53 FASTLED_DBG("Writing frame data, toggle = " << toggle);
54 for (uint32_t i = 0; i < NUM_LEDS; ++i) {
55 CRGB color = (toggle ^ i%2) ? CRGB::Black : CRGB::Red;
56 size_t bytes_written = memoryStream->writeCRGB(&color, 1);
57 if (bytes_written != 1) {
58 FASTLED_DBG("Failed to write frame data, wrote " << bytes_written << " bytes");
59 break;
60 }
61 total_bytes_written += bytes_written;
62 }
63}
64
65void setup() {
66 delay(1000); // sanity delay
67 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
68 .setCorrection(TypicalLEDStrip)
69 .setScreenMap(xymap);
70 FastLED.setBrightness(BRIGHTNESS);
71
72 // Create and fill the ByteStreamMemory with test data
73 memoryStream = ByteStreamMemoryPtr::New(BUFFER_SIZE*sizeof(CRGB));
74
75 video.beginStream(memoryStream);
76 // Add the video effect to the FxEngine
77 fxEngine.addFx(video);
78}
79
80void loop() {
82 write_one_frame(memoryStream); // Write next frame data
83 }
84 // write_one_frame(memoryStream); // Write next frame data
85 // Draw the frame
86 fxEngine.draw(millis(), leds);
87 // Show the LEDs
88 FastLED.show();
89 delay(20); // Adjust this delay to control frame rate
90}
91#else
92void setup() {}
93void loop() {}
94#endif // COMPILE_VIDEO_STREAM
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:45
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:723
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:94
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:79
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:38
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1318
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:54
@ Black
Definition crgb.h:496