-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch.py
41 lines (33 loc) · 1.02 KB
/
switch.py
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
38
39
import RPi.GPIO as GPIO
class Switch:
"""
A SolidStateSwitch, controlled by the GPIO pins.
Attributes:
cool_pin: The pin number (GPIO.board) on which the cool switch is connected
Requirements:
RPi.GPIO imported as GPIO
"""
def __init__(self, cool_pin):
"""
:param pin: Connected GPIO pin, according to GPIO.board
"""
self.cool_pin = cool_pin
# Set board mode (for pin numbering)
GPIO.setmode(GPIO.BOARD)
# setup=0 (0 is output) initial=0; sets pin to low.
GPIO.setup(self.cool_pin, 0, initial=0)
def status(self):
"""
:Returns: True when on, False when off
"""
return True if GPIO.input(self.cool_pin) == 1 else False
def off(self):
"""
Sets the GPIO output of the cool pin to LOW
"""
return GPIO.output(self.cool_pin, 0)
def on(self):
"""
Sets the GPIO output of the cool pin to HIGH
"""
return GPIO.output(self.cool_pin, 1)