import time
from machine import Pin
time.sleep(0.1) # Wait for USB to become ready
BTN1_PIN = 28
BTN2_PIN = 21
BTN3_PIN = 16
BLUE_PIN = 1
GREEN_PIN = 2
RED_PIN = 0
DEBOUNCE_MS = 50
button_1 = Pin(BTN1_PIN, Pin.IN, Pin.PULL_UP)
button_2 = Pin(BTN2_PIN, Pin.IN, Pin.PULL_UP)
button_3 = Pin(BTN3_PIN, Pin.IN, Pin.PULL_UP)
blue = Pin(BLUE_PIN, Pin.OUT)
green = Pin(GREEN_PIN, Pin.OUT)
red = Pin(RED_PIN, Pin.OUT)
buttons = [button_1, button_2, button_3]
#===== code below ============
# button_1 varaible is the red button
# button_2 varaible is the green button
# button_3 varaible is the blue button
# led is the red led
# sets the colour of the rgb led
def set_colour_pins(r, g, b):
red.value(r)
green.value(g)
blue.value(b)
inputs = []
# collect inputs until five are stored in the list
while True:
if button_1.value() == 0:
inputs.append("red")
elif button_2.value() == 0:
inputs.append("green")
elif button_3.value() == 0:
inputs.append("blue")
if len(inputs) >= 5:
break
print(inputs)
time.sleep(0.2)
print(inputs)
# iterate through the inputs list and set the led colour
for colour in inputs:
if colour == "red":
set_colour_pins(1, 0, 0)
elif colour == "green":
set_colour_pins(0, 1, 0)
elif colour == "blue":
set_colour_pins(0, 0, 1)
time.sleep(1)
set_colour_pins(0, 0, 0)