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.

The render pattern is alternating black/red pixels as a checkerboard. Demonstrates drawing to a frame buffer, which is used as source video for the memory player.

// @filter: (memory is large)
#include <FastLED.h>
#include "fl/stl/memory.h"
#include "fl/fx/video.h"
#include "fl/log/log.h"
#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;
fl::memorybufPtr memoryStream;
// Create and initialize Video object
void write_one_frame(fl::memorybufPtr memoryStream) {
//memoryStream->seek(0); // Reset to the beginning of the stream
uint32_t total_bytes_written = 0;
bool toggle = (fl::millis() / 500) % 2 == 0;
FL_DBG("Writing frame data, toggle = " << toggle);
for (uint32_t i = 0; i < NUM_LEDS; ++i) {
fl::CRGB color = (toggle ^ i%2) ? fl::CRGB::Black : fl::CRGB::Red;
size_t bytes_written = memoryStream->writeCRGB(&color, 1);
if (bytes_written != 1) {
FL_DBG("Failed to write frame data, wrote " << bytes_written << " bytes");
break;
}
total_bytes_written += bytes_written;
}
if (total_bytes_written) {
FL_DBG("Frame written, total bytes: " << total_bytes_written);
}
}
void setup() {
delay(1000); // sanity delay
.setCorrection(TypicalLEDStrip)
.setScreenMap(xymap);
FastLED.setBrightness(BRIGHTNESS);
// Create memory-backed file handle for streaming video
// 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
// Show the LEDs
FastLED.show();
delay(20); // Adjust this delay to control frame rate
}
void setup()
void loop()
#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.
const uint32_t BUFFER_SIZE
fl::Video video(NUM_LEDS, 2.0f)
fl::memorybufPtr memoryStream
const int BYTES_PER_FRAME
const int NUM_FRAMES
void write_one_frame(fl::memorybufPtr memoryStream)
#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
fl::CRGB CRGB
Definition crgb.h:25
#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.
void delay(u32 ms, bool run_async=true) FL_NOEXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
Definition delay.h:98
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
Base definition for an LED controller.
Definition crgb.hpp:179
@ 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