LED Pattern Commands
This page describes the pattern commands that are implemented in the firmware.
range
range (LedRange) - set range of pixels to a color.
This command is used to set a range of one or more pixels to a fixed color. The format is:
$range,<start-pixel>,<num-pixels>,<color1>,<color2>,<color3>
- start-pixel - the starting pixel number (0-origin) of the range
- num-pixels - the number of pixels to include in the range
- color1/2/3 - the value of each of the three color fields, 0-255
The color format is usually RGB or GRB. You can experiment setting each in turn to see how they are mapped with your hardware.
The main purpose of this command is for prototyping and debugging. Once a pattern is defined, it should be implemented as a new command class in this code.
Example
Set pixels 10-19 to blue at half intensity:
$range,10,10,0,0,128
The range
command does not have any configuration settings.
meter
meter (LedMeter) - show a level meter over a range of pixels, with gradient.
This command is used to show a "level meter" or "progress meter" over a range of pixels in the LED strip. The command has a "percent" parameter which lights up the corresponding number of pixels over a defined range. There can also be a color gradient. For example all green at the low end and progressively getting redder as the value increases.
The command format is:
$meter,<percent>
where percent
is 0-100.
Prior to using, the meter
command must be configured to specify the pixels
that are part of the meter display, and the color gradient to use. The config
command has the following format:
$config,meter,<start-pxel>,<stop-pixel>,<r0>,<rN>,<g0>,<gN>,<b0>,<bN>
- start-pixel - the beginning pixel of the meter display
- stop-pixel - the ending pixel of the meter display, inclusive
- r0 - the beginning value for "red"
- rN - the ending value for "red"
- g0/gN - begin/end value for "green"
- b0/bN - begin/end value for "blue"
NOTES:
- The colors listed above assume RGB format. Swap values if your order is GRB.
- The start pixel and stop pixel can be in either increasing or decreasing order
- the config only need to be done once for a given powered session. If the controller board is repowered or reset, the config command must be sent again
Example
A meter function is defined to go from pixel 0 to pixel 19 (20 pixels), in the increasing direction. It should be fully red at the low end, and fully green at the full end. The colors in mid-scale will be interpolated between the two ends.
$config,meter,0,19,255,0,0,255,0,0
To set the meter display to 50%, half the pixels (10) will be lit ranging from red at the lowest end to yellow-ish in the middle:
$meter,50
There is one meter command built-in, named meter
. Additional meter instances
can be added using the add
command.
$add,meter2,LedMeter
Will create a second meter function, named meter2
. It can be configured for
a different set of pixels and different gradient so you can have two different
meter displays on a single LED strip.
random
random - random pattern commands.
LedRandom
Bases: CommandTemplate
Configurable random pattern generator.
This command generates a pattern similar to randomog. But it has configurable options. Originally, random colors were used for each pixel. But that ends up with most pixels ahve all 3 of RGB turned on which ends up just making mostly pastels. This pattern generates random colors for each channel, but then randomly chooses only one or two of those channels to mix together (there is also a chance of all 3 channels but it is low probability). This results in much brighter colors and more bright reds, greens, and blues. It just looks more colorful.
At some period, a random spot on the LED strip is selected, and a random number of sequential pixels are lit, with a random color as described above. There is also some probability that pixels are set to dark.
The command itself takes no parameters:
$random
But it has a configuration:
$config,random,<dark-threshold>,<max-intensity>,<num-pixels>,<delayus>
- dark-threshold - a random value from 0-255 is compared to the dark threshold. If it is below the threshold then the color will be dark (off). For example, to make there be a 50% chance of dark pixels, use a value of 128.
- max-intensity - this is a mask that limits the value of a color channel. It is ANDed with the random color. It should probably be a power of 2, minus 1, or you will get strange results. For example, 127, 63, 31, etc. If you select 127 (the default) then that will force the upper bit to always be off, which limits the max intensity for any channel to 127. The reason for doing this is to reduce the overall power consumed by the LED strip. If you want max intensity without any limit, then set this value to 255.
- num-pixels - this should 1 or more. It is the maximum number of consecutive pixels that will be lit up. The algorithm uses a random number between 1 and this value. The default is 5.
- delayus - the repeat period in microseconds. The lower the number, the faster the pattern updates. The default is 100000 which is 100 milliseconds.
Source code in ledstrip/ledrandom.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
LedRandomOG
Bases: CommandTemplate
Random pattern based on Bill's pattern 2.
This command lights one or more LEDs in the string at random locations and with random colors. It is based on Bill's original pattern 2 code. This command has no configuration and no parameters. It is just invoked by itself:
$randomog
Source code in ledstrip/ledrandom.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
stop
stop - stop running pattern with optional clear.
LedStop
Bases: CommandTemplate
Stop the running pattern with option to clear display.
This command will stop any running pattern. There is an optional parameter, which if '1', will also clear the diplay.
Examples
$stop
$stop,0
$stop,1
Source code in ledstrip/ledstop.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|