#---[MÓDULOS que se REQUIEREN]---
import machine
import utime
# Creación de 'objetos' del tipo 'Pin', asociado con LEDs
BOTON = 19
LEDV = 26
verdepeaton = 25
botonc= 0
x= 0
ROJO = 21
AMARILLO = 22
VERDE = 23
tiempo_restante= 0
VERDED= 16
AMARILLOD= 4
ROJOD= 2
VERDEAB= 18
AMARILLOAB= 5
ROJOAB= 17
verdeabajo=0
verdederecha=0
verdeizquierda=0
#semaforo 1
machine.Pin(ROJO, machine.Pin.OUT)
machine.Pin(AMARILLO, machine.Pin.OUT)
machine.Pin(VERDE, machine.Pin.OUT)
machine.Pin(VERDED, machine.Pin.OUT)
machine.Pin(AMARILLOD, machine.Pin.OUT)
machine.Pin(ROJOD, machine.Pin.OUT)
machine.Pin(VERDEAB, machine.Pin.OUT)
machine.Pin(AMARILLOAB, machine.Pin.OUT)
machine.Pin(ROJOAB, machine.Pin.OUT)
#boton
button = machine.Pin(BOTON, machine.Pin.IN, machine.Pin.PULL_UP)
#peaton
machine.Pin(LEDV, machine.Pin.OUT)
machine.Pin(verdepeaton, machine.Pin.OUT)
# Aviso #
print()
print("= Inicio de la aplicación =")
print()
def coche():
global botonc
global verdeabajo
global tiempo_restante
global verdederecha
global verdeizquierda
machine.Pin(VERDE, machine.Pin.OUT).on()
utime.sleep(2)
for x in range (3):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
machine.Pin(VERDE, machine.Pin.OUT).off()
machine.Pin(AMARILLO, machine.Pin.OUT).on()
if botonc==0:
for x in range (3):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
else:
utime.sleep(3)
if botonc==0:
machine.Pin(AMARILLO, machine.Pin.OUT).off()
machine.Pin(ROJO, machine.Pin.OUT).on()
machine.Pin(VERDE, machine.Pin.OUT).off()
machine.Pin(VERDEAB, machine.Pin.OUT).on()
machine.Pin(ROJOAB,machine.Pin.OUT).off()
verdeabajo=1
for x in range (5):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
else:
machine.Pin(AMARILLO, machine.Pin.OUT).off()
machine.Pin(ROJO, machine.Pin.OUT).on()
machine.Pin(verdepeaton, machine.Pin.OUT).on()
machine.Pin(LEDV, machine.Pin.OUT).off()
botonc=0
utime.sleep(10)
machine.Pin(verdepeaton, machine.Pin.OUT).off()
machine.Pin(LEDV, machine.Pin.OUT).on()
if verdeabajo==1:
machine.Pin(VERDEAB, machine.Pin.OUT).off()
machine.Pin(AMARILLOAB, machine.Pin.OUT).on()
if botonc==0:
for x in range (3):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
else:
utime.sleep(3)
if botonc==0:
machine.Pin(AMARILLOAB, machine.Pin.OUT).off()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
machine.Pin(VERDE, machine.Pin.OUT).off()
machine.Pin(VERDED, machine.Pin.OUT).on()
machine.Pin(ROJOD,machine.Pin.OUT).off()
verdederecha=1
for x in range (5):
if button.value()==0:
botonc=1
else:
utime.sleep(1)
else:
machine.Pin(AMARILLOAB, machine.Pin.OUT).off()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
machine.Pin(verdepeaton, machine.Pin.OUT).on()
machine.Pin(LEDV, machine.Pin.OUT).off()
botonc=0
utime.sleep(10)
machine.Pin(verdepeaton, machine.Pin.OUT).off()
machine.Pin(LEDV, machine.Pin.OUT).on()
if verdederecha==1:
machine.Pin(VERDEAB, machine.Pin.OUT).off()
machine.Pin(AMARILLOAB, machine.Pin.OUT).on()
if botonc==0:
for x in range (3):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
else:
utime.sleep(3)
if botonc==0:
machine.Pin(AMARILLOAB, machine.Pin.OUT).off()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
machine.Pin(VERDE, machine.Pin.OUT).off()
machine.Pin(VERDED, machine.Pin.OUT).on()
machine.Pin(ROJOD,machine.Pin.OUT).off()
verdederecha=1
for x in range (5):
if button.value()==0:
botonc=1
else:
utime.sleep(1)
else:
machine.Pin(VERDEAB, machine.Pin.OUT).on()
machine.Pin(ROJOAB, machine.Pin.OUT).off()
if botonc==0:
for x in range (5):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
else:
utime.sleep(5)
machine.Pin(VERDEAB, machine.Pin.OUT).off()
machine.Pin(AMARILLOAB, machine.Pin.OUT).on()
if botonc==0:
for x in range (3):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
else:
utime.sleep(3)
if botonc==0:
machine.Pin(AMARILLOAB, machine.Pin.OUT).off()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
machine.Pin(VERDE, machine.Pin.OUT).off()
machine.Pin(VERDED, machine.Pin.OUT).on()
machine.Pin(ROJOD,machine.Pin.OUT).off()
verdederecha=1
for x in range (5):
if button.value()==0:
botonc=1
else:
utime.sleep(1)
else:
machine.Pin(AMARILLOAB, machine.Pin.OUT).off()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
machine.Pin(VERDED, machine.Pin.OUT).on()
machine.Pin(ROJOD, machine.Pin.OUT).off()
machine.Pin(verdepeaton, machine.Pin.OUT).on()
machine.Pin(LEDV, machine.Pin.OUT).off()
botonc=0
utime.sleep(10)
machine.Pin(verdepeaton, machine.Pin.OUT).off()
machine.Pin(LEDV, machine.Pin.OUT).on()
if botonc==0:
machine.Pin(AMARILLOAB, machine.Pin.OUT).off()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
machine.Pin(VERDE, machine.Pin.OUT).off()
machine.Pin(VERDED, machine.Pin.OUT).on()
machine.Pin(ROJOD,machine.Pin.OUT).off()
verdeabajo=1
for x in range (5):
if button.value()==0:
botonc=1
else:
utime.sleep(1)
else:
machine.Pin(AMARILLOAB, machine.Pin.OUT).off()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
botonc=0
utime.sleep(10)
machine.Pin(AMARILLOD, machine.Pin.OUT).on()
machine.Pin(VERDED, machine.Pin.OUT).off()
for x in range (3):
if button.value()==0:
botonc=1
utime.sleep(1)
else:
utime.sleep(1)
machine.Pin(AMARILLOD, machine.Pin.OUT).off()
machine.Pin(ROJOD, machine.Pin.OUT).on()
def peaton():
machine.Pin(VERDE, machine.Pin.OUT).on()
utime.sleep(2)
machine.Pin(VERDE, machine.Pin.OUT).off()
machine.Pin(AMARILLO, machine.Pin.OUT).on()
utime.sleep(2)
machine.Pin(AMARILLO, machine.Pin.OUT).off()
machine.Pin(ROJO, machine.Pin.OUT).on()
machine.Pin(verdepeaton, machine.Pin.OUT).on()
machine.Pin(LEDV, machine.Pin.OUT).off()
utime.sleep(15)
#---[CICLO]--
while True:
machine.Pin(ROJO, machine.Pin.OUT).off()
machine.Pin(VERDE, machine.Pin.OUT).on()
machine.Pin(verdepeaton, machine.Pin.OUT).off()
machine.Pin(LEDV, machine.Pin.OUT).on()
machine.Pin(ROJOAB, machine.Pin.OUT).on()
machine.Pin(ROJOD, machine.Pin.OUT).on()
machine.Pin(VERDED, machine.Pin.OUT).off()
for x in range (5):
if button.value()==0:
botonc=1
utime.sleep(1)
if botonc == 1:
peaton()
else:
coche()
botonc=0
# Tarea 1: Creación de una aplicación que controle un semáforo simple
# Tarea 2: Agregar un cruce de paso peatonal, en donde el peatón,
# a través de pulsar un botón, solicite se le ceda el paso en el
# siguiente ciclo.
# CUIDADO: no entorpecer el adecuado flujo de automóviles"
# Tarea 4: Crera una aplicación para controlar el sistema de
# semáforos que se encuentra en la esquina de la facultad de Biología
# con Circuito Presidentes.