diff --git a/rpiserver/relays.py b/rpiserver/relays.py new file mode 100644 index 0000000..45c9f46 --- /dev/null +++ b/rpiserver/relays.py @@ -0,0 +1,41 @@ +import asyncio +import RPi.GPIO as GPIO + +RELAY1 = 4 +RELAY2 = 22 +RELAY3 = 6 +RELAY4 = 26 + +RELAY_ON = True +RELAY_OFF = False + +RELAYS = [RELAY1, RELAY2, RELAY3, RELAY4] + +def set_relay(r, state): + GPIO.output(r, state) + +def all_off(): + for r in RELAYS: + set_relay(r, RELAY_OFF) + +def init_relays(): + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + + for r in RELAYS: + GPIO.setup(r, GPIO.OUT) + + all_off() + +async def test(): + for r in RELAYS: + set_relay(r, RELAY_ON) + await asyncio.sleep(0.5) + set_relay(r, RELAY_OFF) + +if __name__ == '__main__': + init_relays() + + loop = asyncio.get_event_loop() + loop.run_until_complete(test()) + loop.close()