FastLED 3.9.7
Loading...
Searching...
No Matches
SdCard.ino
Go to the documentation of this file.
1
10
11
12#ifdef __AVR__
13void setup() {
14 // put your setup code here, to run once:
15}
16
17void loop() {
18 // put your main code here, to run repeatedly:
19}
20#else
21
22#include "FastLED.h"
23#include "Arduino.h"
24
25#include "fx/2d/noisepalette.h"
26// #include "fx/2d/animartrix.hpp"
27#include "fx/fx_engine.h"
28#include "fx/video.h"
29#include "fl/file_system.h"
30#include "fl/ui.h"
31#include "fl/screenmap.h"
32#include "fl/file_system.h"
33
34
35using namespace fl;
36
37
38#define LED_PIN 2
39#define LED_TYPE WS2811
40#define COLOR_ORDER GRB
41#define FPS 60
42#define CHIP_SELECT_PIN 5
43
44
45
46#define MATRIX_WIDTH 32
47#define MATRIX_HEIGHT 32
48#define NUM_VIDEO_FRAMES 2 // enables interpolation with > 1 frame.
49
50
51#define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
52#define IS_SERPINTINE true
53
54
55Title title("SDCard Demo - Mapped Video");
56Description 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.");
57
58
59CRGB leds[NUM_LEDS];
60ScreenMap screenMap;
61
62FileSystem filesystem;
63Video video;
64Video video2;
65
66Slider videoSpeed("Video Speed", 1.0f, -1, 2.0f, 0.01f);
67NumberField whichVideo("Which Video", 0, 0, 1);
68
69
70bool gError = false;
71
72void setup() {
73 Serial.begin(115200);
74 Serial.println("Sketch setup");
75 if (!filesystem.beginSd(CHIP_SELECT_PIN)) {
76 Serial.println("Failed to initialize file system.");
77 }
78
79 // Note that data/ is a special directory used by our wasm compiler. Any data
80 // is placed in it will be included in the files.json file which the browser will
81 // use to stream the file asynchroniously in during the runtime. For a real sd card
82 // just place all this in the /data/ directory of the SD card to get matching
83 // behavior.
84 video = filesystem.openVideo("data/video.rgb", NUM_LEDS, FPS, 2);
85 if (!video) {
86 FASTLED_WARN("Failed to instantiate video");
87 gError = true;
88 return;
89 }
90 video2 = filesystem.openVideo("data/color_line_bubbles.rgb", NUM_LEDS, FPS, 2);
91 if (!video2) {
92 FASTLED_WARN("Failed to instantiate video2");
93 gError = true;
94 return;
95 }
96 ScreenMap screenMap;
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 FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
105 .setCorrection(TypicalLEDStrip)
106 .setScreenMap(screenMap);
108 Serial.println("FastLED setup done");
109}
110
111void loop() {
112 static bool s_first = true;
113 if (s_first) {
114 s_first = false;
115 Serial.println("First loop.");
116 }
117 if (gError) {
118 EVERY_N_SECONDS(1) {
119 FASTLED_WARN("No loop because an error occured.");
120 }
121 return;
122 }
123 Video& vid = !bool(whichVideo.value()) ? video : video2;
124 vid.setTimeScale(videoSpeed);
125 uint32_t now = millis();
126 vid.draw(now, leds);
127 FastLED.show();
128}
129
130#endif
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
void draw(DrawContext context) override
Definition video.cpp:98
@ 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:1283
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:54