import machine
import neopixel
import tm1637
from time import sleep_ms
# Blue - chosen "bit"
# Red - not chosen "bit"
tm = tm1637.TM1637(clk=machine.Pin(13), dio=machine.Pin(12))
BLANK = (0,255,0)
COLOR = (255,0,0)
flags = [0,0,0,0,0]
ON = 0
OFF = 1
GPIO_pin_number_4 = machine.Pin(4)
light_leds_number = 5
ledstrip = neopixel.NeoPixel(GPIO_pin_number_4, light_leds_number)
for i in range(len(ledstrip)):
ledstrip[i] = BLANK
ledstrip.write()
btn1 = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP)
btn2 = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_UP)
btn4 = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_UP)
btn8 = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_UP)
btn16 = machine.Pin(23, machine.Pin.IN, machine.Pin.PULL_UP)
btn_finish = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP)
buttons = [btn1, btn2, btn4, btn8, btn16]
def change_led_state(index: int):
if ledstrip[index] == COLOR:
ledstrip[index] = BLANK
else:
ledstrip[index] = COLOR
ledstrip.write()
def finish():
result = 0
for i in range(len(ledstrip)):
if ledstrip[i] == BLANK:
result += 2 ** i
tm.number(result)
while True:
for i in range(5):
if (buttons[i].value() == ON and flags[i] == ON):
flags[i] = OFF
change_led_state(i)
elif (flags[i] == OFF and buttons[i].value() == OFF):
flags[i] = ON
if btn_finish.value() == ON:
finish()