Add relay drivers
This commit is contained in:
parent
4a8d130c72
commit
ae30c39954
41
rpiserver/relays.py
Normal file
41
rpiserver/relays.py
Normal file
|
@ -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()
|
Loading…
Reference in New Issue
Block a user