import machine
import neopixel
import time
n = 60 # Number of LEDs in your matrix
p = 15 # GPIO pin connected to Din
np = neopixel.NeoPixel(machine.Pin(p), n)
# Define the GPIO pins for the buttons
button_pins = [12, 13, 14]
# Initialize the button pins as pull-up inputs
for btn_pin in button_pins:
machine.Pin(btn_pin, machine.Pin.IN, machine.Pin.PULL_UP)
def set_led_color(color):
for x in range(n):
np[x] = color
np.write()
while True:
# Read button states
btn1_state = machine.Pin(12).value()
btn2_state = machine.Pin(13).value()
btn3_state = machine.Pin(14).value()
# Set LED color based on button states
if btn1_state == 0: # Button 1 pressed
set_led_color((0, 0, 255)) # Blue
elif btn2_state == 0: # Button 2 pressed
set_led_color((0, 255, 0)) # Green
elif btn3_state == 0: # Button 3 pressed
set_led_color((255, 0, 0)) # Red
else:
set_led_color((0, 0, 0)) # Turn off LED
# Add a small delay to avoid excessive loop execution
time.sleep(0.1)