Skip to content

Commit

Permalink
Include urgbw_u32 function and document rgb vs rgbw (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarranz97 authored May 1, 2024
1 parent 3ad146a commit cf0ef9c
Showing 1 changed file with 22 additions and 1 deletion.
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

0 comments on commit cf0ef9c

Please sign in to comment.