Repository navigation
Open
Labels
area: examplesExample sketches and demosstatus: triageNeeds initial assessmenttype: featureNew capability or enhancement
Description
There are a few little modernizations we could make to the example sketches that would help new users get started faster, and develop good habits from the start.
- Switch from
FastLED.setBrightness(...)toFastLED.setMaxPowerInVoltsAndMilliamps( ... ) - [done!] Switch
LEDS.[function]toFastLED.[function] - [done!] Switch from
bytetouint8_t - [done!] Use
uint16_tfor all LED index variables, so that the examples all work with > 255 LEDs - Use
FastLED.showAndHold( ... )(when that exists) instead ofFastLED.show(); FastLED.delay( ...);, with an explicit note that it will keep actively refreshing the LEDs to make temporal dithering / fractional brightnesses work. (See discussion in Please remove FastLED.delay() #1206, in terms of educating new users about the effects of these choices.) - Try to make all examples run at about the same visual speed regardless of microcontroller speed, e.g. use
FastLED.showAndHold(...), or have animations be a function of time, rather than a function of number-of-iterations . - Switch from manifest constants (
#define) tostatic constwhere possible and more legible. - Switch from a startup
delay(3000);to perhaps a warmup function, likeFastLED.fadeIn( 3000 ), which doesn't exist yet in the library as of 3/17/2021, but which I have code for. - [done!] Remove messages about minimum version of FastLED to use
- Unify overall structure of each sketch so they're easier to read as a group
There are other larger pieces of rework we could do, e.g. make the demo animations like Fire2012 into their own classes, with proper member variables to control parameters, etc., but this Issue is not for tracking that work; this issue is just for tracking the small modernizations listed above.
Reacted by Kostyantyn Matviyevskyy, Marc Miller, Julian Schmidt, Elliott Kember, Alexey Sychev, Phozer, Benson Trent, Ralf and John Milner
Metadata
Metadata
Assignees
Labels
area: examplesExample sketches and demosstatus: triageNeeds initial assessmenttype: featureNew capability or enhancement
Type
Projects
- StatusShow more project fieldsTriage
Activity
yesyesuk commentedon Mar 18, 2021
Just for my understanding, why is that better? It is my understanding that "static const" would take up memory whereas a "#define" would not.
kriegsman commentedon Mar 22, 2021
This is a great question! Twenty (or thirty!) years ago, most C or C++ compilers would have actually created the variable for the
static const, which would take up RAM at runtime, as you suggested that it might. However, when any modern compilers see astatic constvalue, they literally forward the value of the constant into the surrounding code, as if you had just typed the constant value inline yourself.You can check your compiler yourself by taking some code, switching it back and forth between a
#defineand astatic constfor the compile-time constants, and checking the size of the executable code (or by literally comparing the disassembly of the executable code). If the code is exactly the same, then you have a modern compiler that does 'constant propagation' aka 'constant forwarding'. If the generated code is different, then you probably have a very old compiler on your hands. More information on constant propagation: https://en.wikipedia.org/wiki/Constant_foldingUsing a
static constalso offers type safety, which makes it a cleaner, safer choice than a#define, all other things being equal.Part of why this is a great question is because the answer used to be that a
#defineused less memory at runtime, because no variable was created, but today virtually all compilers do excellent constant propagation, and they don't bother creating the wasteful, unused variable. So if you have a programming book from more than ten years ago, it probably said "use #define", and it was right at the time! But contemporary compilers are much smarter and more aggressive about code optimization than they were back in the day, and the 'right answer' to this question has changed!Thanks for asking this question - it's a good one.
ssilverman commentedon Apr 2, 2021
Would
constexprbe acceptable in the examples instead ofconst? I figure that C++11 or even 14 is an okay target? I’ve been coding most of my own projects to at least C++14 and sometimes 17. What is your preference?Merge pull request #1218 from marmilicious/master
Some Modernization updates for FastLED#1208
github-actions commentedon Sep 3, 2026
This issue was closed after 30 additional days without activity. If it is still relevant, please comment with current reproduction details or other actionable information and it can be reopened.
zackees commentedon Sep 3, 2026
Reopening: this issue was closed automatically by a stale-bot run, not by a maintainer decision. That auto-close behavior was a mistake and has been disabled — FastLED issues will no longer be closed for inactivity. Apologies for the noise.