import machine
from machine import Pin, Timer
import time
#difinimos tipos
NADA=0
EVENTO=1
ESPERA=2
Verde=Pin(4,Pin.IN, Pin.PULL_UP)
Rojo=Pin(6,Pin.IN, Pin.PULL_UP)
Amarillo=Pin(5,Pin.IN, Pin.PULL_UP)
Azul=Pin(7,Pin.IN, Pin.PULL_UP)
estadoVerde = NADA #Estado del pulsador
estadoAzul = NADA
estadoRojo = NADA
estadoAmarillo = NADA
def procesaEntrada(estadoActual,valorPin):
if estadoActual==NADA and valorPin==False:
return EVENTO
if estadoActual==EVENTO:
return ESPERA
if estadoActual==ESPERA and valorPin==False:
return ESPERA
return NADA
while True:
time.sleep_ms(5) #Dejamos pasar tiempo para eliminar bouncing
#Procesamos la entrada a ver si hay evento
estadoVerde = procesaEntrada(estadoVerde, Verde.value())
if (estadoVerde == EVENTO):
print("verde!")
estadoAzul = procesaEntrada(estadoAzul, Azul.value())
if (estadoAzul == EVENTO):
print("azul!")
estadoRojo = procesaEntrada(estadoRojo, Rojo.value())
if (estadoRojo == EVENTO):
print("rojo!")
estadoAmarillo = procesaEntrada(estadoAmarillo, Amarillo.value())
if (estadoAmarillo == EVENTO):
print("amarillo!")