-
Notifications
You must be signed in to change notification settings - Fork 1
/
pinCheck_test.py
82 lines (59 loc) · 1.5 KB
/
pinCheck_test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Adafruit_BBIO.GPIO as gpio
from time import sleep
from collections import OrderedDict as od
def setup_pin_list(start, stop):
pins = []
base_name = "P8_"
for x in range(start, stop):
if x < 10:
pins.append(base_name + '0' + str(x))
else:
pins.append(base_name + str(x))
print(pins)
return pins
def setPinsGPIOin(pins):
pinDict = od()
for pin in pins:
gpio.setup(pin, gpio.IN)
pinDict[str(pin)] = str(gpio.input(pin))
print pinDict
def setupFallDetect(knob):
try:
gpio.add_event_detect(knob, gpio.FALLING)
except:
print('error')
print(knob + " : " + str(gpio.input(knob)))
def isMoving(knob):
return gpio.event_detected(knob)
def check_all(pins):
pinDict = od()
for pin in pins:
pinDict[pin] = gpio.input(pin)
print(pinDict)
def detectKnob(knob):
running = True
while running == True:
if isMoving(knob) == True:
print('detected')
userInput = raw_input('keep checking?')
if userInput == 'n':
running = False
else:
running = True
else:
print('checking...')
sleep(.1)
def main():
knob = 'P8_07'
pins = setup_pin_list(7,20)
setPinsGPIOin(pins)
check_all(pins)
setupFallDetect(knob)
input = raw_input('check?')
if input == 'y':
pass
else:
exit()
detectKnob(knob)
if __name__ == "__main__":
main()