from machine import Pin
import utime

PORT = [8, 7, 6, 5, 4, 3, 2, 1]  # port connections
DICE_NO = [0, 0x08, 0x41, 0x49, 0x55, 0x5D, 0x77]
L = [0] * 8
Button = Pin(15, Pin.IN)

# This function configures the LED ports as outputs
def Configure_Port():
    for i in range(0, 8):
        L[i] = Pin(PORT[i], Pin.OUT)

# This function sends 8-bit data (0 to 255) to the PORT
def Port_Output(x):
    b = bin(x)[2:]  # convert into binary and remove leading "0b"
    diff = 8 - len(b)  # find the length
    for i in range(diff):
        b = "0" + b  # insert leading 0s
    for i in range(8):
        if b[i] == "1":
            L[i].value(1)
        else:
            L[i].value(0)

# The program jumps here every 3 seconds
def DICE():
    for n in range(1, 7):
        pattern = DICE_NO[n]  # find the pattern
        Port_Output(pattern)  # turn ON required LEDs
        utime.sleep(3)  # wait for 0.5 seconds
        Port_Output(0)  # turn OFF all LEDs
        utime.sleep(0.5)  # wait for 0.5 seconds

# Configure PORT to all outputs
Configure_Port()

# Main program loop
while True:
    for n in range(1, 7):
        DICE()  # Call DICE for each number
        utime.sleep(2)  # wait for 2 seconds before the next dice pattern
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT