-
Notifications
You must be signed in to change notification settings - Fork 3
/
gpio.py
45 lines (34 loc) · 1.5 KB
/
gpio.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
40
41
42
43
44
################################################################################
# GPIO Manipulator
################################################################################
################################################################################
# IMPORTS
################################################################################
################################################################################
# CLASSES
################################################################################
class gpio():
class Direction():
Input = "in"
Output = "out"
def __init__(self, pin):
self.path = "/sys/class/gpio/gpio" + str(pin) + "/"
try:
with open("/sys/class/gpio/export", "w") as f:
f.write(str(pin))
except IOError:
pass
def set_direction(self, dir):
if dir != self.Direction.Input and dir != self.Direction.Output:
return
with open(self.path + "direction", "w") as dir_f:
dir_f.write(dir)
def set_value(self, val):
with open(self.path + "value", "w") as value_f:
value_f.write(str(val))
################################################################################
# VARIABLES
################################################################################
################################################################################
# FUNCTIONS
################################################################################