import machine import time import neopixel # NeoPixel setup NUM_LEDS = 3 np = neopixel.NeoPixel(machine.Pin(17), NUM_LEDS) # Buttons button_pins = [20, 21, 22] buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP) for pin in button_pins] # Colors to cycle through colors = [ (255, 0, 0), # Red (0, 255, 0), # Green (0, 0, 255), # Blue (255, 255, 0), # Yellow (255, 0, 255), # Magenta (0, 255, 255), # Cyan (255, 255, 255) # White ] # Individual color indexes for each pixel indexes = [0, 0, 0] last_state = [1, 1, 1] # buttons start unpressed def show_pixels(): for i in range(NUM_LEDS): np[i] = colors[indexes[i]] np.write() # Initial display show_pixels() while True: for i in range(3): state = buttons[i].value() # Detect press (1 → 0) if last_state[i] == 1 and state == 0: indexes[i] = (indexes[i] + 1) % len(colors) show_pixels() time.sleep_ms(200) # debounce last_state[i] = state time.sleep_ms(10)