-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpio-with-button
More file actions
83 lines (69 loc) · 1.16 KB
/
gpio-with-button
File metadata and controls
83 lines (69 loc) · 1.16 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
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
#import
import RPi.GPIO as GPIO
import time
#setup GPIO
green=4
yellow=17
red=27
blue=22
button=18
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(green,GPIO.OUT)
GPIO.setup(yellow,GPIO.OUT)
GPIO.setup(red,GPIO.OUT)
GPIO.setup(blue,GPIO.OUT)
GPIO.setup(button,GPIO.IN)
def LEDon(pin):
GPIO.output(pin,GPIO.HIGH)
return
def LEDoff(pin):
GPIO.output(pin,GPIO.LOW)
return
def blink(pin):
LEDon(pin)
time.sleep(.5)
LEDoff(pin)
time.sleep(.5)
return
def fastblink(pin):
LEDon(pin)
time.sleep(.1)
LEDoff(pin)
time.sleep(.1)
return
def cycleall():
blink(green)
blink(yellow)
blink(red)
blink(blue)
return
def pattern1():
LEDon(green)
LEDon(red)
LEDoff(yellow)
LEDoff(blue)
time.sleep(.5)
LEDoff(green)
LEDoff(red)
LEDon(yellow)
LEDon(blue)
time.sleep(.5)
LEDoff(green)
LEDoff(yellow)
LEDoff(red)
LEDoff(blue)
return
button_input = GPIO.input(button)
running = True
buttonmode = False
while running:
if (GPIO.input(button)):
print("Running!")
for i in range(0,5):
fastblink(green)
fastblink(yellow)
fastblink(red)
fastblink(blue)
#cleanup
GPIO.cleanup