# mPy - connect input to pulse output using IRQ
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-10-31  initial release

from	machine		import	Pin
import	time
from	mve_rw2050	import	portA, portB

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

RED   = 0
GREEN = 1

pin_out = portA[0]
pin_inp = portB[0]
out		= Pin(pin_out, Pin.OUT, value=RED)
inp     = Pin(pin_inp, Pin.IN, Pin.PULL_UP)

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

class Main:

    # instantiate required objects an start main loop
    def __init__(self):
        self.pulse = 0				# pulse length on out
        inp.irq(self.onInp, Pin.IRQ_FALLING)
        self.task()
        

    def onInp(self, pin):
        out.value(1)
        self.pulse = 20				# set pulse to 2 sec
        
        
    # main loop
    def task(self):
        while True:
            for _ in range(10):
                if self.pulse:			# do @ 100 mS
                    self.pulse -= 1
                    if self.pulse == 0: out.value(0)
                time.sleep(0.1)
            print('*', end='')			# do @ 1 sec
 
 
Main()

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