FastLED 3.6.0
Loading...
Searching...
No Matches
CFastLED Class Reference

Detailed Description

High level controller interface for FastLED.

This class manages controllers, global settings, and trackings such as brightness and refresh rates, and provides access functions for driving led data to controllers via the show() / showColor() / clear() methods. This is instantiated as a global object with the name FastLED.

Definition at line 221 of file FastLED.h.

#include <FastLED.h>

Public Member Functions

void setBrightness (uint8_t scale)
 Set the global brightness scaling.
 
uint8_t getBrightness ()
 Get the current global brightness setting.
 
void setMaxPowerInVoltsAndMilliamps (uint8_t volts, uint32_t milliamps)
 Set the maximum power to be used, given in volts and milliamps.
 
void setMaxPowerInMilliWatts (uint32_t milliwatts)
 Set the maximum power to be used, given in milliwatts.
 
void show (uint8_t scale)
 Update all our controllers with the current led colors, using the passed in brightness.
 
void show ()
 Update all our controllers with the current led colors.
 
void clear (bool writeData=false)
 Clear the leds, wiping the local array of data.
 
void clearData ()
 Clear out the local data array.
 
void showColor (const struct CRGB &color, uint8_t scale)
 Set all leds on all controllers to the given color/scale.
 
void showColor (const struct CRGB &color)
 Set all leds on all controllers to the given color.
 
void delay (unsigned long ms)
 Delay for the given number of milliseconds.
 
void setTemperature (const struct CRGB &temp)
 Set a global color temperature.
 
void setCorrection (const struct CRGB &correction)
 Set a global color correction.
 
void setDither (uint8_t ditherMode=BINARY_DITHER)
 Set the dithering mode.
 
void setMaxRefreshRate (uint16_t refresh, bool constrain=false)
 Set the maximum refresh rate.
 
void countFPS (int nFrames=25)
 For debugging, this will keep track of time between calls to countFPS().
 
uint16_t getFPS ()
 Get the number of frames/second being written out.
 
int count ()
 Get how many controllers have been registered.
 
CLEDControlleroperator[] (int x)
 Get a reference to a registered controller.
 
int size ()
 Get the number of leds in the first controller.
 
CRGBleds ()
 Get a pointer to led data for the first controller.
 

Static Public Member Functions

