import machine
import utime
#declaración de variables y puertos donde estan conectados
led_rojo = machine.Pin(15, machine.Pin.OUT)
led_amarillo = machine.Pin(13, machine.Pin.OUT)
led_verde = machine.Pin(7, machine.Pin.OUT)
#configuración del boton
boton = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)
#Ciclo while, parpadeo infinito
while True:
# Ciclo led ROJO
led_rojo.value(1)
led_amarillo.value(0)
led_verde.value(0)
utime.sleep(5)
# ciclo led VERDE
led_rojo.value(0)
led_amarillo.value(0)
led_verde.value(1)
#Se repite el ciclo 10 veces
for i in range(10):
#Cuando se presiona el boton se corta antes
if boton.value() == 0:
break
utime.sleep(1)
# Si se presionó el botón
if boton.value() == 0:
led_rojo.value(1)
led_amarillo.value(0)
led_verde.value(0)
utime.sleep(5)
# Se forza el color Rojo
led_rojo.value(1)
led_amarillo.value(0)
led_verde.value(0)
utime.sleep(5)
# VUELVE A Amarillo
led_rojo.value(0)
led_amarillo.value(1)
led_verde.value(0)
utime.sleep(2)
#termina en rojo
led_rojo.value(1)
led_amarillo.value(0)
led_verde.value(0)
utime.sleep(2)