# mPy - shuttle 2 x 3 one wire 2-aspect signals
#    simple linear programming
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-10-24  initial release

from	machine	import	Pin
import	time

# =========================== Hardware set-up =============================

RED   = 0
GREEN = 1

pin_pa0  = 16									# used pin numbers on Esp32s2
pin_pa1  = 18
pin_pa2  = 33
pin_pb0  = 35
pin_pb1  = 37
pin_pb2  = 39

signal_a0 = Pin(pin_pa0, Pin.OUT, value=RED)	# instantiate signal objects in RED
signal_a1 = Pin(pin_pa1, Pin.OUT, value=RED)
signal_a2 = Pin(pin_pa2, Pin.OUT, value=RED)
signal_b0 = Pin(pin_pb0, Pin.OUT, value=RED)
signal_b1 = Pin(pin_pb1, Pin.OUT, value=RED)
signal_b2 = Pin(pin_pb2, Pin.OUT, value=RED)

# ============================= main ============================

while True:
    signal_a0.value(GREEN)						# train departs A
    signal_a1.value(GREEN)
    signal_a2.value(GREEN)
    time.sleep(2)
    signal_a0.value(RED)						# train passes A0
    time.sleep(2)
    signal_a1.value(RED)						# train passes A1
    time.sleep(2)
    signal_a2.value(RED)						# train passes A2, arrives in B
    time.sleep(5)								# train waits in B

    signal_b0.value(GREEN)						# train departs B
    signal_b1.value(GREEN)
    signal_b2.value(GREEN)
    time.sleep(2)
    signal_b0.value(RED)						# train passes B0
    time.sleep(2)
    signal_b1.value(RED)						# train passes B1
    time.sleep(2)
    signal_b2.value(RED)						# train passes B2, arrives in A
    time.sleep(5)								# train waits in A

# ============================== end ===============================
