import machine
import utime
from picozero import Speaker
RED_A = machine.Pin(10,machine.Pin.OUT)
AMBER_A = machine.Pin(7,machine.Pin.OUT)
GREEN_A = machine.Pin(5,machine.Pin.OUT)
RED_B = machine.Pin(21,machine.Pin.OUT)
AMBER_B = machine.Pin(26,machine.Pin.OUT)
GREEN_B = machine.Pin(28,machine.Pin.OUT)
speaker = Speaker(0)
START_GREEN = machine.Pin(15,machine.Pin.IN,machine.Pin.PULL_UP)
STOP_RED = machine.Pin(16,machine.Pin.IN,machine.Pin.PULL_UP)
def int_handler(pin):
STOP_RED.irq(handler = None)
print("interrupt detected!")
RED_A.value(1)
AMBER_A.value(0)
GREEN_A.value(0)
RED_B.value(1)
AMBER_B.value(0)
GREEN_B.value(0)
speaker.on()
while True:
if START_GREEN() == 0:
utime.sleep(0.25)
break
else:
pass
speaker.off()
print("interrupt exited!")
STOP_RED.irq(handler = int_handler)
STOP_RED.irq(trigger = machine.Pin.IRQ_FALLING, handler = int_handler)
while True:
if START_GREEN() == 0:
utime.sleep(0.25)
while True:
##################### step 1
RED_A.value(1)
AMBER_A.value(0)
GREEN_A.value(0)
RED_B.value(0)
AMBER_B.value(0)
GREEN_B.value(1)
if START_GREEN() == 0:
utime.sleep(0.25)
continue
utime.sleep(5)
if START_GREEN() == 0:
utime.sleep(0.25)
continue
####################### step 2
RED_A.value(1)
AMBER_A.value(0)
GREEN_A.value(0)
RED_B.value(0)
AMBER_B.value(1)
GREEN_B.value(0)
if START_GREEN() == 0:
utime.sleep(0.25)
continue
utime.sleep(2)
if START_GREEN() == 0:
utime.sleep(0.25)
continue
####################### step 3
RED_A.value(0)
AMBER_A.value(0)
GREEN_A.value(1)
RED_B.value(1)
AMBER_B.value(0)
GREEN_B.value(0)
if START_GREEN() == 0:
utime.sleep(0.25)
continue
utime.sleep(5)
if START_GREEN() == 0:
utime.sleep(0.25)
continue
###################### step 4 and back to step 1
RED_A.value(0)
AMBER_A.value(1)
GREEN_A.value(0)
RED_B.value(1)
AMBER_B.value(0)
GREEN_B.value(0)
if START_GREEN() == 0:
utime.sleep(0.25)
continue
utime.sleep(2)
if START_GREEN() == 0:
utime.sleep(0.25)
continue