Skip to content

Commit cf0ef9c

Browse files
authored
Include urgbw_u32 function and document rgb vs rgbw (#452)
1 parent 3ad146a commit cf0ef9c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pio/ws2812/ws2812.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@
1212
#include "hardware/clocks.h"
1313
#include "ws2812.pio.h"
1414

15-
#define IS_RGBW true
15+
/**
16+
* NOTE:
17+
* Take into consideration if your WS2812 is a RGB or RGBW variant.
18+
*
19+
* If it is RGBW, you need to set IS_RGBW to true and provide 4 bytes per
20+
* pixel (Red, Green, Blue, White) and use urgbw_u32().
21+
*
22+
* If it is RGB, set IS_RGBW to false and provide 3 bytes per pixel (Red,
23+
* Green, Blue) and use urgb_u32().
24+
*
25+
* When RGBW is used with urgb_u32(), the White channel will be ignored (off).
26+
*
27+
*/
28+
#define IS_RGBW false
1629
#define NUM_PIXELS 150
1730

1831
#ifdef PICO_DEFAULT_WS2812_PIN
@@ -33,6 +46,14 @@ static inline uint32_t urgb_u32(uint8_t r, uint8_t g, uint8_t b) {
3346
(uint32_t) (b);
3447
}
3548

49+
static inline uint32_t urgbw_u32(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
50+
return
51+
((uint32_t) (r) << 8) |
52+
((uint32_t) (g) << 16) |
53+
((uint32_t) (w) << 24) |
54+
(uint32_t) (b);
55+
}
56+
3657
void pattern_snakes(uint len, uint t) {
3758
for (uint i = 0; i < len; ++i) {
3859
uint x = (i + (t >> 1)) % 64;

0 commit comments

Comments
 (0)