Skip to content
Snippets Groups Projects
Commit 5ca7966b authored by ebp1g21's avatar ebp1g21
Browse files

Upload New File

parent eb11cbf7
No related branches found
No related tags found
No related merge requests found
#include "pico/stdlib.h"
#include "hardware/pio.h"
#include "ws2812.pio.h"
#define IS_RGBW true
#define WS2812_PIN 28
#define BUTTON_1_PIN 20
#define BUTTON_2_PIN 21
#define BUTTON_3_PIN 22
static inline void put_pixel(uint32_t pixel_grb) {
pio_sm_put_blocking(pio0, 0, pixel_grb << 8u);
}
static inline uint32_t urgb_u32(uint8_t r, uint8_t g, uint8_t b) {
return
((uint32_t) (r) << 8) |
((uint32_t) (g) << 16) |
(uint32_t) (b);
}
int main() {
stdio_init_all();
// Setting up the ws2812
PIO pio = pio0;
int sm = 0;
uint offset = pio_add_program(pio, &ws2812_program);
ws2812_program_init(pio, sm, offset, WS2812_PIN, 800000, IS_RGBW);
// Initializing buttons
gpio_init(BUTTON_1_PIN);
gpio_set_dir(BUTTON_1_PIN, GPIO_IN);
gpio_pull_up(BUTTON_1_PIN);
gpio_init(BUTTON_2_PIN);
gpio_set_dir(BUTTON_2_PIN, GPIO_IN);
gpio_pull_up(BUTTON_2_PIN);
gpio_init(BUTTON_3_PIN);
gpio_set_dir(BUTTON_3_PIN, GPIO_IN);
gpio_pull_up(BUTTON_3_PIN);
// Main loop
while (true) {
if (!gpio_get(BUTTON_1_PIN)) {
put_pixel(urgb_u32(0xff, 0, 0));
}
if (!gpio_get(BUTTON_2_PIN)) {
put_pixel(urgb_u32(0, 0xff, 0));
}
if (!gpio_get(BUTTON_3_PIN)) {
put_pixel(urgb_u32(0, 0, 0xff));
}
}
return 0; // This will never be reached
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment