LED strip library for Plaquette.
PqLEDStripuses theFastLEDlibrary for LED control. It was initially developed withFastLED3.10.1.- Do not call
FastLED.show()as you might be used to!PlaquetteandPqLEDStripmanage the showing of LEDs automagically for you. - Do not to set the value of the LEDs every iteration of your update loop because you want your update loop to run as fast as possible and only update the LEDs about every 20 to 50 milliseconds. Use a
Plaquette field(eg.PivotField,TimeSliceField) or on an interval set with aPlaquetteMetronome. See best practices at the bottom of this document.
- Currently, only the WS281X type of strip is supported.
LEDStripWS281X<3, RGB, 16> myStrip
LEDStripWS281X<PIN, ORDER, COUNT>
| Parameter | Description |
|---|---|
PIN |
The microcontroller pin connected to the LED strip. |
ORDER |
The color order (e.g., GRB, RGB, etc.). |
COUNT |
The number of LEDs in the strip. |
No palette is set initially. Default fallback is grayscale gradient.
Creates a strip and sets a palette.
paletteis a FastLED palette of typeCRGBPalette16,CRGBPalette32,CRGBPalette256,TProgmemRGBPalette16,CHSVPalette16,CHSVPalette32orCHSVPalette256.blendis eitherLINEARBLEND,LINEARBLEND_NOWRAP, orNOBLEND.
Fills the entire strip using values from a Plaquette field, rendered with the current palette. See below on how to use with a TimeSliceField.
Manually set the color of an individual pixel.
Get the count of the pixels.
Set the strip brightness between 0.0 and 1.0.
Removes the currently assigned palette. Default fallback is grayscale gradient.
Set a palette.
paletteis a FastLED palette of typeCRGBPalette16,CRGBPalette32,CRGBPalette256,TProgmemRGBPalette16,CHSVPalette16,CHSVPalette32orCHSVPalette256.blendis eitherLINEARBLEND,LINEARBLEND_NOWRAP, orNOBLEND.
Usually, your update loop is running very fast (more than 1000 times per second). Now, a LED strip does not need to (and probably cannot) be updated so fast. So you must update the LED strip at a slower interval. Here are two techniques: one with a Plaquette Metronome and another with a Plaquette TimeSliceField.
In global space, declare a Metronome with a period of 50 milliseconds (for a refresh rate of 20 Hz):
Metronome stripUpdateMetronome{0.05};In your update loop, check if the Metronome has triggered and update the strip:
if (stripUpdateMetronome)
{
// Update the strip here
}loop(): [x][x][x][x][x][x][x][x][x][x]...
Check if metronome ticked
Time (ms): 0 50 100 150
Metronome: [✓] [✓] [✓] [✓]
^ ^ ^ ^
LED update LED update LED update LED update
A TimeSliceField allows you to establish a "time bridge" between the fast loop() and the slow update speed of the LED strip.
A TimeSliceField not only collects data over time, but also spreads the processing across multiple loop() iterations.
This avoids a performance spike from computing all samples in a single burst right before updating the strip. Instead, a small amount of work is done each loop, keeping performance smooth and consistent.
In global space, declare a TimeSliceField that contains 16 samples (the number of samples does not have to match the number of pixels) that will be taken over a period of 50 milliseconds (for a refresh rate of 20 Hz):
TimeSliceField<16> timeSliceField{0.05}; // 16 samples over a period of 50 msIn your loop(), feed any float-based data source (such as a Wave, Ramp, or analogIn) into the TimeSliceField. Then, check if the TimeSliceField has triggered (i.e., its time period has elapsed), and instruct the strip to draw using the collected samples:
sineWave >> timeSliceField;
if (timeSliceField.updated()) // 50 milliseconds have passed
{
strip.draw(timeSliceField); // Draw the 16 samples onto the strip using the current palette
}The TimeSliceField collects 16 samples over a 50 ms period (e.g., from a wave or analog input). After 50 ms, it triggers once and uses the collected samples to update the LED strip.
To capture a full cycle of a waveform (like a Wave), the waveform's period should match the TimeSliceField's period — in this case, 50 ms.
loop(): [ x ][ x ][ x ][ x ][ x ][ x ][ x ][ x ][ x ][ x ]...
Time (ms): 50 ...
SineWave: [0.3][0.2][0.1][0.0][0.1][0.2][0.3][0.4][0.5][0.6]...
|
TimeSliceField triggers here (50 ms have passed)
LED draw: Draw the collected data to the strip
The collected data is mapped to each pixel in order (the number of samples does not have to match the number of puxels) . The values are mapped to CRGB colors through a palette:
Pixel index : 0 1 2 3 4 5 6 7 8 9 ...
Collected data : [0.3][0.2][0.1][0.0][0.1][0.2][0.3][0.4][0.5][0.6]...
Palette lookup: CRGB CRGB CRGB CRGB CRGB CRGB CRGB CRGB CRGB CRGB ...