from machine import Pin
import time as t
DOWN = Pin(16, Pin.IN, Pin.PULL_DOWN)
UP = Pin(17, Pin.IN, Pin.PULL_DOWN)
SET = Pin(18, Pin.IN, Pin.PULL_DOWN)
RST = Pin(19, Pin.IN, Pin.PULL_DOWN)
leds = (0, 1, 2, 3, 4, 5, 6)
lista_Pin = list()
for i in range(7):
lista_Pin.append(Pin(leds[i], Pin.OUT))
digitos = {
0: [1, 1, 1, 1, 1, 1, 0],
1: [0, 1, 1, 0, 0, 0, 0],
2: [1, 1, 0, 1, 1, 0, 1],
3: [1, 1, 1, 1, 0, 0, 1],
4: [0, 1, 1, 0, 0, 1, 1],
5: [1, 0, 1, 1, 0, 1, 1],
6: [1, 0, 1, 1, 1, 1, 1],
7: [1, 1, 1, 0, 0, 0, 0],
8: [1, 1, 1, 1, 1, 1, 1],
9: [1, 1, 1, 1, 0, 1, 1]
}
habs = (15, 14, 13, 12)
lista_habs = list()
for i in range(4):
lista_habs.append(Pin(habs[i], Pin.OUT))
habilitadores = {
0: [0, 1, 1, 1],
1: [1, 0, 1, 1],
2: [1, 1, 0, 1],
3: [1, 1, 1, 0],
4: [1, 1, 1, 1] # Apagar los displays
}
def mostrar(numero):
for pin, estado in zip(lista_Pin, digitos[numero]):
pin.value(estado)
def habilitar(numero):
for pin, estado in zip(lista_habs, habilitadores[numero]):
pin.value(estado)
counter = 0
retardo = 300 # milisegundos
u_pres = {
"UP": 0,
"DOWN": 0,
"SET": 0,
"RST": 0
}
def fun_UP(UP):
global counter
t_actual = t.ticks_ms()
if t.ticks_diff(t_actual, u_pres["UP"]) > retardo:
counter = counter + 1
if counter == 1001:
counter = 0
u_pres["UP"] = t_actual
def fun_DOWN(DOWN):
global counter
t_actual = t.ticks_ms()
if t.ticks_diff(t_actual, u_pres["DOWN"]) > retardo:
counter = counter - 1
if counter == -1:
counter = 1000
u_pres["DOWN"] = t_actual
def fun_SET(SET):
global counter
t_actual = t.ticks_ms()
if t.ticks_diff(t_actual, u_pres["SET"]) > retardo:
counter = 500
u_pres["SET"] = t_actual
def fun_RST(RST):
global counter
t_actual = t.ticks_ms()
if t.ticks_diff(t_actual, u_pres["RST"]) > retardo:
counter = 0
u_pres["RST"] = t_actual
UP.irq(trigger = Pin.IRQ_RISING, handler=fun_UP)
DOWN.irq(trigger = Pin.IRQ_RISING, handler=fun_DOWN)
SET.irq(trigger = Pin.IRQ_RISING, handler=fun_SET)
RST.irq(trigger = Pin.IRQ_RISING, handler=fun_RST)
while True:
unidad = counter % 10
decena = (counter // 10) % 10
centena = (counter // 100) % 10
millar = (counter // 1000) % 10
habilitar(4)
mostrar(unidad)
habilitar(0)
t.sleep_ms(5)
habilitar(4)
mostrar(decena)
habilitar(1)
t.sleep_ms(5)
habilitar(4)
mostrar(centena)
habilitar(2)
t.sleep_ms(5)
habilitar(4)
mostrar(millar)
habilitar(3)
t.sleep_ms(5)