FastLED 3.9.3
Loading...
Searching...
No Matches
lib8tion.h File Reference

Detailed Description

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


Definition in file lib8tion.h.

#include "FastLED.h"
#include "lib8tion/types.h"
#include <stdint.h>
#include "lib8tion/lib8static.h"
#include "qfx.h"
#include <string.h>
#include "lib8tion/math8.h"
#include "lib8tion/scale8.h"
#include "lib8tion/random8.h"
#include "lib8tion/trig8.h"

Go to the source code of this file.

Classes

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

Macros

#define GET_MILLIS   millis
 The a number of functions need access to a millisecond counter in order to keep time.
 
#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME, TIMETYPE, TIMEGETTER)
 Preprocessor-based class "template" for CEveryNTime, used with EVERY_N_TIME timekeepers.
 
#define USE_GET_MILLISECOND_TIMER
 Set this flag to use the get_millisecond_timer() function in place of the default millis() function.
 
"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;
fill_rainbow(leds, NUM_LEDS, hue);
EVERY_N_MILLIS(20) { hue++; } // advances hue every 20 milliseconds
void fill_rainbow(struct CRGB *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue)
Fill a range of LEDs with a rainbow of colors.
#define EVERY_N_MILLIS(N)
Checks whether to execute a block of code every N milliseconds.
Definition lib8tion.h:1279

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)   EVERY_N_MILLIS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N milliseconds.
 
#define EVERY_N_MILLIS_I(NAME, N)   static CEveryNMillis NAME(N); if( NAME )
 Checks whether to execute a block of code every N milliseconds, using a custom instance name.
 
#define EVERY_N_SECONDS(N)   EVERY_N_SECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N seconds.
 
#define EVERY_N_SECONDS_I(NAME, N)   static CEveryNSeconds NAME(N); if( NAME )
 Checks whether to execute a block of code every N seconds, using a custom instance name.
 
#define EVERY_N_BSECONDS(N)   EVERY_N_BSECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N bseconds.
 
#define EVERY_N_BSECONDS_I(NAME, N)   static CEveryNBSeconds NAME(N); if( NAME )
 Checks whether to execute a block of code every N bseconds, using a custom instance name.
 
#define EVERY_N_MINUTES(N)   EVERY_N_MINUTES_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N minutes.
 
#define EVERY_N_MINUTES_I(NAME, N)   static CEveryNMinutes NAME(N); if( NAME )
 Checks whether to execute a block of code every N minutes, using a custom instance name.
 
#define EVERY_N_HOURS(N)   EVERY_N_HOURS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N hours.
 
#define EVERY_N_HOURS_I(NAME, N)   static CEveryNHours NAME(N); if( NAME )
 Checks whether to execute a block of code every N hours, using a custom instance name.
 
#define EVERY_N_MILLISECONDS(N)   EVERY_N_MILLIS(N)
 Alias for EVERY_N_MILLIS.
 
#define EVERY_N_MILLISECONDS_I(NAME, N)   EVERY_N_MILLIS_I(NAME,N)
 Alias for EVERY_N_MILLIS_I.
 
#define EVERY_N_MILLISECONDS_DYNAMIC(PERIOD_FUNC)   EVERY_N_MILLISECONDS_DYNAMIC_I(CONCAT_MACRO(__dynamic_millis_timer, __COUNTER__ ), (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.
 

Functions

LIB8STATIC float sfract15ToFloat (sfract15 y)
 Conversion from 16-bit fixed point (sfract15) to IEEE754 32-bit float.
 
LIB8STATIC sfract15 floatToSfract15 (float f)
 Conversion from IEEE754 float in the range (-1,1) to 16-bit fixed point (sfract15).
 
void * memmove8 (void *dst, const void *src, uint16_t num)
 Faster alternative to memmove() on AVR.
 
void * memcpy8 (void *dst, const void *src, uint16_t num)
 Faster alternative to memcpy() on AVR.
 
void * memset8 (void *ptr, uint8_t value, uint16_t num)
 Faster alternative to memset() on AVR.
 
