Plasma (Seg Line) - AlbertGBarber/PixelSpork GitHub Wiki
See the Documentation Guide for help understanding each page section.
Effect Sample (see here for sample info) |
![]() |
An effect based on the PlasmaSL.ino code by Andrew Tuline found here. Uses two moving waves to blend a set of palette colors together.
The effect is controlled by frequency and phase values for each of the two waves. These control where the waves meet and how the colors blend. When creating the effect, you have the option to set them to default values (from Andrew's original effect), or have them set randomly. The phases can be configured to drift randomly over time, which helps prevent the effect from repeating as much. (More on that below)
There are a few issues with this effect at lower brightness (<50), where the LEDs seem to blink. The brightness is controlled by a wave. The blinking happens when the wave frequency is too low. You can adjust the frequency and the maximum dimming using briFreq
and briRange
. I've defaulted these to a pair of values that seem to work okay at lower brightness, but you may need to adjust them. Andrew Tuline's defaults are 9 and 96 respectively.
You can change all of the effect's settings on the fly, but they will probably cause a "jump" in the effect.
The effect is adapted to work on segment lines for 2D use.
Finally, I note that I've never been completely happy with how this effect turned out, it just doesn't seem to have enough variation for me (maybe I've implemented it wrong?). Probably looks better on a 1D strip than in 2D. For alternative, but more computationally intensive effects, check out the "noise" series.
To produce a more varied effect you can opt to have the wave phases shift with time by setting randomize
= true.
-
phase1Base
andphase1Range
control the shifting of wave 1. -
phase2Base
andphase2Range
control the shifting of wave 2. -
phase1Base
is the minimum phase value, whilephase1Base + phase1Range
is the maximum. (Same for the wave 2 settings)
To randomize the phase, a target phase value will be set by adding the "phase base" to a randomly picked value up to the "phase range" ie, phase1Base + random(phase1Range)
. With a target set, the phase will move towards the target value by one step each update cycle. This avoids color "jumps" by keeping the transition gradual. Once the target is reached, a new target value is picked and the process begins again.
The default is to use the full range of 255 to vary the phases where:
- Both phase bases are set to a default value of 0.
- Both phase ranges are set to a default value of 255.
You can adjust either of these on the fly. If you don't want any shifting, simply set randomize = false. However, note that the to phases will stay at what ever value they currently have.
!!Do NOT set either phases directly after turning on randomize. If you do, be sure to adjust phase1 == targetPhase1
and phase2 == targetPhase2
.
There are also an additional pair of phases that always vary using a sin() function. You don't need to touch these, but know that their frequencies are randomly adjusted by a small amount on startup if randomize
is true. Giving them a slight variation helps produce a more unique effect.
If randomize
is true in the constructor, the frequencies for the waves will be randomized once (between 10 and 30) but they will not be shifted over time because it causes jumps in the effect. You can randomize the frequencies at any time by calling randomizeFreq(freqMin, freqMax)
with a min and max value.
If you choose not to randomize, the freqs will be set to defaults (matching original values from Andrew Tuline):
-
freq1
= 23. -
freq2
= 15.
PlasmaSL plasma(mainSegments, 3, 50, true, 80);
/* Will do the effect using 3 randomly chosen colors
with 50 blend steps between each color
the freqs and phases will be randomized (randomize is true)
The effect updates every 80ms */
PlasmaSL plasma(mainSegments, cybPnkPal_PS, 80, false, 40);
/* Will do a the effect using colors from the cybPnkPal_PS palette
with 80 blend steps between each color
and the freqs and phases are not randomized
(set to defaults, and will not shift over time)
The effect updates every 40ms */
//Constructor for effect with palette
PlasmaSL(SegmentSetPS &SegSet, palettePS &Palette, uint16_t BlendSteps, bool Randomize, uint16_t Rate);
//Constructor for effect with randomly chosen palette
PlasmaSL(SegmentSetPS &SegSet, uint8_t numColors, uint16_t BlendSteps, bool Randomize, uint16_t Rate);
-
SegmentSetPS* segSet -- The Segment Set the effect will draw on. See common vars
segSet
entry for more details. -
palettePS* palette (optional, see constructors) -- The set of colors the effect will use. See palettes. It is a pointer. See common vars
palette
entry for more details. -
uint8_t numColors (optional, see constructors) -- The number of randomly chosen colors for the effect. The colors will be placed into the effect's local palette,
paletteTemp
for use. -
uint16_t blendSteps -- Sets how many steps are used to blend between each color, changing how fast the colors blend. Between 20 - 100 looks good.
-
bool randomize -- If true, will randomize and shift the phase values over time (and also randomize the freqs once). (See notes in Intro above)
-
uint16_t* rate -- Update rate (ms). Is a pointer, allowing you to bind it to an external variable. By default it's bound the effect's local variable,
rateOrig
. See common varsrate
entry for more.
freq1 (default 23) -- The first frequency used in the wave calculation freq2 (default 15) -- The second frequency used in the wave calculation pAdj1 (default 0) -- Random factor for the phaseWave1 calculation pAdj2 (default 0) -- Random factor for the phaseWave2 calculation phase1Base (default 0) -- The minimum value of phase1 (see Shifting Phases with Time above) phase2Base (default 0) -- The minimum value of phase2 (see Shifting Phases with Time above) phase1Range (default 255) -- The range for the variation of wave 1 phase (see Shifting Phases with Time above) phase1Range (default 255) -- The range for the variation of wave 2 phase (see Shifting Phases with Time above) briFreq (default 15) -- The frequency at which the brightness changes briRange (default 75) -- The maximum reduction in brightness (min is 0)
-
uint8_t freq1 (default 23) -- The frequency used for the first wave.
-
uint8_t freq2 (default 15) -- The frequency used for the second wave.
-
uint8_t pAdj1 (default 0) -- Random factor for the wave 1 phase calculation (randomized during construction if randomize is true).
-
uint8_t pAdj2 (default 255) -- Random factor for the wave 2 phase calculation (randomized during construction if randomize is true).
-
uint8_t phase1Base (default 0) -- The minimum value of the wave 1 phase (see Shifting Phases with Time above).
-
uint8_t phase2Base (default 0) -- The minimum value of the wave 2 phase (see Shifting Phases with Time above).
-
uint8_t phase1Range (default 255) -- The range for the variation of wave 1 phase (see Shifting Phases with Time above).
-
uint8_t phase2Range (default 255) -- The range for the variation of wave 2 phase (see Shifting Phases with Time above).
-
uint8_t briFreq (default 15) -- The frequency at which the brightness changes.
-
uint8_t briRange (default 75) -- The maximum reduction in brightness (min is 0).
-
bool showNow (default true) -- Controls if the effect "draws" during each update cycle by calling
FastLED.show()
. Common to all effects. See common varsshowNow
entry for more details.
-
void randomizeFreq( uint8_t freqMin, uint8_t freqMax );
Sets both wave frequencies to be a random value between the passed in min and max. (Causes a jump in the effect).
-
void update();
Updates the effect.