-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiRelay.py
More file actions
35 lines (26 loc) · 889 Bytes
/
piRelay.py
File metadata and controls
35 lines (26 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
try:
import RPi.GPIO as GPIO
except RuntimeError:
print(
"Error importing RPi.GPIO! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script")
import timecode.con
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(True)
class Relay:
''' Class to handle Relay
Arguments:
relay = string Relay label (i.e. "RELAY1","RELAY2","RELAY3","RELAY4")
'''
relayGpio = {"RELAY1": 19, "RELAY2": 13, "RELAY3": 6, "RELAY4": 5}
def __init__(self, relay):
self.pin = self.relayGpio[relay]
self.relay = relay
GPIO.setup(self.pin, GPIO.OUT)
GPIO.output(self.pin, GPIO.LOW)
def on(self):
print(self.relay + " - ON")
GPIO.output(self.pin, GPIO.HIGH)
def off(self):
print(self.relay + " - OFF")
GPIO.output(self.pin, GPIO.LOW)