import time
import rp2
from machine import Pin, Timer
time.sleep(0.1) # Wait for USB to become ready
dictREL = {
"R1": Pin(21, Pin.OUT),
"R2": Pin(20, Pin.OUT),
"R3": Pin(19, Pin.OUT),
"R4": Pin(18, Pin.OUT)
}
dictSEN = {
1: Pin(2, Pin.IN),
2: Pin(3, Pin.IN),
3: Pin(4, Pin.IN),
4: Pin(5, Pin.IN)
}
def pohyb(_pin):
print(_pin, _pin.value())
if _pin.value() == 1 and _pin == dictSEN[1]:
dictREL["R1"].off()
elif _pin.value() == 1 and _pin == dictSEN[2]:
dictREL["R2"].off()
elif _pin.value() == 1 and _pin == dictSEN[3]:
dictREL["R3"].off()
elif _pin.value() == 1 and _pin == dictSEN[4]:
dictREL["R4"].off()
dictSEN[1].irq(trigger=Pin.IRQ_RISING, handler=pohyb)
dictSEN[2].irq(trigger=Pin.IRQ_RISING, handler=pohyb)
dictSEN[3].irq(trigger=Pin.IRQ_RISING, handler=pohyb)
dictSEN[4].irq(trigger=Pin.IRQ_RISING, handler=pohyb)
dictREL["R1"].on()
dictREL["R2"].on()
dictREL["R3"].on()
dictREL["R4"].on()
while True:
time.sleep(100)
'''
while True:
cmd = input("> ")
if cmd == "exit":
break
print("\n.The end")
sys.exit()
'''