import time
from machine import Pin
segmentos_pins = [
Pin(28, Pin.OUT), Pin(27, Pin.OUT), Pin(26, Pin.OUT),
Pin(22, Pin.OUT), Pin(21, Pin.OUT), Pin(20, Pin.OUT), Pin(19, Pin.OUT)
]
digitos_pin = [
Pin(12, Pin.OUT), Pin(13, Pin.OUT), Pin(14, Pin.OUT), Pin(15, Pin.OUT)
]
# Botones con Pull-Up interno
up_btn = Pin(0, Pin.IN, Pin.PULL_UP)
down_btn = Pin(1, Pin.IN, Pin.PULL_UP)
set_btn = Pin(2, Pin.IN, Pin.PULL_UP)
reset_btn = Pin(3, Pin.IN, Pin.PULL_UP)
count = 0
debounce = 250
ult_up = 0
patron_segmento = [
(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,0,0), # 7
(1,1,1,1,1,1,1), # 8
(1,1,1,1,0,1,1) # 9
]
# Extraer Miles, Centenas, Decenas y Unidades
def udcm(num):
return [
(num // 1000) % 10,
(num // 100) % 10,
(num // 10) % 10,
num % 10
]
def up_intrr(pin):
global count, ult_up
now = time.ticks_ms()
if time.ticks_diff(now, ult_up) > debounce:
count = 0 if count >= 1000 else count + 1
ult_up = now
def down_intrr(pin):
global count, ult_up
now = time.ticks_ms()
if time.ticks_diff(now, ult_up) > debounce:
count = 1000 if count <= 0 else count - 1
ult_up = now
def set_intrr(pin):
global count, ult_up
now = time.ticks_ms()
if time.ticks_diff(now, ult_up) > debounce:
count = 500
ult_up = now
def reset_intrr(pin):
global count, ult_up
now = time.ticks_ms()
if time.ticks_diff(now, ult_up) > debounce:
count = 0
ult_up = now
# Registro de interrupciones
up_btn.irq(trigger=Pin.IRQ_FALLING, handler=up_intrr)
down_btn.irq(trigger=Pin.IRQ_FALLING, handler=down_intrr)
set_btn.irq(trigger=Pin.IRQ_FALLING, handler=set_intrr)
reset_btn.irq(trigger=Pin.IRQ_FALLING, handler=reset_intrr)
for d in digitos_pin: d.value(1) # Apagar dígitos
for s in segmentos_pins: s.value(0) # Apagar segmentos
while True:
digits = udcm(count)
for i in range(4):
for d in digitos_pin:
d.value(1)
patter = patron_segmento[digits[i]]
for j in range(7):
segmentos_pins[j].value(patter[j])
digitos_pin[i].value(0)
time.sleep(0.004)Loading
pi-pico-w
pi-pico-w