-
Notifications
You must be signed in to change notification settings - Fork 1
/
all.py
182 lines (147 loc) · 3.72 KB
/
all.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import time
from time import sleep
import os
import subprocess
import RPi.GPIO as GPIO
GPIO.setmode (GPIO.BCM) #BCM uses the GPIO numbers while BOARD uses the actual pin number
GPIO.setwarnings (False)
red = 10
green = 9
blue = 11
mosfet = 22
button1 = 17
button2 = 18
button3 = 27
in4 = 4
in14 = 14
in15 = 15
in7 = 7
in21 = 21
in20 = 20
in19 = 19
in13 = 13
in12 = 12
GPIO.setup(red,GPIO.OUT)
GPIO.setup(green,GPIO.OUT)
GPIO.setup(blue,GPIO.OUT)
GPIO.setup(mosfet,GPIO.OUT)
GPIO.setup(button1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(button2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(button3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in14, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in7, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in21, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in20, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in19, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in13, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(in12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print "*~*~* Start testing LEDs *~*~*"
print ""
print "Green LED on"
GPIO.output(green,GPIO.HIGH)
time.sleep(2)
print "Green LED off"
GPIO.output(green,GPIO.LOW)
print "Red LED on"
GPIO.output(red,GPIO.HIGH)
time.sleep(2)
print "Red LED off"
GPIO.output(red,GPIO.LOW)
print "Blue LED on"
GPIO.output(blue,GPIO.HIGH)
time.sleep(2)
print "Blue LED off"
GPIO.output(blue,GPIO.LOW)
print ""
print "Finished testing LEDs!"
print ""
print "*~*~* Start testing MOSFET *~*~*"
print ""
print "MOSFET on"
GPIO.output(mosfet,GPIO.HIGH)
time.sleep(2)
print "MOSFET off"
GPIO.output(mosfet,GPIO.LOW)
print ""
print "Finished testing MOSFET!"
print ""
print "*~*~* Start testing RTC *~*~*"
print ""
subprocess.call(["sudo", "hwclock", "--systohc"])
subprocess.call(["sudo", "hwclock", "--verbose", "-r"])
print ""
print "Finished testing RTC!"
print ""
print "*~*~* Starting button tests *~*~*"
print ""
print "Waiting for button 1 press..."
while GPIO.input(button1) == False:
time.sleep(0.1)
print "Button 1 pressed!"
print ""
print "Waiting for button 2 press..."
while GPIO.input(button2) == False:
time.sleep(0.1)
print "Button 2 pressed!"
print ""
print "Waiting for button 3 press..."
while GPIO.input(button3) == False:
time.sleep(0.1)
print "Button 3 pressed!"
print ""
print "Finished testing buttons!"
print ""
print "*~*~* Start testing GPIO inputs *~*~*"
print ""
print "Waiting for input on GPIO4"
while (GPIO.input(in4) == False):
time.sleep(0.1)
print "Input on GPIO 4 detected"
print ""
print "Waiting for input on GPIO14"
while (GPIO.input(in14) == False):
time.sleep(0.1)
print "Input on GPIO 14 detected"
print ""
print "Waiting for input on GPIO15"
while (GPIO.input(in15) == False):
time.sleep(0.1)
print "Input on GPIO 15 detected"
print ""
print "Waiting for input on GPIO7"
while (GPIO.input(in7) == False):
time.sleep(0.1)
print "Input on GPIO 7 detected"
print ""
print "Waiting for input on GPIO21"
while (GPIO.input(in21) == False):
time.sleep(0.1)
print "Input on GPIO 21 detected"
print ""
print "Waiting for input on GPIO20"
while (GPIO.input(in20) == False):
time.sleep(0.1)
print "Input on GPIO 20 detected"
print ""
print "Waiting for input on GPIO19"
while (GPIO.input(in19) == False):
time.sleep(0.1)
print "Input on GPIO 19 detected"
print ""
print "Waiting for input on GPIO13"
while (GPIO.input(in13) == False):
time.sleep(0.1)
print "Input on GPIO 13 detected"
print ""
print "Waiting for input on GPIO12"
while (GPIO.input(in12) == False):
time.sleep(0.1)
print "Input on GPIO 12 detected"
print ""
print "Finished testing inputs!"
print ""
print "Exiting... goodbye!"
print ""
GPIO.cleanup()