########################################################################### # Setup code goes below, this is called once at the start of the program: # ########################################################################### import time import machine button = machine.Pin(0) # 0 = pressed relay = machine.Pin(12, machine.Pin.OUT) #relay.on(), relay.off() led = machine.Pin(13, machine.Pin.OUT) #led.value(1) = off, led.value(0) = on pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP) #extra pin on header tx = machine.Pin(1, machine.Pin.IN, machine.Pin.PULL_UP) #tx pin on header #rx = machine.Pin(3, machine.Pin.IN, machine.Pin.PULL_UP) #rx pin on header status = 0 timer = 0 timeout = 30 ################################################################### # Loop code goes inside the loop here, this is called repeatedly: # ################################################################### while True: time.sleep(1.0) #Check Inputs if pin.value(): if tx.value(): status = 0 #Empty else: status = 1 else: if tx.value(): status = 2 else: status = 3 #Full #Set Outputs if status == 0 and timer == 0: print('Turning relay on') relay.on() elif status == 1: print('status = 1') elif status == 2: print('status = 2') elif status == 3: print('Turning relay off') relay.off() timer = 0 else: print('Something when wrong') #Timeout if relay.value(): timer += 1 if timer > timeout: relay.off()