from machine import Pin
from utime import sleep
# Pinos do display da unidade (exemplo com os seus pinos originais)
unidade_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 (não usado)
]
# Pinos do display da dezena (troque pelos seus pinos reais)
dezena_pins = [
Pin(9, Pin.OUT), # A
Pin(10, Pin.OUT), # B
Pin(11, Pin.OUT), # C
Pin(12, Pin.OUT), # D
Pin(13, Pin.OUT), # E
Pin(15, Pin.OUT), # F
Pin(14, Pin.OUT), # G
Pin(16, Pin.OUT) # DP (não usado)
]
# Dígitos 0-9 para anodo comum (igual do seu código)
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, 0, 1, 0, 0, 1], # 9
]
def reset(pins):
for pin in pins:
pin.value(1)
reset(unidade_pins)
reset(dezena_pins)
botao = Pin(1, Pin.IN, Pin.PULL_UP)
contador_ativo = False
numero = 0
def mostra_digito(pins, digito):
for i in range(len(pins)):
pins[i].value(digits[digito][i])
while True:
if botao.value() == 0:
while botao.value() == 0:
sleep(0.02) # espera soltar
contador_ativo = not contador_ativo
if contador_ativo:
dezena = numero // 10
unidade = numero % 10
mostra_digito(dezena_pins, dezena)
mostra_digito(unidade_pins, unidade)
sleep(1)
numero += 1
if numero > 99:
numero = 0
else:
dezena = numero // 10
unidade = numero % 10
mostra_digito(dezena_pins, dezena)
mostra_digito(unidade_pins, unidade)
sleep(0.02)