from machine import Pin, ADC
from utime import sleep
sleep(0.1) # Wait for USB to become ready

# VARS ----------------------------------------

led_1 = Pin(0, Pin.OUT)
led_2 = Pin(1, Pin.OUT)
led_3 = Pin(2, Pin.OUT)
led_4 = Pin(3, Pin.OUT)
led_5 = Pin(4, Pin.OUT)
led_6 = Pin(5, Pin.OUT)
led_7 = Pin(6, Pin.OUT)

push_button = Pin(15, Pin.IN, Pin.PULL_DOWN)
ptm_button = ADC(26)

conv_factor = 1/65535
speed = 0
dice_lights = (
    (0,4),
    (1,7),
    (1,4,7),
    (1,3,5,7),
    (1,3,4,5,7),
    (1,2,3,5,6,7)
)

# FUNCTIONS -----------------------------------

def all_led_off() :
    for i in range(8) :
        led = "led_" + str(i)
        if led in locals() :
            locals()[led].value(0)

# ---------------------------------------------

while True :
    for i1, dice_side in enumerate(dice_lights) :
        if push_button.value() != 1 : break
        for i2, light in enumerate(dice_side) :
            led = "led_" + str(light)
            if led in locals() :
                locals()[led].value(1)
        speed = ptm_button.read_u16() * conv_factor
        sleep(1 + speed)
        all_led_off()
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT