13 lines
430 B
C++
13 lines
430 B
C++
|
#include "ws2812.h"
|
||
|
|
||
|
WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_sm{sm} {
|
||
|
uint offset = pio_add_program(m_pio, &ws2812_program);
|
||
|
ws2812_program_init(m_pio, m_sm, offset, gpio, 800000, true);
|
||
|
switchColor(Color::OFF);
|
||
|
}
|
||
|
|
||
|
void WS2812::switchColor(Color color) {
|
||
|
putPixel(static_cast<uint32_t>(color));
|
||
|
}
|
||
|
|
||
|
void WS2812::putPixel(uint32_t pixel_grb) { pio_sm_put_blocking(m_pio, m_sm, pixel_grb << 8u); }
|