from machine import Pin
import time
seg_a = Pin(0, Pin.OUT)
seg_b = Pin(1, Pin.OUT)
seg_c = Pin(2, Pin.OUT)
seg_d = Pin(3, Pin.OUT)
seg_e = Pin(4, Pin.OUT)
seg_f = Pin(5, Pin.OUT)
seg_g = Pin(6, Pin.OUT)
# Lista con todos los segmentos en orden a,b,c,d,e,f,g
segmentos = [seg_a, seg_b, seg_c, seg_d, seg_e, seg_f, seg_g]
# -----------------------------------------------
# TABLA DE DÍGITOS
# El orden es: [a, b, c, d, e, f, g]
# -----------------------------------------------
digitos = {
0: [1, 1, 1, 1, 1, 1, 0], # 0 → todos menos g
1: [0, 1, 1, 0, 0, 0, 0], # 1 → solo lado derecho
2: [1, 1, 0, 1, 1, 0, 1], # 2 → a,b,g,e,d
3: [1, 1, 1, 1, 0, 0, 1], # 3 → a,b,c,d,g
4: [0, 1, 1, 0, 0, 1, 1], # 4 → f,g,b,c
5: [1, 0, 1, 1, 0, 1, 1], # 5 → a,f,g,c,d
6: [1, 0, 1, 1, 1, 1, 1], # 6 → a,f,g,e,c,d
7: [1, 1, 1, 0, 0, 0, 0], # 7 → solo a,b,c
8: [1, 1, 1, 1, 1, 1, 1], # 8 → todos encendidos
9: [1, 1, 1, 1, 0, 1, 1], # 9 → todos menos e
}
# -----------------------------------------------
# FUNCIÓN: mostrar_digito(numero)
# -----------------------------------------------
def mostrar_digito(numero):
patron = digitos[numero]
for i in range(7): # recorre los 7 segmentos
segmentos[i].value(patron[i]) # enciende (1) o apaga (0) cada uno
def apagar_todos():
for seg in segmentos:
seg.off()
print("=== Cuenta regresiva del 9 al 0 ===")
# -----------------------------------------------
# BUCLE inicial
# Cuenta del 9 al 0 usando range(9, -1, -1)
# range(9, -1, -1) genera: 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
# -----------------------------------------------
while True:
for numero in range(9, -1, -1): # 9, 8, 7, ... 1, 0
mostrar_digito(numero) # muestra el número en el display
print(f"Mostrando: {numero}")
time.sleep(1) # espera 1 segundo entre cada número
apagar_todos()
time.sleep(0.5)