Driver for WS2812 and WS2812B RGB LEDs.
More...
#include <stdint.h>
Go to the source code of this file.
Macros |
#define | TYPE_RGB 0 |
#define | TYPE_GRB 1 |
#define | COLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b)) |
#define | SCALE(x, l) ((x) * (l) / 255) |
#define | COLORX(r, g, b, l) ((SCALE(r, l) << 16) | (SCALE(g, l) << 8) | SCALE(b, l)) |
#define | COLOR_BLACK 0x000000 |
#define | COLOR_RED 0xFF0000 |
#define | COLOR_GREEN 0x00FF00 |
#define | COLOR_BLUE 0x0000FF |
#define | COLOR_WHITE 0xFFFFFF |
#define | COLOR_CYAN 0x00FFFF |
#define | COLOR_MAGENTA 0xFF00FF |
#define | COLOR_YELLOW 0xFFFF00 |
#define | COLOR_CHARTREUSE 0x7FFF00 |
#define | COLOR_ORANGE 0xFF6000 |
#define | COLOR_AQUAMARINE 0x7FFFD4 |
#define | COLOR_PINK 0xFF5F5F |
#define | COLOR_TURQUOISE 0x3FE0C0 |
#define | COLOR_REALWHITE 0xC8FFFF |
#define | COLOR_INDIGO 0x3F007F |
#define | COLOR_VIOLET 0xBF7FBF |
#define | COLOR_MAROON 0x320010 |
#define | COLOR_BROWN 0x0E0600 |
#define | COLOR_CRIMSON 0xDC283C |
#define | COLOR_PURPLE 0x8C00FF |
Functions |
ws2812_t * | ws2812_open (void) |
| Open a driver for WS2812 chips.
|
ws2812_t * | ws2812b_open (void) |
| Open a driver for WS2812B chips.
|
void | ws2812_close (ws2812_t *driver) |
| Close a WS2812 or WS2812B driver.
|
int | ws2812_start (ws2812_t *driver) |
| Start a driver for WS2812 chips.
|
int | ws2812b_start (ws2812_t *driver) |
| Start a driver for WS2812B chips.
|
int | ws_start (ws2812_t *driver, int usreset, int ns0h, int ns0l, int ns1h, int ns1l, int type) |
| Load a COG with a driver using custom parameters.
|
void | ws2812_stop (ws2812_t *driver) |
| Shut down the COG running a driver.
|
void | ws2812_set (ws2812_t *driver, int pin, uint32_t *colors, int count) |
| Set color pattern on a chain of LEDs.
|
uint32_t | ws2812_wheel (int pos) |
| Create color from a 0 to 255 position input.
|
uint32_t | ws2812_wheel_dim (int pos, int brightness) |
| Create color from a 0 to 255 position input.
|
Detailed Description
Driver for WS2812 and WS2812B RGB LEDs.
- Author
- Parallax Inc.
- Version
- 0.85
- Copyright
- Copyright (c) Parallax Inc. 2014, All Rights MIT Licensed.
Function Documentation
Close a WS2812 or WS2812B driver.
- Parameters
-
driver | Pointer to the driver structure |
Open a driver for WS2812 chips.
- Returns
- A pointer to the driver structure or NULL on failure
void ws2812_set |
( |
ws2812_t * |
driver, |
|
|
int |
pin, |
|
|
uint32_t * |
colors, |
|
|
int |
count |
|
) |
| |
Set color pattern on a chain of LEDs.
- Parameters
-
driver | Pointer to the driver structure |
pin | Pin connected to the first LED |
colors | Array of colors, one for each LED in the chain |
count | Number of LEDs in the chain |
Start a driver for WS2812 chips.
- Parameters
-
driver | Pointer to a driver structure |
- Returns
- Driver COG number or -1 on failure
Shut down the COG running a driver.
- Parameters
-
driver | Pointer to the driver structure |
uint32_t ws2812_wheel |
( |
int |
pos | ) |
|
Create color from a 0 to 255 position input.
Colors transition red to green to blue.
- Parameters
-
pos | Position in the color spectrum where 0 is on the red end and 255 is on the blue end |
- Returns
- Color at the specified position
uint32_t ws2812_wheel_dim |
( |
int |
pos, |
|
|
int |
brightness |
|
) |
| |
Create color from a 0 to 255 position input.
Colors transition red to green to blue.
- Parameters
-
pos | Position in the color spectrum where 0 is on the red end and 255 is on the blue end |
brightness | The brightness of the generated color where 0 is off and 255 is full |
- Returns
- Color at the specified position
Open a driver for WS2812B chips.
- Returns
- A pointer to the driver structure or NULL on failure
Start a driver for WS2812B chips.
- Parameters
-
driver | Pointer to a driver structure |
- Returns
- Driver COG number or -1 on failure
int ws_start |
( |
ws2812_t * |
driver, |
|
|
int |
usreset, |
|
|
int |
ns0h, |
|
|
int |
ns0l, |
|
|
int |
ns1h, |
|
|
int |
ns1l, |
|
|
int |
type |
|
) |
| |
Load a COG with a driver using custom parameters.
- Parameters
-
usreset | Reset timing (us) |
ns0h | 0-bit high timing (ns) |
ns0l | 0-bit low timing (ns) |
ns1h | 1-bit high timing (ns) |
ns1l | 1-bit low timing (ns) |
type | color format (either TYPE_RGB or TYPE_GRB) |
- Returns
- Driver COG number or -1 on failure