from machine import Pin
from time import sleep
from LCD import CharLCD
bfA = Pin(25, Pin.IN, Pin.PULL_DOWN) #Seguir A
btA = Pin(27, Pin.IN, Pin.PULL_DOWN) #Retroceder A
bfB = Pin(14, Pin.IN, Pin.PULL_DOWN) #Seguir B
btB = Pin(12, Pin.IN, Pin.PULL_DOWN) #Retroceder B
PlA = 0 #Placar A
PlB = 0 #Placar B
botao_ultimo = None
lcd = CharLCD(rs=23, en=21, d4=19, d5=18, d6=5, d7=17, cols=16, rows=2)
lcd.message('Ligado', 2)
sleep(2)
def checar_botao():
if bfA.value() == 1:
sleep(0.05)
if bfA.value() == 1:
while bfA.value() == 1:
sleep(0.01)
return "BFA"
elif btA.value() == 1:
sleep(0.05)
if btA.value() == 1:
while btA.value() == 1:
sleep(0.01)
return "BTA"
elif bfB.value() == 1:
sleep(0.05)
if bfB.value() == 1:
while bfB.value() == 1:
sleep(0.01)
return "BFB"
elif btB.value() == 1:
sleep(0.05)
if btB.value() == 1:
while btB.value() == 1:
sleep(0.01)
return "BTB"
else:
return None
def atualizar_display():
lcd.set_line(0)
lcd.message(f"{PlA} A x B {PlB}", 2)
lcd.clear()
atualizar_display()
while True:
botao = checar_botao()
if botao != botao_ultimo and botao is not None:
print(botao)
if botao == "BFA":
PlA += 1
elif botao == "BTA":
if PlA > 0:
PlA = PlA - 1
elif botao == "BFB":
PlB += 1
elif botao == "BTB":
if PlB > 0:
PlB = PlB - 1
atualizar_display()
botao_ultimo = botao