LIB8STATIC uint8_t lerp8by8 (uint8_t a, uint8_t b, fract8 frac)
 Linear interpolation between two unsigned 8-bit values, with 8-bit fraction.
 
LIB8STATIC uint16_t lerp16by16 (uint16_t a, uint16_t b, fract16 frac)
 Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
 
LIB8STATIC uint16_t lerp16by8 (uint16_t a, uint16_t b, fract8 frac)
 Linear interpolation between two unsigned 16-bit values, with 8-bit fraction.
 
LIB8STATIC int16_t lerp15by8 (int16_t a, int16_t b, fract8 frac)
 Linear interpolation between two signed 15-bit values, with 8-bit fraction.
 
LIB8STATIC int16_t lerp15by16 (int16_t a, int16_t b, fract16 frac)
 Linear interpolation between two signed 15-bit values, with 8-bit fraction.
 
LIB8STATIC uint8_t map8 (uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
 Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
 
LIB8STATIC uint8_t ease8InOutQuad (uint8_t i)
 8-bit quadratic ease-in / ease-out function.
 
LIB8STATIC uint16_t ease16InOutQuad (uint16_t i)
 16-bit quadratic ease-in / ease-out function.
 
LIB8STATIC fract8 ease8InOutCubic (fract8 i)
 8-bit cubic ease-in / ease-out function.
 
LIB8STATIC fract8 ease8InOutApprox (fract8 i)
 Fast, rough 8-bit ease-in/ease-out function.
 
LIB8STATIC uint8_t triwave8 (uint8_t in)
 Triangle wave generator.
 
LIB8STATIC uint8_t quadwave8 (uint8_t in)
 Quadratic waveform generator.
 
LIB8STATIC uint8_t cubicwave8 (uint8_t in)
 Cubic waveform generator.
 
LIB8STATIC uint8_t squarewave8 (uint8_t in, uint8_t pulsewidth=128)
 Square wave generator.
 
LIB8STATIC uint16_t beat88 (accum88 beats_per_minute_88, uint32_t timebase=0)
 Generates a 16-bit "sawtooth" wave at a given BPM, with BPM specified in Q8.8 fixed-point format.
 
LIB8STATIC uint16_t beat16 (accum88 beats_per_minute, uint32_t timebase=0)
 Generates a 16-bit "sawtooth" wave at a given BPM.
 
LIB8STATIC uint8_t beat8 (accum88 beats_per_minute, uint32_t timebase=0)
 Generates an 8-bit "sawtooth" wave at a given BPM.
 
LIB8STATIC uint16_t beatsin88 (accum88 beats_per_minute_88, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
 Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint16_t beatsin16 (accum88 beats_per_minute, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
 Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint8_t beatsin8 (accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
 Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint16_t seconds16 ()
 Return the current seconds since boot in a 16-bit value.
 
LIB8STATIC uint16_t minutes16 ()
 Return the current minutes since boot in a 16-bit value.
 
LIB8STATIC uint8_t hours8 ()
 Return the current hours since boot in an 8-bit value.
 
LIB8STATIC uint16_t div1024_32_16 (uint32_t in32)
 Helper routine to divide a 32-bit value by 1024, returning only the low 16 bits.
 
LIB8STATIC uint16_t bseconds16 ()
 Returns the current time-since-boot in "binary seconds", which are actually 1024/1000 of a second long.
 

CEveryNTime Base Classes

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

#define CEveryNMilliseconds   CEveryNMillis
 Alias for CEveryNMillis.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNMillis, uint32_t, GET_MILLIS)
 Create the CEveryNMillis class for millisecond intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNSeconds, uint16_t, seconds16)
 Create the CEveryNSeconds class for second intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNBSeconds, uint16_t, bseconds16)
 Create the CEveryNBSeconds class for bsecond intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNMinutes, uint16_t, minutes16)
 Create the CEveryNMinutes class for minutes intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNHours, uint8_t, hours8)
 Create the CEveryNHours class for hours intervals.