from machine import Pin # Interactuar con los pines
import time # Manejar el tiempo
# Configurar GPIO [General Purpose Input/Output]
BTN_PULLUP_GPIO = 14 # Pull-up: suelto = 1, presionado = 0
BTN_PULLDOWN_GPIO = 13 # Pull-down: suelto = 0, presionado = 1
LED_ROJO_GPIO = 23
LED_VERDE_GPIO = 22
# ENTRADAS
btn_pullup_pin = Pin(BTN_PULLUP_GPIO, Pin.IN)
btn_pulldn_pin = Pin(BTN_PULLDOWN_GPIO, Pin.IN)
# SALIDAS
led_rojo = Pin(LED_ROJO_GPIO, Pin.OUT)
led_verde = Pin(LED_VERDE_GPIO, Pin.OUT)
print("Leyendo botones Pull-up y Pull-down")
t_print = time.ticks_ms()
while True:
# Lecturas actuales
v_up = btn_pullup_pin.value()
v_dn = btn_pulldn_pin.value()
# Control de leds
if v_up == 0:
led_verde.value(1)
else:
led_verde.value(0)
led_rojo.value(1 if v_dn == 1 else 0)
# Mostrar valores por terminal
if time.ticks_diff(time.ticks_ms(), t_print) >= 300:
t_print = time.ticks_ms()
print("UP: ", v_up, "DN: ", v_dn) # Muestro impresion
time.sleep_ms(10)