abfall/src/ws2812.cpp

20 lines
611 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);
}
2023-01-03 12:04:30 +01:00
void WS2812::switchColor(Color color) { putPixel(static_cast<uint32_t>(color)); }
void WS2812::blinkReady() {
for (int i = 0; i < 2; i++) {
switchColor(Color::WHITE);
sleep_ms(250);
switchColor(Color::OFF);
sleep_ms(250);
}
2023-01-02 10:35:58 +01:00
}
void WS2812::putPixel(uint32_t pixel_grb) { pio_sm_put_blocking(m_pio, m_sm, pixel_grb << 8u); }