This repository has been archived by the owner on Jan 18, 2019. It is now read-only.
forked from vbarekos/astro-pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraffic_lights.py
86 lines (67 loc) · 1.88 KB
/
traffic_lights.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
from sense_hat import SenseHat
import time
s = SenseHat()
s.low_light = True
g = (0, 255, 0) # Πράσινο
r = (255, 0, 0) # Red colour
o = (255,165, 0) # Orange colour
n = (0, 0, 0) # Μαύρο - σβηστά pixels
s.set_rotation(180)
green_sign = [
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, g, g, g, g, n, n,
n, n, g, g, g, g, n, n,
]
orange_sign = [
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, o, o, o, o, n, n,
n, n, o, o, o, o, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
]
red_sign = [
n, n, r, r, r, r, n, n,
n, n, r, r, r, r, n, n,
n, n, n, n, n,
n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
n, n, n, n, n, n, n, n,
]
s.clear()
while True:
for event in s.stick.get_events():
# Events when key is pressed (Enter)
if event.direction == "middle":
s.set_pixels(green_sign)
time.sleep(2)
s.set_pixels(orange_sign)
time.sleep(2)
s.set_pixels(red_sign)
time.sleep(2)
s.clear()
# Events when LEFT key is pressed
if event.direction == "left":
s.set_pixels(red_sign)
time.sleep(2)
s.clear()
# Events when RIGHT key is pressed
if event.direction == "right":
s.set_pixels(green_sign)
time.sleep(2)
s.clear()
# Events when UP or DOWN key is pressed
if (event.direction == "up") | (event.direction == "down"):
s.set_pixels(orange_sign)
time.sleep(2)
s.clear()