-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPIO.py
More file actions
43 lines (36 loc) · 1.31 KB
/
Copy pathGPIO.py
File metadata and controls
43 lines (36 loc) · 1.31 KB
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
import RPi.GPIO as GPIO
def init():
GPIO.setmode(GPIO.BCM) #use broadcom pin numbers (label on pins not physical pin number)
GPIO.setwarnings(True)
def setPin(pin, direction, PUD):
if PUD == 'NONE':
GPIO.setup(pin, setDirection(direction))
else:
GPIO.setup(pin, setDirection(direction), pull_up_down = setPUD(PUD))
def setDirection(direction): #not meant to be used outside this module
if direction == 'OUT':
return GPIO.OUT
elif direction == 'IN':
return GPIO.IN
else:
print ("Error in direction declaration, expected either: 'IN' or 'OUT'")
return
def setPUD(PUD): #not meant to be used outside this module
if PUD == 'UP':
return GPIO.PUD_UP
elif PUD == 'DOWN':
return GPIO.PUD_DOWN
else:
print ("Error in PUD declaration, expected either: 'NONE', 'UP', or 'DOWN'")
return
def write(pin, output):
if output == 'HIGH':
GPIO.output(pin, GPIO.HIGH)
elif output == 'LOW':
GPIO.output(pin, GPIO.LOW)
else:
GPIO.output(pin, output) #values accepted are 1, 0, True, False - RPi.GPIO will send an error if it isn't
def read(pin): #returns data read at pin - 1 or 0
return GPIO.input(pin)
def closeGPIO():
GPIO.cleanup()