You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
701 B
41 lines
701 B
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()
|
|
|