# mPy - Application controled by external USB commands
#    True is green led, other is red led
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2026-03-11  initial release

from	machine	import	Pin
from	drivers	import	nbInput

# ======================== Main ==========================

class Main:
    
    # setup and main loop
    def __init__(self):
        try:
            self.led_red      = Pin(26, Pin.OUT, value=1)		# led Red   on pin 26
            self.led_green    = Pin(27, Pin.OUT, value=0)		# led green on pin 27
            self.green_active = True
            while True:
                self.taskMonitor()
                self.taskLeds()
        finally:
            self.led_red(0)
            self.led_green(0)
            
        
    # monitor and interpret incoming USB commands
    def taskMonitor(self):
        if s_rx := nbInput():
            print('s_rx:', s_rx)
            self.green_active = s_rx == 'True'
        
        
    # synchronise leds with global pars
    def taskLeds(self):
        self.led_green(self.green_active)
        self.led_red(not self.green_active)
        
        
Main()

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