import time
from neopixel import Neopixel
from machine import Pin
pixels = Neopixel(17, 0, 6, "GRB")
switch = Pin(15, Pin.IN, Pin.PULL_UP) # Pushbutton on GP15
green_led = Pin(16, Pin.OUT) # Green LED on GP16
red_led = Pin(17, Pin.OUT) # Red LED on GP17
white_led = Pin(11, Pin.OUT) # White LED on GP11
blue_led = Pin(12, Pin.OUT) # Blue LED on GP12
colors = [
(0xb6, 0xe4, 0x30), # Yellow
(0x42, 0xd1, 0xe0), # Blue
(0xff, 0xa5, 0x00), # Orange
(0x80, 0x00, 0x80), # Purple
]
pixel_index = 0
color_index = 0
while True:
if switch.value() == 0: # Button pressed (ON)
green_led.value(1) # Green ON
red_led.value(0) # Red OFF
white_led.value(1)
blue_led.value(1)
pixels.set_pixel(pixel_index, colors[color_index])
pixels.show()
pixel_index += 1
if pixel_index == 16:
pixel_index = 0
color_index = (color_index + 1) % len(colors) # Now cycles through 4 colors
time.sleep(0.1)
else: # Button not pressed (OFF)
green_led.value(0) # Green OFF
red_led.value(1) # Red ON
white_led.value(1)
blue_led.value(1)
for i in range(17):
pixels.set_pixel(i, (0, 0, 0))
pixels.show()
time.sleep(0.1)