FastLED 3.9.15
Loading...
Searching...
No Matches
FxGfx2Video.ino

This sketch is fully compatible with the FastLED web compiler.

This sketch is fully compatible with the FastLED web compiler. To use it do the following:

  1. Install Fastled: pip install fastled
  2. cd into this examples page.
  3. Run the FastLED web compiler at root: fastled
  4. When the compiler is done a web page will open.
#ifndef COMPILE_VIDEO_STREAM
#if defined(__AVR__)
// This has grown too large for the AVR to handle.
#define COMPILE_VIDEO_STREAM 0
#else
#define COMPILE_VIDEO_STREAM 1
#endif
#endif // COMPILE_VIDEO_STREAM
#if COMPILE_VIDEO_STREAM
#include <FastLED.h>
#include "fx/fx_engine.h"
#include "fl/memory.h"
#include "fx/video.h"
#include "fl/dbg.h"
using namespace fl;
#define LED_PIN 2
#define BRIGHTNESS 96
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define MATRIX_WIDTH 22
#define MATRIX_HEIGHT 22
#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
const int BYTES_PER_FRAME = 3 * NUM_LEDS;
const int NUM_FRAMES = 2;
const uint32_t BUFFER_SIZE = BYTES_PER_FRAME * NUM_FRAMES;
ByteStreamMemoryPtr memoryStream;
// Create and initialize Video object
Video video(NUM_LEDS, 2.0f);
void write_one_frame(ByteStreamMemoryPtr memoryStream) {
//memoryStream->seek(0); // Reset to the beginning of the stream
uint32_t total_bytes_written = 0;
bool toggle = (millis() / 500) % 2 == 0;
FASTLED_DBG("Writing frame data, toggle = " << toggle);
for (uint32_t i = 0; i < NUM_LEDS; ++i) {
CRGB color = (toggle ^ i%2) ? CRGB::Black : CRGB::Red;
size_t bytes_written = memoryStream->writeCRGB(&color, 1);
if (bytes_written != 1) {
FASTLED_DBG("Failed to write frame data, wrote " << bytes_written << " bytes");
break;
}
total_bytes_written += bytes_written;
}
if (total_bytes_written) {
FASTLED_DBG("Frame written, total bytes: " << total_bytes_written);
}
}
void setup() {
delay(1000); // sanity delay
.setCorrection(TypicalLEDStrip)
.setScreenMap(xymap);
FastLED.setBrightness(BRIGHTNESS);
// Create and fill the ByteStreamMemory with test data
memoryStream = fl::make_shared<ByteStreamMemory>(BUFFER_SIZE*sizeof(CRGB));
video.beginStream(memoryStream);
// Add the video effect to the FxEngine
fxEngine.addFx(video);
}
void loop() {
write_one_frame(memoryStream); // Write next frame data
}
// write_one_frame(memoryStream); // Write next frame data
// Draw the frame
fxEngine.draw(millis(), leds);
// Show the LEDs
FastLED.show();
delay(20); // Adjust this delay to control frame rate
}
#else
void setup() {}
void loop() {}
#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