# mPy - shuttle 2 x 3 one wire 2-aspect signals
#    sequencing through a pattern, using library and class
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-10-30  initial release

from	machine	import	Pin
import	time
from	mve_rw2050	import	portA

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

RED   = 0
GREEN = 1

signals   = [Pin(pin_nr, Pin.OUT, value=RED) for pin_nr in portA]
patterns  = ((1, 1, 1, 0, 0, 0), (0, 1, 1, 0, 0, 0), (0, 0, 1, 0, 0, 0), (0, 0, 0, 0, 0, 0),
             (0, 0, 0, 1, 1, 1), (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 0, 1), (0, 0, 0, 0, 0, 0))

# ============================= local ===========================

# delay for dly seconds, print '*' @ 1 Hz and background task @ 10 Hz
def delay(dly):
    for tSec in range(dly):
        for t100mS in range(10):
            pass						# nothing to do for background task
            time.sleep(0.1)
        print('*', end='')

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

class Main:
    
    def __init__(self):
        self.ptrn_last = (0, 0, 0, 0, 0, 0)
        while True:
            for pattern in patterns:
                self.setPattern(pattern)
                delay(2)
            if pattern == (0, 0, 0, 0, 0, 0):	# if train in A or B
                delay(2)


    # set 6 signals according pattern
    def setPattern(self, pattern):
        for signal, aspect, aspect_last in zip(signals, pattern, self.ptrn_last):
            if aspect_last != aspect:
                signal.value(aspect)    
        self.ptrn_last = pattern
            
    
Main()

# ================================= End =====================================

