from machine import Pin
from time import sleep_ms
# Pinos dos LEDs
LED_VERDE = Pin(26, Pin.OUT)
LED_AMARELO = Pin(27, Pin.OUT)
LED_VERMELHO = Pin(14, Pin.OUT)
# Pinos dos Botoes (PULL_UP: pressionado = 0)
BOTAO1 = Pin(13, Pin.IN, Pin.PULL_UP)
BOTAO2 = Pin(12, Pin.IN, Pin.PULL_UP)
BOTAO3 = Pin(4, Pin.IN, Pin.PULL_UP)
def apagar_todos():
LED_VERDE.value(0)
LED_AMARELO.value(0)
LED_VERMELHO.value(0)
print("Pronto. Pressione um botao.")
while True:
b1 = BOTAO1.value() == 0
b2 = BOTAO2.value() == 0
b3 = BOTAO3.value() == 0
apagar_todos()
if b3:
# Botao 3: todos os LEDs acendem
LED_VERDE.value(1)
LED_AMARELO.value(1)
LED_VERMELHO.value(1)
print("Botao 3 - Todos os LEDs acesos")
elif b2:
# Botao 2: LED Verde e Amarelo acendem
LED_VERDE.value(1)
LED_AMARELO.value(1)
print("Botao 2 - LED Verde e Amarelo acesos")
elif b1:
# Botao 1: apenas LED Verde acende
LED_VERDE.value(1)
print("Botao 1 - LED Verde aceso")
sleep_ms(50)