-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathledb.py
More file actions
executable file
·58 lines (48 loc) · 962 Bytes
/
ledb.py
File metadata and controls
executable file
·58 lines (48 loc) · 962 Bytes
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
#!/usr/bin/python
# LED and Buton test ledb.py
import sys
import RPi.GPIO as GPIO
from time import sleep
blue = 23
red = 21
green = 19
bgreen = 15
bwhite = 13
leds = (blue, red, green, bgreen, bwhite)
ledn = ("Blue","Red","Green","Bright Green","Bright White")
change = 22
end = 18
i = 0
GPIO.setmode(GPIO.BOARD)
for pin in leds:
GPIO.setup(pin, GPIO.OUT)
GPIO.setup(change, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(end, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def main():
global i
while True:
if not (GPIO.input(change)):
change_led()
if not (GPIO.input(end)):
cleanup()
ledon(leds[i])
sleep(.25)
ledoff(leds[i])
sleep(.25)
def ledon(pin):
GPIO.output(pin, 1)
def ledoff(pin):
GPIO.output(pin, 0)
def change_led():
global i
print "Change button was pushed"
i=i+1
if i == len(leds):
i = 0
print "Color is now" , ledn[i]
def cleanup():
print("end pushed")
GPIO.cleanup()
sys.exit()
if __name__ == "__main__":
main()