Police Strobe (Seg Line or Seg) - AlbertGBarber/PixelSpork GitHub Wiki
See the Documentation Guide for help understanding each page section.
Effect Sample (see here for sample info) |
An effect to strobe a strip to mimic police lights, with some additional options. A strobe is a rapid blinking of light. An alternative to the general Strobe (Seg Line) effect.
The base constructor takes two colors, but you can optionally pass in a pattern and palette, or just a palette alone.
There are a few options for randomly choosing what pattern of strobes is used, how the strobe colors are chosen, when/if the strobing pauses, and more.
The effect is adapted to work on segment lines or whole segments for 2D use (see segMode
), each segment/segment line will be a solid color when pulsing.
Supports color modes for both the main and background colors.
You can change the effect's settings freely on the fly.
- 0 -- Pulse half the segment set in each color (alternating halves and colors), then pulse each color on the whole segment set (modes 1 and 2 combined).
- 1 -- Pulse half the segment set in each color (alternating halves and colors).
- 2 -- Pulse the whole segment set in each color (alternating colors).
The strobe of each color will continue for a set number of on/off pulses (creating the strobe effect).
If using a pattern, all the pattern indexes will be cycled through before resetting. For pulseMode
, this means all the colors will be strobe'd in halves, then strobe'd on the full strip.
segMode
controls if the strobe will pulse using segment lines or whole segments. True does whole segments.
Sets how colors are chosen from the pattern/palette:
- 0 -- Colors will be chosen from the palette in order (not random).
- 1 -- Colors will be chosen completely at random (not using the palette).
- 2 -- Colors will be chosen randomly from the pattern, but the same color will not be chosen in twice.
After a strobe cycle is finished (strobe'd all colors) there is a user configurable pause time between cycles, after which, the strobe will restart. The pause can alternatively be configured to occur after every set of pulses, controlled by pauseEvery
. The length of the pause is controlled by pauseTime
(ms).
By default the background is filled after every pulse and during a pause. Both these can be disabled with the fillBg
and fillBGOnPause
flags respectively. This causes the last pulse color to persist after the pulse set is done.
When using the dual color constructor option, the colors will be formed into a pattern and palette within the effect. They are stored as paletteTemp
and patternTemp
. To change the colors, you must set them in paletteTemp
, ie paletteUtilsPS::setColor(<your strobe effect name>->paletteTemp, <your new color>, color index (0 or 1))
.
PoliceStrobeSLSeg policeStrobe(mainSegments, CRGB::Red, CRGB::Blue, 0, 1, 0, 1, false, 200);
/* Does a classic police set of lights
Blinks each half of the strip for one pulse between red and blue, with 200ms per pulse.
The background color is blank
There is no pause between the cycles
The strobes will be along segment lines (segMode is false) */
PoliceStrobeSLSeg policeStrobe(mainSegments, cybPnkPal_PS, CRGB:Purple, 4, 500, 0, true, 50);
/* A more dynamic strobe
Will strobe all the colors in the cybPnkPal_PS palette, with 4 pulses at 50ms each.
The background color is purple
Strobe mode 0 is used, so the strobe will alternate between strobing halves of the strip and the whole strip
There is a 500ms pause between cycles
The strobes will be along whole segments (segMode is true)*/
uint8_t pattern_arr = {0, 2, 1};
patternPS pattern = {pattern_arr, SIZE(pattern_arr), SIZE(pattern_arr)};
PoliceStrobeSLSeg policeStrobe(mainSegments, pattern, cybPnkPal_PS, CRGB:green, 6, 300, 0, false, 50);
/* Will strobe colors from the palette based on the pattern (ie colors 0, 2, and 1 in order), with 6 pulses at 50ms each
The background color is green
strobe mode 0 is used, so the strobe will alternate between strobing halves of the strip and the whole strip
There is a 300ms pause between cycles
The strobes will be along segment lines (segMode is false)*/
//Constructor for a traditional two color strobe
PoliceStrobeSLSeg(SegmentSetPS &SegSet, CRGB ColorOne, CRGB ColorTwo, CRGB BgColor, uint8_t NumPulses,
uint16_t PauseTime, uint8_t PulseMode, bool SegMode, uint16_t Rate);
//Constructor using both pattern and palette
PoliceStrobeSLSeg(SegmentSetPS &SegSet, patternPS &Pattern, palettePS &Palette, CRGB BgColor, uint8_t NumPulses,
uint16_t PauseTime, uint8_t PulseMode, bool SegMode, uint16_t Rate);
//Constructor for using palette as the pattern
PoliceStrobeSLSeg(SegmentSetPS &SegSet, palettePS &Palette, CRGB BgColor, uint8_t NumPulses, uint16_t PauseTime,
uint8_t PulseMode, bool SegMode, 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. -
patternPS* pattern (optional, see constructors) -- The color pattern the effect will use. See patterns. It is a pointer. See common vars
pattern
entry for more details. -
CRGB colorOne (optional, see constructors) -- First color for a dual color strobe. The color will be placed into the effect's local palette,
paletteTemp
for use. -
CRGB colorTwo (optional, see constructors) -- Second color for a dual color strobe. The color will be placed into the effect's local palette,
paletteTemp
for use. -
CRGB* bgColor -- The color between strobe pulses. Is a pointer, allowing you to bind it to an external color. By default it's bound the effect's local,
bgColorOrig
color. See common varsbgColor
entry for more details. -
uint8_t numPulses -- The number of pulses per strobe.
-
uint16_t pauseTime -- The pause time between strobe cycles. (See pause notes in intro).
-
uint8_t pulseMode -- The type of strobe that will be used (see pulse modes notes in intro).
-
bool segMode -- Controls if the strobe will pulse using segment lines or whole segments. True does whole segments.
-
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.
-
uint8_t colorMode (default 0) -- The colorMode use for the effect, also see common vars
colorMode
entry for more details. -
uint8_t bgColorMode (default 0) -- The colorMode used for the background pixels, also see common vars
colorMode
entry for more details. -
bool pauseEvery (default false) -- If true, the effect will pause after every set of pulses, rather than after a whole strobe cycle (strobing all colors in the pattern/palette).
-
bool fillBg (default true) -- Flag to fill the background after each set of pulses. (See background notes in intro)
-
bool fillBGOnPause (default true) -- Flag to fill the background during each pause. (See background notes in intro)
-
uint8_t randMode (default 0) -- Sets how colors will be chosen, (see randMode notes in intro).
-
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 setPaletteAsPattern();
Sets the effect pattern to match the current effect palette. See Common Functions for more.
-
void reset();
Restarts the effect from its initial state.
-
void update();
Updates the effect.
- uint16_t colorNum -- The pattern index of the color currently being pulsed (resets once every step in the pattern has been pulsed).
- bool pause -- Set true if a pause is active.