from ws2812 import WS2812 import utime import machine power = machine.Pin(11, machine.Pin.OUT) power.value(1) BLACK = (0, 0, 0) RED = (255, 0, 0) YELLOW = (255, 150, 0) GREEN = (0, 255, 0) CYAN = (0, 255, 255) BLUE = (0, 0, 255) PURPLE = (180, 0, 255) WHITE = (255, 255, 255) COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE) led = WS2812(12, 1) # WS2812(pin_num, led_count) button = machine.Pin(2, machine.Pin.IN, machine.Pin.PULL_UP) animation_enabled = False def toggle_animation(pin): global animation_enabled animation_enabled = not animation_enabled button.irq(trigger=machine.Pin.IRQ_FALLING, handler=toggle_animation) while True: if animation_enabled: print("Beautiful color") for color in COLORS: led.pixels_fill(color) led.pixels_show() utime.sleep(0.2) else: led.pixels_fill(BLACK) led.pixels_show()