from machine import Pin
import utime
import random
PORT = [i for i in range(1, 8)] # соединения порта
Dice_no = [0, 0x08, 0x41, 0x49, 0x55, 0x5D, 0x77] # направления порта
# [0, 8, 65, 73, 85, 93, 119]
'''
0000000 ->
0001000 -> 1
1000001 -> 2
1001001 -> 3
1010101 -> 4
1011101 -> 5
1110111 -> 6
'''
L = [0] * 7
button = Pin(15, Pin.IN)
print(PORT, Dice_no, L, sep='\n')
def Configure_pin():
for i in range(7):
L[i] = Pin(PORT[i], Pin.OUT)
print("Pin number", L, sep='\n')
def port_output(x):
b = bin(x)
b = b.replace("0b", "")
diff = 7 - len(b)
for i in range(0, diff):
b = "0" + b
print("This is binary number : ", b)
for i in range(7):
if b[i] == "1":
L[i].value(1)
else:
L[i].value(0)
return
def DICE():
n = random.randint(1, 6)
print("Dice result : ", n)
pattern = Dice_no[n]
print("pattern : ", pattern)
port_output(pattern)
utime.sleep(3)
# port_output(0) # выключаем все светодиод
return
# устанавливаем порты
Configure_pin()
# основной цикл программы проверяем нажата ли кнопка
while True:
if button.value() == 0: # нажата кнопка?
DICE()
print("END PROGRAM!!")