from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
pines = [26, 27, 14, 12, 13, 25, 33]
segmentos = [Pin(pin, Pin.OUT) for pin in pines]
uni = Pin(19, Pin.OUT)
dec = Pin(18, Pin.OUT)
Rojo = Pin(2, Pin.OUT)
Aumentar = Pin(17, Pin.IN, Pin.PULL_DOWN)
Bajar = Pin(16, Pin.IN, Pin.PULL_DOWN)
Inicio = Pin(4, Pin.IN, Pin.PULL_DOWN)
matriz = [
[1, 1, 1, 1, 1, 1, 0], # 0
[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
[1, 1, 1, 0, 0, 1, 0], # 7
[1, 1, 1, 1, 1, 1, 1], # 8
[1, 1, 1, 1, 0, 1, 1], # 9
]
contador = 0
estado_up = 0
estado_down = 0
estado_auto = 0
conteo_activo = False
ultimo_tiempo = ticks_ms()
def num(fila):
for columna in range(7):
segmentos[columna].value(matriz[fila][columna])
def conmutador(valor):
uni.value(valor)
dec.value(1 - valor)
def mostrar_numero(n):
decenas = n // 10
unidades = n % 10
for _ in range(10):
conmutador(1)
num(decenas)
sleep_ms(5)
conmutador(0)
num(unidades)
sleep_ms(5)
while True:
actual_up = Aumentar.value()
actual_down = Bajar.value()
actual_auto = Inicio.value()
if actual_up and not estado_up:
contador = (contador + 1) % 100
if actual_down and not estado_down:
contador = (contador - 1) % 100
if actual_auto and not estado_auto:
conteo_activo = not conteo_activo
estado_up = actual_up
estado_down = actual_down
estado_auto = actual_auto
if conteo_activo and ticks_diff(ticks_ms(), ultimo_tiempo) >= 500:
if contador > 0:
contador = contador-1
else:
conteo_activo = False
ultimo_tiempo = ticks_ms()
mostrar_numero(contador)
if contador == 0:
Rojo.value(1)
sleep_ms(50)
Rojo.value(0)
sleep_ms(50)
else:
Rojo.value(0)