Repository navigation
Expand file tree
/
Copy pathLED_System.py
More file actions
168 lines (124 loc) · 4.78 KB
/
Copy pathLED_System.py
File metadata and controls
168 lines (124 loc) · 4.78 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
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
__author__ = 'David Rossiter'
import Image
import ImageDraw
import BicolorMatrix8x8
import time
# Create display instance on default I2C address (0x70) and bus number.
display = BicolorMatrix8x8.BicolorMatrix8x8()
# Alternatively, create a display with a specific I2C address and/or bus.
# display = Matrix8x8.Matrix8x8(address=0x74, busnum=1)
# Initialize the display. Must be called once before using the display.
display.begin()
def led(status):
# Set green forward arrow
if status == "Forward":
# Clear the display buffer.
display.clear()
# First create an 8x8 RGB image.
image = Image.new('RGB', (8, 8))
# Then create a draw instance.
draw = ImageDraw.Draw(image)
# Draw a forwards arrow
draw.line((7, 4, 0, 4), fill=(0, 255, 0))
draw.line((7, 3, 0, 3), fill=(0, 255, 0))
draw.line((3, 0, 0, 3), fill=(0, 255, 0))
draw.line((3, 7, 0, 4), fill=(0, 255, 0))
# Draw the image on the display buffer.
display.set_image(image)
# Draw the buffer to the display hardware.
display.write_display()
# Set green right arrow
elif status == "Right":
# Clear the display buffer.
display.clear()
# First create an 8x8 RGB image.
image = Image.new('RGB', (8, 8))
# Then create a draw instance.
draw = ImageDraw.Draw(image)
# Draw a right arrow
draw.line((4, 7, 4, 0), fill=(0, 255, 0))
draw.line((3, 7, 3, 0), fill=(0, 255, 0))
draw.line((3, 0, 0, 3), fill=(0, 255, 0))
draw.line((4, 0, 7, 3), fill=(0, 255, 0))
# Draw the image on the display buffer.
display.set_image(image)
# Draw the buffer to the display hardware.
display.write_display()
# Set green left arrow
elif status == "Left":
# Clear the display buffer.
display.clear()
# First create an 8x8 RGB image.
image = Image.new('RGB', (8, 8))
# Then create a draw instance.
draw = ImageDraw.Draw(image)
# Draw a left arrow
draw.line((4, 7, 4, 0), fill=(0, 255, 0))
draw.line((3, 7, 3, 0), fill=(0, 255, 0))
draw.line((3, 7, 0, 4), fill=(0, 255, 0))
draw.line((4, 7, 7, 4), fill=(0, 255, 0))
# Draw the image on the display buffer.
display.set_image(image)
# Draw the buffer to the display hardware.
display.write_display()
# Set green reverse arrow
elif status == "Reverse":
# Clear the display buffer.
display.clear()
# First create an 8x8 RGB image.
image = Image.new('RGB', (8, 8))
# Then create a draw instance.
draw = ImageDraw.Draw(image)
# Draw a reverse arrow
draw.line((7, 4, 0, 4), fill=(0, 255, 0))
draw.line((7, 3, 0, 3), fill=(0, 255, 0))
draw.line((4, 7, 7, 4), fill=(0, 255, 0))
draw.line((4, 0, 7, 4), fill=(0, 255, 0))
# Draw the image on the display buffer.
display.set_image(image)
# Draw the buffer to the display hardware.
display.write_display()
# Set green tick to represent mapping complete
elif status == "Complete":
# Clear the display buffer.
display.clear()
# First create an 8x8 RGB image.
image = Image.new('RGB', (8, 8))
# Then create a draw instance.
draw = ImageDraw.Draw(image)
# Draw a forwards arrow
draw.line((6, 5, 1, 0), fill=(0, 255, 0))
draw.line((6, 5, 4, 7), fill=(0, 255, 0))
draw.line((7, 5, 2, 0), fill=(0, 255, 0))
draw.line((7, 5, 5, 7), fill=(0, 255, 0))
draw.line((5, 5, 0, 0), fill=(0, 255, 0))
draw.line((5, 5, 3, 7), fill=(0, 255, 0))
# Draw the image on the display buffer.
display.set_image(image)
# Draw the buffer to the display hardware.
display.write_display()
# Set orange exclaimation mark
elif status == "Halt":
# Clear the display buffer.
display.clear()
# First create an 8x8 RGB image.
image = Image.new('RGB', (8, 8))
# Then create a draw instance.
draw = ImageDraw.Draw(image)
# Draw a forwards arrow
draw.line((4, 4, 0, 4), fill=(255, 255, 0))
draw.line((4, 3, 0, 3), fill=(255, 255, 0))
draw.line((7, 4, 6, 4), fill=(255, 255, 0))
draw.line((7, 3, 6, 3), fill=(255, 255, 0))
# Draw the image on the display buffer.
display.set_image(image)
# Draw the buffer to the display hardware.
display.write_display()
elif status == "Clear":
# Clear the display buffer.
display.clear()
# Write blank buffer to display to clear
display.write_display()
else:
# Print error
print "LED System status does not exist!"