-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiRelay.py
More file actions
37 lines (27 loc) · 797 Bytes
/
PiRelay.py
File metadata and controls
37 lines (27 loc) · 797 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
36
37
#!/usr/bin/python
# Library for PiRelay V2
# Developed by: SB Components
# Author: Satyam
# Project: PiRelay-V2
# Python: 3.7.3
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
class Relay:
''' Class to handle Relay
Arguments:
relay = string Relay label (i.e. "RELAY1","RELAY2","RELAY3","RELAY4")
'''
relaypins = {"RELAY1":35, "RELAY2":33, "RELAY3":31, "RELAY4":29}
def __init__(self, relay):
self.pin = self.relaypins[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)