This repository contains pattern functions for setting colors on a line of RGB leds (e.g. WS2812, WS2813). These patterns are used by iot_rgb_controller.
No requirements.
See iot_rgb_controller.
In esp-idf environment rgb_led_line_patterns
should be placed in components directory.
The following pictures show patterns examples on led line.
The repository contains the following patterns:
- Standby - pattern is active when controller is in state OFF, 2 diodes move from ends to the center, brightness = 1, refresh period 1 s
- running_point - one point moves from the beginning to the end
- rgb_palette - all diodes have the same color that changes smoothly in order: red -> green -> blue -> red and so on
- tetris - the line is filled with points running from one end to the other, after filling, the removal of points begins, after such a cycle the color changes
- static - static color, no changes
- floating_ends - colors smoothly change from one end to the other
- new_year - something like fireworks
- christmas - something for christmas time
Each pattern is described by parameters contained in the structure pattParam_t
, these are:
dt
- refresh period in milisecondsfreq_max
andfreq_min
- maximum and minimum refresh frequency in Hzspeed
- percentage of maximum refresh speed, 0 .. 100color_1
- RGB color used by some patternsparam_1
,param_2
,param_3
- pattern parameters, used differently in different patternsbrightness
- percentage of full brightness, 0 .. 100on_diodes
- number of controlled diodesold_diodes
- used when checking if the number of diodes has changedrgb_color_buff
- buffer for RGB values for each diode in the line
Initialization is done in
void initRgbPatterns(int32_t *diodes,
uint8_t *rgb_buff,
pattParam_t **paramTab,
pRefreshFun *funTab){
Parameters
diodes
: pointer to variable with diodes numberrgb_buff
: buffer for RGB values, must havediodes
* 3 bytesparamTab
: table for pattern parametersfunTab
: from this table pattern functions are called by the controller thread
Pattern function is called every specified period of time (set in pattParam_t param.dt
) by the controller thread. The function calculates new RGB values for each diode based on the parameters defined for the given pattern and saves them in the rgb_color_buff
buffer.
Changing the RGB values to values that the diode understands and sending these values to the diodes takes place in the controller thread (see function refreshRgb
in thing_ws2812_controller).
The SPI interface is used to send data to the led line
The source is available from GitHub.
The code in this project is licensed under the MIT license - LICENSE for details.
- Krzysztof Zurek - kz