from neopixel import Neopixel
from machine import Pin
import time

print("Hello, TMPCB!")

colors = [
  (0, 0, 0),     # off
  (255, 0, 0),   # red
  (255, 0, 255), # purple
  (0, 0, 255),   # blue
]
buttons = [Pin(n+1, Pin.IN, Pin.PULL_UP) for n in range(10)]
btncolor = [0 for n in range(10)]
pixels = Neopixel(11, 0, 19, "GRB")

while True:
  for index, button in enumerate(buttons):
    if button.value() == 0:
      print("Changing color for button {}".format(index + 1))
      btncolor[index] += 1
      color = colors[btncolor[index] % len(colors)]
      pixels.set_pixel(index, color)
      pixels.show()
      time.sleep(0.2)
  time.sleep(0.01)
Loading
wokwi-custom-board
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT