Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include urgbw_u32 function and document rgb vs rgbw #452

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pio/ws2812/ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@
#include "hardware/clocks.h"
#include "ws2812.pio.h"

#define IS_RGBW true
/**
* NOTE:
* Take into consideration if your WS2812 is a RGB or RGBW variant.
*
* If it is RGBW, you need to set IS_RGBW to true and provide 4 bytes per
* pixel (Red, Green, Blue, White) and use urgbw_u32().
*
* If it is RGB, set IS_RGBW to false and provide 3 bytes per pixel (Red,
* Green, Blue) and use urgb_u32().
*
* When RGBW is used with urgb_u32(), the White channel will be ignored (off).
*
*/
#define IS_RGBW false
#define NUM_PIXELS 150

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

static inline uint32_t urgbw_u32(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
return
((uint32_t) (r) << 8) |
((uint32_t) (g) << 16) |
((uint32_t) (w) << 24) |
(uint32_t) (b);
}

void pattern_snakes(uint len, uint t) {
for (uint i = 0; i < len; ++i) {
uint x = (i + (t >> 1)) % 64;
Expand Down