import time
import machine
import urandom
led_pins = [26, 25, 33, 32, 14, 27, 12]
patterns = [
[0, 0, 0, 1, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 1, 0, 0, 1],
[1, 0, 1, 0, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1],
[1, 1, 1, 0, 1, 1, 1]
]
button_pin = 13
for pin in led_pins:
machine.Pin(pin, machine.Pin.OUT).value(0)
button = machine.Pin(button_pin, machine.Pin.IN, machine.Pin.PULL_UP)
def roll_dice():
return urandom.randint(1, 6)
def show_dice(number):
for pin in led_pins:
machine.Pin(pin, machine.Pin.OUT).value(0)
for i in range(7):
if patterns[number-1][i]:
machine.Pin(led_pins[i], machine.Pin.OUT).value(1)
while True:
while button.value():
time.sleep(0.01)
number = roll_dice()
show_dice(number)
while not button.value():
time.sleep(0.01)
for pin in led_pins:
machine.Pin(pin, machine.Pin.OUT).value(0)