static CLEDControlleraddLeds (CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a CLEDController instance to the world.
 

Adding SPI-based controllers

Add an SPI based CLEDController instance to the world.

There are two ways to call this method (as well as the other addLeds() variations). The first is with 2 arguments, in which case the arguments are a pointer to led data, and the number of leds used by this controller. The second is with 3 arguments, in which case the first argument is the same, the second argument is an offset into the CRGB data where this controller's CRGB data begins, and the third argument is the number of leds for this controller object.

Parameters
database pointer to an array of CRGB data structures
nLedsOrOffsetnumber of leds (3 argument version) or offset into the data array
nLedsIfOffsetnumber of leds (4 argument version)
Template Parameters
CHIPSETthe chipset type
DATA_PINthe optional data pin for the leds (if omitted, will default to the first hardware SPI MOSI pin)
CLOCK_PINthe optional clock pin for the leds (if omitted, will default to the first hardware SPI clock pin)
RGB_ORDERthe rgb ordering for the leds (e.g. what order red, green, and blue data is written out in)
SPI_DATA_RATEthe data rate to drive the SPI clock at, defined using DATA_RATE_MHZ or DATA_RATE_KHZ macros
Returns
a reference to the added controller
template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER, uint32_t SPI_DATA_RATE>
CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add an SPI based CLEDController instance to the world.
 
template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add an SPI based CLEDController instance to the world.
 
template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add an SPI based CLEDController instance to the world.
 

Adding 3-wire led controllers

Add a clockless (aka 3-wire, also DMX) based CLEDController instance to the world.

There are two ways to call this method (as well as the other addLeds() variations). The first is with 2 arguments, in which case the arguments are a pointer to led data, and the number of leds used by this controller. The second is with 3 arguments, in which case the first argument is the same, the second argument is an offset into the CRGB data where this controller's CRGB data begins, and the third argument is the number of leds for this controller object.

This method also takes 2 to 3 template parameters for identifying the specific chipset, data pin, RGB ordering, and SPI data rate

Parameters
database pointer to an array of CRGB data structures
nLedsOrOffsetnumber of leds (3 argument version) or offset into the data array
nLedsIfOffsetnumber of leds (4 argument version)
Template Parameters
CHIPSETthe chipset type (required)
DATA_PINthe data pin for the leds (required)
RGB_ORDERthe rgb ordering for the leds (e.g. what order red, green, and blue data is written out in)
Returns
a reference to the added controller
template<template< uint8_t DATA_PIN, EOrder RGB_ORDER > class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a clockless based CLEDController instance to the world.
 
template<template< uint8_t DATA_PIN, EOrder RGB_ORDER > class CHIPSET, uint8_t DATA_PIN>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a clockless based CLEDController instance to the world.
 
template<template< uint8_t DATA_PIN > class CHIPSET, uint8_t DATA_PIN>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a clockless based CLEDController instance to the world.
 

Adding 3rd party library controllers

Add a 3rd party library based CLEDController instance to the world.

There are two ways to call this method (as well as the other addLeds() variations). The first is with 2 arguments, in which case the arguments are a pointer to led data, and the number of leds used by this controller. The second is with 3 arguments, in which case the first argument is the same, the second argument is an offset into the CRGB data where this controller's CRGB data begins, and the third argument is the number of leds for this controller object. This class includes the SmartMatrix and OctoWS2811 based controllers

This method also takes 1 to 2 template parameters for identifying the specific chipset and RGB ordering.

Parameters
database pointer to an array of CRGB data structures
nLedsOrOffsetnumber of leds (3 argument version) or offset into the data array
nLedsIfOffsetnumber of leds (4 argument version)
Template Parameters
CHIPSETthe chipset type (required)
RGB_ORDERthe rgb ordering for the leds (e.g. what order red, green, and blue data is written out in)
Returns
a reference to the added controller
template<template< EOrder RGB_ORDER > class CHIPSET, EOrder RGB_ORDER>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a 3rd party library based CLEDController instance to the world.
 
template<template< EOrder RGB_ORDER > class CHIPSET>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a 3rd party library based CLEDController instance to the world.
 
template<OWS2811 CHIPSET, EOrder RGB_ORDER>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a OCTOWS2811 based CLEDController instance to the world.
 
template<OWS2811 CHIPSET>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a OCTOWS2811 library based CLEDController instance to the world.
 
template<SWS2812 CHIPSET, int DATA_PIN, EOrder RGB_ORDER>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a WS2812Serial library based CLEDController instance to the world.
 
template<ESM CHIPSET>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a SmartMatrix library based CLEDController instance to the world.
 

Adding parallel output controllers

Add a block based CLEDController instance to the world.

There are two ways to call this method (as well as the other addLeds() variations). The first is with 2 arguments, in which case the arguments are a pointer to led data, and the number of leds used by this controller. The second is with 3 arguments, in which case the first argument is the same, the second argument is an offset into the CRGB data where this controller's CRGB data begins, and the third argument is the number of leds for this controller object.

This method also takes a 2 to 3 template parameters for identifying the specific chipset and rgb ordering RGB ordering, and SPI data rate

Parameters
database pointer to an array of CRGB data structures
nLedsOrOffsetnumber of leds (3 argument version) or offset into the data array
nLedsIfOffsetnumber of leds (4 argument version)
Template Parameters
CHIPSETthe chipset/port type (required)
NUM_LANEShow many parallel lanes of output to write
RGB_ORDERthe rgb ordering for the leds (e.g. what order red, green, and blue data is written out in)
Returns
a reference to the added controller
template<EBlockChipsets CHIPSET, int NUM_LANES, EOrder RGB_ORDER>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a block based parallel output CLEDController instance to the world.
 
template<EBlockChipsets CHIPSET, int NUM_LANES>
static CLEDControlleraddLeds (struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
 Add a block based parallel output CLEDController instance to the world.
 

Constructor & Destructor Documentation

◆ CFastLED()

CFastLED::CFastLED ( )

Definition at line 33 of file FastLED.cpp.

Member Function Documentation

◆ addLeds() [1/15]

CLEDController & CFastLED::addLeds ( CLEDController pLed,
struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
static

Add a CLEDController instance to the world.

Exposed to the public to allow people to implement their own CLEDController objects or instances. There are two ways to call this method (as well as the other addLeds() variations). The first is with 3 arguments, in which case the arguments are the controller, a pointer to led data, and the number of leds used by this controller. The second is with 4 arguments, in which case the first two arguments are the same, the third argument is an offset into the CRGB data where this controller's CRGB data begins, and the fourth argument is the number of leds for this controller object.

Parameters
pLedthe led controller being added
database pointer to an array of CRGB data structures
nLedsOrOffsetnumber of leds (3 argument version) or offset into the data array
nLedsIfOffsetnumber of leds (4 argument version)
Returns
a reference to the added controller
Examples
ArrayOfLedArrays.ino, Blink.ino, ColorPalette.ino, ColorTemperature.ino, Cylon.ino, DemoReel100.ino, Fire2012.ino, Fire2012WithPalette.ino, FirstLight.ino, MirroringSample.ino, MultiArrays.ino, MultipleStripsInOneArray.ino, Noise.ino, NoisePlayground.ino, NoisePlusPalette.ino, OctoWS2811Demo.ino, PJRCSpectrumAnalyzer.ino, Pacifica.ino, ParallelOutputDemo.ino, Pride2015.ino, RGBSetDemo.ino, SmartMatrix.ino, TwinkleFox.ino, and XYMatrix.ino.

Definition at line 42 of file FastLED.cpp.

◆ addLeds() [2/15]

template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER, uint32_t SPI_DATA_RATE>
CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inline

Add an SPI based CLEDController instance to the world.

Definition at line 267 of file FastLED.h.

◆ addLeds() [3/15]

template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add an SPI based CLEDController instance to the world.

Definition at line 282 of file FastLED.h.

◆ addLeds() [4/15]

template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add an SPI based CLEDController instance to the world.

Definition at line 297 of file FastLED.h.

◆ addLeds() [5/15]

template<template< uint8_t DATA_PIN, EOrder RGB_ORDER > class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a clockless based CLEDController instance to the world.

Definition at line 351 of file FastLED.h.

◆ addLeds() [6/15]

template<template< uint8_t DATA_PIN, EOrder RGB_ORDER > class CHIPSET, uint8_t DATA_PIN>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a clockless based CLEDController instance to the world.

Definition at line 358 of file FastLED.h.

◆ addLeds() [7/15]

template<template< uint8_t DATA_PIN > class CHIPSET, uint8_t DATA_PIN>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a clockless based CLEDController instance to the world.

Definition at line 365 of file FastLED.h.

◆ addLeds() [8/15]

template<template< EOrder RGB_ORDER > class CHIPSET, EOrder RGB_ORDER>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a 3rd party library based CLEDController instance to the world.

Definition at line 413 of file FastLED.h.

◆ addLeds() [9/15]

template<template< EOrder RGB_ORDER > class CHIPSET>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a 3rd party library based CLEDController instance to the world.

Definition at line 420 of file FastLED.h.

◆ addLeds() [10/15]

template<OWS2811 CHIPSET, EOrder RGB_ORDER>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a OCTOWS2811 based CLEDController instance to the world.

See also
https://www.pjrc.com/teensy/td_libs_OctoWS2811.html
https://github.com/PaulStoffregen/OctoWS2811

Definition at line 430 of file FastLED.h.

◆ addLeds() [11/15]

template<OWS2811 CHIPSET>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a OCTOWS2811 library based CLEDController instance to the world.

See also
https://www.pjrc.com/teensy/td_libs_OctoWS2811.html
https://github.com/PaulStoffregen/OctoWS2811

Definition at line 445 of file FastLED.h.

◆ addLeds() [12/15]

template<SWS2812 CHIPSET, int DATA_PIN, EOrder RGB_ORDER>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a WS2812Serial library based CLEDController instance to the world.

See also
https://www.pjrc.com/non-blocking-ws2812-led-library/
https://github.com/PaulStoffregen/WS2812Serial

Definition at line 457 of file FastLED.h.

◆ addLeds() [13/15]

template<ESM CHIPSET>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a SmartMatrix library based CLEDController instance to the world.

See also
https://github.com/pixelmatix/SmartMatrix

Definition at line 468 of file FastLED.h.

◆ addLeds() [14/15]

template<EBlockChipsets CHIPSET, int NUM_LANES, EOrder RGB_ORDER>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a block based parallel output CLEDController instance to the world.

Definition at line 503 of file FastLED.h.

◆ addLeds() [15/15]

template<EBlockChipsets CHIPSET, int NUM_LANES>
static CLEDController & CFastLED::addLeds ( struct CRGB data,
int  nLedsOrOffset,
int  nLedsIfOffset = 0 
)
inlinestatic

Add a block based parallel output CLEDController instance to the world.

Definition at line 545 of file FastLED.h.

◆ clear()

void CFastLED::clear ( bool  writeData = false)

Clear the leds, wiping the local array of data.

Optionally you can also send the cleared data to the LEDs.

Parameters
writeDatawhether or not to write out to the leds as well

Definition at line 117 of file FastLED.cpp.

◆ clearData()

void CFastLED::clearData ( )

Clear out the local data array.

Definition at line 124 of file FastLED.cpp.

◆ count()

int CFastLED::count ( )

Get how many controllers have been registered.

Returns
the number of controllers (strips) that have been added with addLeds()

Definition at line 75 of file FastLED.cpp.

◆ countFPS()

void CFastLED::countFPS ( int  nFrames = 25)

For debugging, this will keep track of time between calls to countFPS().

Every nFrames calls, it will update an internal counter for the current FPS.

Todo:
Make this a rolling counter
Parameters
nFrameshow many frames to time for determining FPS

Definition at line 221 of file FastLED.cpp.

◆ delay()

void CFastLED::delay ( unsigned long  ms)

Delay for the given number of milliseconds.

Provided to allow the library to be used on platforms that don't have a delay function (to allow code to be more portable).

Note
This will call show() constantly to drive the dithering engine (and will call show() at least once).
Parameters
msthe number of milliseconds to pause for
Examples
ColorPalette.ino, ColorTemperature.ino, DemoReel100.ino, Fire2012.ino, Fire2012WithPalette.ino, OctoWS2811Demo.ino, and RGBSetDemo.ino.

Definition at line 132 of file FastLED.cpp.

◆ getBrightness()

uint8_t CFastLED::getBrightness ( )
inline

Get the current global brightness setting.

Returns
the current global brightness value

Definition at line 557 of file FastLED.h.

◆ getFPS()

uint16_t CFastLED::getFPS ( )
inline

Get the number of frames/second being written out.

Returns
the most recently computed FPS value

Definition at line 630 of file FastLED.h.

◆ leds()

CRGB * CFastLED::leds ( )
inline

Get a pointer to led data for the first controller.

Returns
pointer to the CRGB buffer for the first controller

Definition at line 646 of file FastLED.h.

◆ operator[]()

CLEDController & CFastLED::operator[] ( int  x)

Get a reference to a registered controller.

Returns
a reference to the Nth controller

Definition at line 85 of file FastLED.cpp.

◆ setBrightness()

void CFastLED::setBrightness ( uint8_t  scale)
inline

Set the global brightness scaling.

Parameters
scalea 0-255 value for how much to scale all leds before writing them out
Examples
ColorPalette.ino, ColorTemperature.ino, Cylon.ino, DemoReel100.ino, Fire2012.ino, Fire2012WithPalette.ino, Noise.ino, NoisePlayground.ino, NoisePlusPalette.ino, OctoWS2811Demo.ino, Pride2015.ino, SmartMatrix.ino, and XYMatrix.ino.

Definition at line 553 of file FastLED.h.

◆ setCorrection()

void CFastLED::setCorrection ( const struct CRGB correction)

Set a global color correction.

Sets the color correction for all added led strips, overriding whatever previous color correction those controllers may have had.

Parameters
correctionA CRGB structure describin the color correction.

Definition at line 154 of file FastLED.cpp.

◆ setDither()

void CFastLED::setDither ( uint8_t  ditherMode = BINARY_DITHER)

Set the dithering mode.

Sets the dithering mode for all added led strips, overriding whatever previous dithering option those controllers may have had.

Parameters
ditherModewhat type of dithering to use, either BINARY_DITHER or DISABLE_DITHER

Definition at line 162 of file FastLED.cpp.

◆ setMaxPowerInMilliWatts()

void CFastLED::setMaxPowerInMilliWatts ( uint32_t  milliwatts)
inline

Set the maximum power to be used, given in milliwatts.

Parameters
milliwattsthe max power draw desired, in milliwatts

Definition at line 566 of file FastLED.h.

◆ setMaxPowerInVoltsAndMilliamps()

void CFastLED::setMaxPowerInVoltsAndMilliamps ( uint8_t  volts,
uint32_t  milliamps 
)
inline

Set the maximum power to be used, given in volts and milliamps.

Parameters
voltshow many volts the leds are being driven at (usually 5)
milliampsthe maximum milliamps of power draw you want
Examples
Pacifica.ino, and TwinkleFox.ino.

Definition at line 562 of file FastLED.h.

◆ setMaxRefreshRate()

void CFastLED::setMaxRefreshRate ( uint16_t  refresh,
bool  constrain = false 
)

Set the maximum refresh rate.

This is global for all leds. Attempts to call show() faster than this rate will simply wait.

Note
The refresh rate defaults to the slowest refresh rate of all the leds added through addLeds(). If you wish to set/override this rate, be sure to call setMaxRefreshRate() after adding all of your leds.
Parameters
refreshmaximum refresh rate in hz
constrainconstrain refresh rate to the slowest speed yet set

Definition at line 237 of file FastLED.cpp.

◆ setTemperature()

void CFastLED::setTemperature ( const struct CRGB temp)

Set a global color temperature.

Sets the color temperature for all added led strips, overriding whatever previous color temperature those controllers may have had.

Parameters
tempA CRGB structure describing the color temperature
Examples
ColorTemperature.ino.

Definition at line 146 of file FastLED.cpp.

◆ show() [1/2]

void CFastLED::show ( )
inline

Update all our controllers with the current led colors.

Definition at line 573 of file FastLED.h.

◆ show() [2/2]

void CFastLED::show ( uint8_t  scale)

◆ showColor() [1/2]

void CFastLED::showColor ( const struct CRGB color)
inline

Set all leds on all controllers to the given color.

Parameters
colorwhat color to set the leds to

Definition at line 590 of file FastLED.h.

◆ showColor() [2/2]

void CFastLED::showColor ( const struct CRGB color,
uint8_t  scale 
)

Set all leds on all controllers to the given color/scale.

Parameters
colorwhat color to set the leds to
scalewhat brightness scale to show at

Definition at line 97 of file FastLED.cpp.

◆ size()

int CFastLED::size ( )
inline

Get the number of leds in the first controller.

Returns
the number of LEDs in the first controller

Definition at line 642 of file FastLED.h.


The documentation for this class was generated from the following files: