from machine import Pin
from time import sleep
import random
# Pines conectados a los segmentos A-G del display
segments = [Pin(i, Pin.OUT) for i in (13, 12, 14, 27, 26, 25, 33)]
# Botón conectado al pin 32 con resistencia pull-up interna
button = Pin(32, Pin.IN, Pin.PULL_UP)
# Codificación binaria para los números 1 a 6
# Índice 0 no se usa
digits = [
[0,0,0,0,0,0,0], # 0 (no se usa)
[0,1,1,0,0,0,0], # 1
[1,1,0,1,1,0,1], # 2
[1,1,1,1,0,0,1], # 3
[0,1,1,0,0,1,1], # 4
[1,0,1,1,0,1,1], # 5
[1,0,1,1,1,1,1] # 6
]
def show_number(n):
for i in range(7):
segments[i].value(digits[n][i])
while True:
if button.value() == 0: # Cuando se presiona (LOW)
number = random.randint(1, 6)
show_number(number)
sleep(1) # Tiempo de espera para evitar múltiples lecturas