This should make using the WS2812 examples a bit easier. (#84)

* This should make using the WS2812 examples a bit easier.
Moved parameters to the top as defines:
- Number of LEDs in your NeoPixel/WS2812 strip/ring
- Flag if the LEDs are WRGB or not
Changed PIN to 2 as pin 0 is used for serial UART.
This commit is contained in:
Josef Wegner
2021-10-22 22:36:58 +02:00
committed by GitHub
parent ad51837566
commit 74aff26c75
2 changed files with 25 additions and 23 deletions

View File

@@ -12,6 +12,13 @@
#include "hardware/clocks.h"
#include "ws2812.pio.h"
#define IS_RGBW true
#define NUM_PIXELS 150
#ifndef PICO_DEFAULT_WS2812_PIN
#warning "no WS2812 default PIN defined for board, please check if pin 2 is okay"
#define PICO_DEFAULT_WS2812_PIN 2
#endif
static inline void put_pixel(uint32_t pixel_grb) {
pio_sm_put_blocking(pio0, 0, pixel_grb << 8u);
}
@@ -71,8 +78,6 @@ const struct {
{pattern_greys, "Greys"},
};
const int PIN_TX = 0;
int main() {
//set_sys_clock_48();
stdio_init_all();
@@ -83,7 +88,7 @@ int main() {
int sm = 0;
uint offset = pio_add_program(pio, &ws2812_program);
ws2812_program_init(pio, sm, offset, PIN_TX, 800000, true);
ws2812_program_init(pio, sm, offset, PICO_DEFAULT_WS2812_PIN, 800000, IS_RGBW);
int t = 0;
while (1) {
@@ -92,9 +97,9 @@ int main() {
puts(pattern_table[pat].name);
puts(dir == 1 ? "(forward)" : "(backward)");
for (int i = 0; i < 1000; ++i) {
pattern_table[pat].pat(150, t);
pattern_table[pat].pat(NUM_PIXELS, t);
sleep_ms(10);
t += dir;
}
}
}
}