-
Notifications
You must be signed in to change notification settings - Fork 0
/
HW_1.py
40 lines (34 loc) · 1.05 KB
/
HW_1.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
import RPi.GPIO as GPIO
import time
l = {"g": 2, "y": 3, "r": 4}
r = {"g": 16, "y": 20, "r": 21}
def main():
GPIO.setmode(GPIO.BCM)
for key, value in l.items():
GPIO.setup(value, GPIO.OUT)
GPIO.output(value, False)
for key, value in r.items():
GPIO.setup(value, GPIO.OUT)
GPIO.output(value, False)
try:
gside = l
rside = r
while True:
GPIO.output(rside["r"], True)
GPIO.output(gside["r"], True)
time.sleep(1)
GPIO.output(gside["r"], False)
GPIO.output(gside["g"], True)
time.sleep(10)
GPIO.output(gside["g"], False)
for i in range(5):
GPIO.output(gside["y"], True)
time.sleep(0.5)
GPIO.output(gside["y"], False)
time.sleep(0.5)
tmp = gside
gside = rside
rside = tmp
except KeyboardInterrupt:
GPIO.cleanup()
main()