FastLED 3.9.15
Loading...
Searching...
No Matches
Fast Math Functions

Detailed Description

Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.

Because of the AVR (Arduino) and ARM assembly language implementations provided, using these functions often results in smaller and faster code than the equivalent program using plain "C" arithmetic and logic.

Included are:

Lib8tion is pronounced like 'libation': lie-BAY-shun

+ Collaboration diagram for Fast Math Functions:

Topics

 Easing Functions
 Specify the rate of change of a parameter over time.
 
 Fast Random Number Generators
 Fast 8-bit and 16-bit unsigned random number generators.
 
 Fixed-Point Fractional Types.
 Types for storing fractional data.
 
 Float-to-Fixed and Fixed-to-Float Conversions
 Functions to convert between floating point and fixed point types.
 
 Integer Mapping Functions
 Maps a scalar from one integer size to another.
 
 Linear Interpolation
 Fast linear interpolation functions, such as could be used for Perlin noise, etc.
 
 Waveform Generators
 General purpose wave generator functions.
 

Classes

class  CEveryNMillisDynamic
 Create the CEveryNMillisDynamic class for dynamic millisecond intervals. More...
 
class  CEveryNMillisRandom
 
class  CEveryNTime
 Time interval checking class. More...
 

Macros

#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME, TIMETYPE, TIMEGETTER)
 Preprocessor-based class "template" for CEveryNTime, used with EVERY_N_TIME timekeepers.
 
#define LIB8STATIC   __attribute__ ((unused)) static inline
 Define a LIB8TION member function as static inline with an "unused" attribute.
 
#define LIB8STATIC_ALWAYS_INLINE   FL_ALWAYS_INLINE
 Define a LIB8TION member function as always static inline This macro is deprecated and should be replaced with FL_ALWAYS_INLINE.
 

CEveryNTime Base Classes

These macros define the time interval checking classes used in the EVERY_N_TIME time macros.

 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNMillis, fl::u32, GET_MILLIS)
 Create the CEveryNMillis class for millisecond intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNSeconds, fl::u16, seconds16)
 Create the CEveryNSeconds class for second intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNBSeconds, fl::u16, bseconds16)
 Create the CEveryNBSeconds class for bsecond intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNMinutes, fl::u16, minutes16)
 Create the CEveryNMinutes class for minutes intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNHours, fl::u8, hours8)
 Create the CEveryNHours class for hours intervals.
 
#define CEveryNMilliseconds   CEveryNMillis
 Alias for CEveryNMillis.
 

"EVERY_N_TIME" Macros

Check whether to excecute a block of code every N amount of time.

These are useful for limiting how often code runs. For example, you can use fill_rainbow() to fill a strip of LEDs with color, combined with an EVERY_N_MILLIS block to limit how fast the colors change:

static uint8_t hue = 0;
EVERY_N_MILLIS(20) { hue++; } // advances hue every 20 milliseconds
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
uint8_t hue
Definition advanced.h:94
void fill_rainbow(CRGB *targetArray, int numToFill, u8 initialhue, u8 deltahue)
Fill a range of LEDs with a rainbow of colors.
Definition fill.cpp.hpp:29
#define EVERY_N_MILLIS(N)
Checks whether to execute a block of code every N milliseconds.
Definition lib8tion.h:1001
unsigned char uint8_t
Definition s16x16x4.h:209

Note that in order for these to be accurate, the EVERY_N block must be evaluated at a regular basis.

#define EVERY_N_MILLIS(N)
 Checks whether to execute a block of code every N milliseconds.
 
#define EVERY_N_MILLIS_I(NAME, N)
 Checks whether to execute a block of code every N milliseconds, using a custom instance name.
 
#define EVERY_N_SECONDS(N)
 Checks whether to execute a block of code every N seconds.
 
#define EVERY_N_SECONDS_I(NAME, N)
 Checks whether to execute a block of code every N seconds, using a custom instance name.
 
#define EVERY_N_BSECONDS(N)
 Checks whether to execute a block of code every N bseconds.
 
#define EVERY_N_BSECONDS_I(NAME, N)
 Checks whether to execute a block of code every N bseconds, using a custom instance name.
 
#define EVERY_N_MINUTES(N)
 Checks whether to execute a block of code every N minutes.
 
#define EVERY_N_MINUTES_I(NAME, N)
 Checks whether to execute a block of code every N minutes, using a custom instance name.
 
#define EVERY_N_HOURS(N)
 Checks whether to execute a block of code every N hours.
 
#define EVERY_N_HOURS_I(NAME, N)
 Checks whether to execute a block of code every N hours, using a custom instance name.
 
#define EVERY_N_MILLISECONDS(N)
 Alias for EVERY_N_MILLIS.
 
#define EVERY_N_MILLISECONDS_I(NAME, N)
 Alias for EVERY_N_MILLIS_I.
 
#define EVERY_N_MILLISECONDS_DYNAMIC(PERIOD_FUNC)
 Checks whether to execute a block of code every N milliseconds, where N is determined dynamically.
 
#define EVERY_N_MILLISECONDS_DYNAMIC_I(NAME, PERIOD_FUNC)
 Checks whether to execute a block of code every N milliseconds, where N is determined dynamically, using a custom instance name.
 
#define EVERY_N_MILLISECONDS_RANDOM(MIN, MAX)
 
#define EVERY_N_MILLISECONDS_RANDOM_I(NAME, MIN, MAX)