#include <stdio.h>
#include "pico/stdlib.h"
#include "led_strip.pio.h"
#if !defined LED_STRIP_PIO_LED_PIN
#define LED_STRIP_PIO_LED_PIN 1
#endif
int main() {
stdio_init_all();
PIO pio;
uint sm;
uint offset;
// This will find a free pio and state machine for our program and load it for us
// We use pio_claim_free_sm_and_add_program_for_gpio_range so we can address gpios >= 32 if needed and supported by the hardware
bool success = pio_claim_free_sm_and_add_program_for_gpio_range(&pioLedStrip_program, &pio, &sm, &offset, LED_STRIP_PIO_LED_PIN, 1, true);
hard_assert(success);
// Configure it to run our program, and start it, using the
// helper function we included in our .pio file.
printf("Using gpio %d\n", LED_STRIP_PIO_LED_PIN);
ws2812byte_program_init(pio, sm, offset, LED_STRIP_PIO_LED_PIN, 20000, 24);
uint8_t brightness = 0;
int8_t direction = 1;
while (getchar_timeout_us(0) == PICO_ERROR_TIMEOUT) {
brightness += direction * 3;
if (brightness >= 255 || brightness <= 0) {
direction = direction * -1;
brightness += direction * 3;
}
printf("Brightness: %d Direction: %d\n", brightness, direction);
uint8_t br = (brightness) % 255;
// Sample color
uint8_t g = br;
uint8_t r = 0;
uint8_t b = br / 4;
uint32_t grb = (g << 16) + (r << 8) + b;
printf("B: %d Color %d!\n", br, grb << 8);
pio_sm_put(pio, sm, grb << 8);
sleep_ms(100);
}
}