FastLED 3.9.15
Loading...
Searching...
No Matches
FxSdCard.ino
Go to the documentation of this file.
1
10
11#include "FastLED.h"
12
13#if !SKETCH_HAS_LOTS_OF_MEMORY
14void setup() {
15 // put your setup code here, to run once:
16}
17
18void loop() {
19 // put your main code here, to run repeatedly:
20}
21#else
22
23#include "FastLED.h"
24#include "Arduino.h"
25
26#include "fx/2d/noisepalette.h"
27// #include "fx/2d/animartrix.hpp"
28#include "fx/fx_engine.h"
29#include "fx/video.h"
30#include "fl/file_system.h"
31#include "fl/ui.h"
32#include "fl/screenmap.h"
33#include "fl/file_system.h"
34
35
36using namespace fl;
37
38
39#define LED_PIN 2
40#define LED_TYPE WS2811
41#define COLOR_ORDER GRB
42#define FPS 60
43#define CHIP_SELECT_PIN 5
44
45
46
47#define MATRIX_WIDTH 32
48#define MATRIX_HEIGHT 32
49#define NUM_VIDEO_FRAMES 2 // enables interpolation with > 1 frame.
50
51
52#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
53#define IS_SERPINTINE true
54
55
56UITitle title("SDCard Demo - Mapped Video");
57UIDescription description("Video data is streamed off of a SD card and displayed on a LED strip. The video data is mapped to the LED strip using a ScreenMap.");
58
59
62
63FileSystem filesystem;
64Video video;
65Video video2;
66
67UISlider videoSpeed("Video Speed", 1.0f, -1, 2.0f, 0.01f);
68UINumberField whichVideo("Which Video", 0, 0, 1);
69
70
71bool gError = false;
72
73void setup() {
74 Serial.begin(115200);
75 Serial.println("Sketch setup");
76 // Initialize the file system and check for errors
77 if (!filesystem.beginSd(CHIP_SELECT_PIN)) {
78 Serial.println("Failed to initialize file system.");
79 }
80
81 // Open video files from the SD card
82 video = filesystem.openVideo("data/video.rgb", NUM_LEDS, FPS, 2);
83 if (!video) {
84 FASTLED_WARN("Failed to instantiate video");
85 gError = true;
86 return;
87 }
88 video2 = filesystem.openVideo("data/color_line_bubbles.rgb", NUM_LEDS, FPS, 2);
89 if (!video2) {
90 FASTLED_WARN("Failed to instantiate video2");
91 gError = true;
92 return;
93 }
94
95 // Read the screen map configuration
97 bool ok = filesystem.readScreenMap("data/screenmap.json", "strip1", &screenMap);
98 if (!ok) {
99 Serial.println("Failed to read screen map");
100 gError = true;
101 return;
102 }
103
104 // Configure FastLED with the LED type, pin, and color order
106 .setCorrection(TypicalLEDStrip)
107 .setScreenMap(screenMap);
108 FastLED.setBrightness(96);
109 Serial.println("FastLED setup done");
110}
111
112void loop() {
113 static bool s_first = true;
114 if (s_first) {
115 s_first = false;
116 Serial.println("First loop.");
117 }
118 if (gError) {
119 // If an error occurred, print a warning every second
120 EVERY_N_SECONDS(1) {
121 FASTLED_WARN("No loop because an error occured.");
122 }
123 return;
124 }
125
126 // Select the video to play based on the UI input
127 Video& vid = !bool(whichVideo.value()) ? video : video2;
128 vid.setTimeScale(videoSpeed);
129
130 // Get the current time and draw the video frame
131 uint32_t now = millis();
132 vid.draw(now, leds);
133 FastLED.show();
134}
135
136#endif
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
UITitle title("Chromancer")
#define COLOR_ORDER
#define LED_TYPE
#define LED_PIN
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:62
central include file for FastLED, defines the CFastLED class/object
void setup()
Definition FxSdCard.ino:14
void loop()
Definition FxSdCard.ino:18
bool beginSd(int cs_pin)
Video openVideo(const char *path, size_t pixelsPerFrame, float fps=30.0f, size_t nFrameHistory=0)
bool readScreenMap(const char *path, const char *name, ScreenMap *out, Str *error=nullptr)
void draw(DrawContext context) override
Definition video.cpp:94
void setTimeScale(float timeScale)
Definition video.cpp:124
fl::ScreenMap screenMap
Definition Corkscrew.h:70
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1306
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Demonstrates how to mix noise generation with color palettes on a 2D LED matrix.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55
#define FASTLED_WARN
Definition warn.h:7
UIDescription description("Advanced layered and blended wave effects.")