abfall/src/ws2812.cpp

13 lines
430 B
C++
Raw Normal View History

2023-01-02 10:35:58 +01:00
#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); }