#btn1 -> up(gp0)
#btn2 -> down(gp1)
#btn3 -> set(gp2)
#btn4 -> rst(gp3)
#a -> gp28
#b -> gp27
#c -> gp26
#d -> gp22
#e -> gp21
#f -> gp20
#g -> gp19
#dig1 -> gp12
#dig2 -> gp13
#dig3 -> gp14
#dig4 -> gp15
import time
from machine import Pin
time.sleep(0.1)
#segmentos
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
digitos_pin = [
Pin(12, Pin.OUT),
Pin(13, Pin.OUT),
Pin(14, Pin.OUT),
Pin(15, Pin.OUT),
]
#botones
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
ult_down = 0
ult_set = 0
ult_reset = 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
]
#unidades, decenas, centenas, miles
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
up_btn.irq(trigger=Pin.IRQ_FALLING, interrupcion=up_intrr)
down_btn.irq(trigger=Pin.IRQ_FALLING, interrupcion=down_intrr)
set_btn.irq(trigger=Pin.IRQ_FALLING, interrupcion=set_intrr)
reset_btn.irq(trigger=Pin.IRQ_FALLING, interrupcion=reset_intrr)
#apagar todos los segmentos
for d in digitos_pin:
d.value(1)
for s in segmentos_pins:
s.value(0)
while True:
digits = get_digits(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.005)