FastLED 3.9.15
Loading...
Searching...
No Matches
Async.h
Go to the documentation of this file.
1// @file examples/TaskExample/TaskExample.ino
2// @brief Example showing how to use the fl::task API
3
4#include "FastLED.h"
5#include "fl/task/task.h"
6#include "fl/task/executor.h"
7
8#define NUM_LEDS 60
9#define DATA_PIN 5
10
13
14void setup() {
15 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
16 FastLED.setBrightness(16);
17
18 // Create a task that runs every 100ms to change color
19 auto colorPicker = fl::task::every_ms(100, FL_TRACE)
20 .then([] {
21 current_color = CHSV(random8(), 255, 255);
22 });
23
24 // Create a task that runs at 60fps to update the LEDs
25 auto displayTask = fl::task::at_framerate(60, FL_TRACE)
26 .then([] {
28 FastLED.show();
29 });
30}
31
32void loop() {
33 // Yield to allow other operations to run
35}
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
void setup()
Definition Async.h:14
CRGB current_color
Definition Async.h:12
void loop()
Definition Async.h:32
#define DATA_PIN
Definition ClientReal.h:82
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Handle & then(function< void()> on_then) FL_NOEXCEPT
Definition task.cpp.hpp:276
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:9
constexpr EOrder GRB
Definition eorder.h:19
Task executor — runs registered task runners and manages the run loop.
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition crgb.h:25
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53
Handle every_ms(int interval_ms)
Definition task.cpp.hpp:320
void run(fl::u32 microseconds, ExecFlags flags)
Run selected task subsystems.
Handle at_framerate(int fps)
Definition task.cpp.hpp:328
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:510
#define FL_TRACE
A macro to capture the current source file, line number, and time.
Definition trace.h:102