import machine
from machine import Pin, Timer
import time
NADA = 0
EVENTO = 1
ESPERA = 2
verde = Pin(4, Pin.IN, Pin.PULL_UP)
amarillo = Pin(5, Pin.IN, Pin.PULL_UP)
rojo = Pin(6, Pin.IN, Pin.PULL_UP)
azul = Pin(7, Pin.IN, Pin.PULL_UP)
estadoVerde = NADA
estadoAmarillo = NADA
estadoRojo = NADA
estadoAzul = 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)
estadoVerde = procesaEntrada(estadoVerde, verde.value())
estadoAmarillo = procesaEntrada(estadoAmarillo, amarillo.value())
estadoAzul = procesaEntrada(estadoAzul, azul.value())
estadoRojo = procesaEntrada(estadoRojo, rojo.value())
if (estadoVerde == EVENTO):
print("Verde")
if (estadoRojo == EVENTO):
print("Rojo")
if (estadoAmarillo == EVENTO):
print("amarillo")
if (estadoAzul == EVENTO):
print("azul")