/rgb-led-line-patterns

Patterns for RGB led lines (e.g. WS2812, WS2813).

Primary LanguageCMIT LicenseMIT

RGB patterns for RGB led lines

Introduction

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.

Dependencies

No requirements.

Example

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.

photo_1 photo_2

photo_3

Features

The repository contains the following patterns:

  1. Standby - pattern is active when controller is in state OFF, 2 diodes move from ends to the center, brightness = 1, refresh period 1 s
  2. running_point - one point moves from the beginning to the end
  3. rgb_palette - all diodes have the same color that changes smoothly in order: red -> green -> blue -> red and so on
  4. 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
  5. static - static color, no changes
  6. floating_ends - colors smoothly change from one end to the other
  7. new_year - something like fireworks
  8. christmas - something for christmas time

Documentation

Pattern parameters

Each pattern is described by parameters contained in the structure pattParam_t, these are:

  • dt - refresh period in miliseconds
  • freq_max and freq_min - maximum and minimum refresh frequency in Hz
  • speed - percentage of maximum refresh speed, 0 .. 100
  • color_1 - RGB color used by some patterns
  • param_1, param_2, param_3 - pattern parameters, used differently in different patterns
  • brightness - percentage of full brightness, 0 .. 100
  • on_diodes - number of controlled diodes
  • old_diodes - used when checking if the number of diodes has changed
  • rgb_color_buff - buffer for RGB values for each diode in the line

Initialization

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 number
  • rgb_buff: buffer for RGB values, must have diodes * 3 bytes
  • paramTab: table for pattern parameters
  • funTab: from this table pattern functions are called by the controller thread

How it runs

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

Source Code

The source is available from GitHub.

License

The code in this project is licensed under the MIT license - LICENSE for details.

Authors

  • Krzysztof Zurek - kz