-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathledplay.py
46 lines (32 loc) · 1008 Bytes
/
ledplay.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
#!/usr/bin/env python
import RPi.GPIO as GPIO
light1 = 18
light2 = 23
light3 = 24
button1 = 10
button2 = 27
button3 = 22
def my_callback(self):
GPIO.output(light1, GPIO.input(button1))
GPIO.output(light2, GPIO.input(button2))
GPIO.output(light3, GPIO.input(button3))
GPIO.setmode(GPIO.BCM)
GPIO.setup(button1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(light1, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(button2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(light2, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(button3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(light3, GPIO.OUT, initial=GPIO.LOW)
GPIO.add_event_detect(button1, GPIO.BOTH, callback=my_callback)
GPIO.add_event_detect(button2, GPIO.BOTH, callback=my_callback)
GPIO.add_event_detect(button3, GPIO.BOTH, callback=my_callback)
run = 1
while (run != 0):
try:
pass
except KeyboardInterrupt:
GPIO.cleanup()
run = 0
print 'KeyboardInterrupt caught'
break
print 'EXITED!'