ws2812 library  v0.85
Supports ws2812 and ws2812b
Data Structures | Macros | Typedefs | Functions
ws2812.h File Reference

Driver for WS2812 and WS2812B RGB LEDs. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ws2812_t

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

Typedefs

typedef ws2812_t ws2812

Functions

ws2812_tws2812_open (void)
 Open a driver for WS2812 chips.
ws2812_tws2812b_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

Function Documentation

void ws2812_close ( ws2812_t driver)

Close a WS2812 or WS2812B driver.

Parameters
driverPointer to the driver structure
ws2812_t* ws2812_open ( void  )

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
driverPointer to the driver structure
pinPin connected to the first LED
colorsArray of colors, one for each LED in the chain
countNumber of LEDs in the chain
int ws2812_start ( ws2812_t driver)

Start a driver for WS2812 chips.

Parameters
driverPointer to a driver structure
Returns
Driver COG number or -1 on failure
void ws2812_stop ( ws2812_t driver)

Shut down the COG running a driver.

Parameters
driverPointer 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
posPosition 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
posPosition in the color spectrum where 0 is on the red end and 255 is on the blue end
brightnessThe brightness of the generated color where 0 is off and 255 is full
Returns
Color at the specified position
ws2812_t* ws2812b_open ( void  )

Open a driver for WS2812B chips.

Returns
A pointer to the driver structure or NULL on failure
int ws2812b_start ( ws2812_t driver)

Start a driver for WS2812B chips.

Parameters
driverPointer 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
usresetReset timing (us)
ns0h0-bit high timing (ns)
ns0l0-bit low timing (ns)
ns1h1-bit high timing (ns)
ns1l1-bit low timing (ns)
typecolor format (either TYPE_RGB or TYPE_GRB)
Returns
Driver COG number or -1 on failure