-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rpio.py
88 lines (51 loc) · 2.21 KB
/
test_rpio.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
83
84
85
86
87
import RPIO
import time
#debounce time varaible (None -> XXX miliseconds typical between 10 and 200)
tb=None
#eliminating warnings
RPIO.setwarnings(False)
def call_P1(gpio,val):
print "P1-4"
RPIO.del_interrupt_callback(4)
RPIO.add_interrupt_callback(25,call_C1,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
def call_C1(gpio_id,val):
print "C1-25"
RPIO.del_interrupt_callback(25)
RPIO.add_interrupt_callback(4,call_P1,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
def call_P2(gpio,val):
print "P2-17"
RPIO.del_interrupt_callback(17)
RPIO.add_interrupt_callback(18,call_C2,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
def call_C2(gpio_id,val):
print "C2-18"
RPIO.del_interrupt_callback(18)
RPIO.add_interrupt_callback(17,call_P2,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
def call_P3(gpio,val):
print "P3-21"
RPIO.del_interrupt_callback(21)
RPIO.add_interrupt_callback(22,call_C3,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
def call_C3(gpio_id,val):
print "C3-22"
RPIO.del_interrupt_callback(22)
RPIO.add_interrupt_callback(21,call_P3,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
def call_P4(gpio,val):
print "P4-7"
RPIO.del_interrupt_callback(7)
RPIO.add_interrupt_callback(8,call_C4,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
def call_C4(gpio_id,val):
print "C4-8"
RPIO.del_interrupt_callback(8)
RPIO.add_interrupt_callback(7,call_P4,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=tb)
RPIO.add_interrupt_callback(4,call_P1,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=100)
RPIO.add_interrupt_callback(17,call_P2,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=100)
RPIO.add_interrupt_callback(21,call_P3,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=100)
RPIO.add_interrupt_callback(7,call_P4,edge='falling',pull_up_down=RPIO.PUD_UP,debounce_timeout_ms=100)
RPIO.wait_for_interrupts(threaded=True)
print "Ready... Let's play the piano..."
try:
while True:
time.sleep(0.1)
except KeyboardInterrupt:
RPIO.stop_waiting_for_interrupts()
RPIO.cleanup()
print "FUCKING ERROR ON EXIT..."