from machine import Pin
from utime import sleep
# Configuración de pines del display 7 segmentos (ánodo común)
pins = [
Pin(2, Pin.OUT), # A
Pin(3, Pin.OUT), # B
Pin(4, Pin.OUT), # C
Pin(5, Pin.OUT), # D
Pin(6, Pin.OUT), # E
Pin(8, Pin.OUT), # F
Pin(7, Pin.OUT), # G
Pin(0, Pin.OUT) # DP (no usado)
]
# Patrones de 0-F en 7 segmentos
digits = [
[0,0,0,0,0,0,1,1], # 0
[1,0,0,1,1,1,1,1], # 1
[0,0,1,0,0,1,0,1], # 2
[0,0,0,0,1,1,0,1], # 3
[1,0,0,1,1,0,0,1], # 4
[0,1,0,0,1,0,0,1], # 5
[0,1,0,0,0,0,0,1], # 6
[0,0,0,1,1,1,1,1], # 7
[0,0,0,0,0,0,0,1], # 8
[0,0,0,1,1,0,0,1], # 9
[0,0,0,1,0,0,0,1], # A
[1,1,0,0,0,0,0,1], # b
[0,1,1,0,0,0,1,1], # C
[1,0,0,0,0,1,0,1], # d
[0,1,1,0,0,0,0,1], # E
[0,1,1,1,0,0,0,1], # F
]
# Patrones especiales
BLANK = [1,1,1,1,1,1,1,1]
ALL_ON = [0,0,0,0,0,0,0,0]
def reset():
for pin in pins:
pin.value(1)
reset()
# Switch de dirección
switch_dir = Pin(13, Pin.IN, Pin.PULL_UP)
# DIP-Switch (con pull-up internos)
dip1 = Pin(17, Pin.IN, Pin.PULL_UP)
dip2 = Pin(16, Pin.IN, Pin.PULL_UP)
def mostrar(pat):
for j in range(len(pins)):
pins[j].value(pat[j])
def recorrer(secuencia):
if switch_dir.value() == 1:
iterable = secuencia
else:
iterable = reversed(secuencia)
for i in iterable:
if i == "BLANK":
mostrar(BLANK)
elif i == "ALL":
mostrar(ALL_ON)
else:
mostrar(digits[i])
sleep(0.5)
# -----------------------------
# Loop principal
# -----------------------------
while True:
d1 = dip1.value()
d2 = dip2.value()
if d1 == 0 and d2 == 0:
recorrer(["BLANK", "ALL"])
elif d1 == 0 and d2 == 1:
recorrer([0,2,4,6,8,10,12,14])
elif d1 == 1 and d2 == 0:
recorrer([1,3,5,7,9,11,13,15])
elif d1 == 1 and d2 == 1:
recorrer([0,1])