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.h"
6#include "fl/async.h"
7
8#define NUM_LEDS 60
9#define DATA_PIN 5
10
13
14void setup() {
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}
CRGB leds[NUM_LEDS]
#define NUM_LEDS
#define DATA_PIN
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
WS2812B controller class.
Definition FastLED.h:236
task & then(function< void()> on_then)
Definition task.cpp:188
static task at_framerate(int fps)
Definition task.cpp:151
static task every_ms(int interval_ms)
Definition task.cpp:143
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
Definition fill.cpp:9
@ GRB
Green, Red, Blue (0102)
Definition eorder.h:16
void setup()
Definition Async.h:14
CRGB current_color
Definition Async.h:12
void loop()
Definition Async.h:32
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:46
void async_run()
Run all registered async tasks once.
Definition async.cpp:63
Generic asynchronous task management for FastLED.
@ 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
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition hsv.h:15
#define FL_TRACE
A macro to capture the current source file, line number, and time.
Definition trace.h:27