-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtron_digits.py
More file actions
364 lines (362 loc) · 10.8 KB
/
tron_digits.py
File metadata and controls
364 lines (362 loc) · 10.8 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# In this file you'll find functions which print big tron font digits
# each digit is a 2 x 2 characters object printed at on of the 8 (or 10) places.
# It is understood that each place numbered from 0 to 7 and mapped on x axis like this:
# characters 0, 1 - place 0
# characters 2, 3 - place 1
# characters 4, 5 - place 2
# characters 6, 7 - place 3
# characters 8, 9 - place 4
# characters 10, 11 - place 5
# characters 12, 13 - place 6
# characters 14, 15 - place 7
#
# The seed_eeprom function should be used only once, at the moment of first using the code
# with this library on your device. This way we preserve writing cycles of eeprom bulit into the
# character lcd's controler chip.
#
# Functions tron_0, tron_1, tron_2, ..., tron_9 are resoinsible for printing repectively
# digit 0, 1, 2, ..., 9.
# They all require _position argument which the place number briefly described at the top.
#
# This module contains two files:
# tron_digits.py and tron_chars.py.
#
# The second file is a dependcy of the first one - contains bytearray definitions of small individual characters
# used to construct big 2 x 2 digits which are printed to the lcd by the functions from this module.
#
# This module also assumes you're using a module driver to operate the charcter lcd very similar to the way it's
# done here: https://github.com/open-sorcerer64/i2c-lcd-pico.
# Especially that it uses move_to, put_char and custom_char functions.
# From the technical poimt of view the _lcd argument of initialising the class from this module is an instance
# of the charcter lcd operation class used by the driver module of your choice and must provide functions mentioned
# above.
#
# Furtheromore there is an example code in tron_example.py file provided with an example usage of this module.
#
# Have Fun!
#
# LEGAL NOTICE
#
# The author of this library - ToMiDevelop makes it publicly availalabe based on the MIT license.
#
# License of this module:
#
# Copyright (c) 2024 ToMiDevelop
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# CREDITS
#
# All credits connected with the font implemented here and idea of programing it with the usage
# of character dislays go to
# upiir: https://github.com/upiir/character_display_big_digits
#
# All for made publicly available in pointed upiir's repository is also published on MIT license.
# More details can be found in upiir's repository.
from tron_chars import font_tron
class Tron:
def __init__(self, _lcd):
self.lcd = _lcd
self.empty = font_tron.empty
self.full = font_tron.full
#
def seed_eeprom(self):
custom_chars = [
font_tron.c0,
font_tron.c1,
font_tron.c2,
font_tron.c3,
font_tron.c4,
font_tron.c5,
font_tron.c6,
font_tron.c7
]
for i, char in enumerate(custom_chars):
self.lcd.custom_char(i, char)
#
def tron_0 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(4))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(2))
self.lcd.move_to(x,1)
self.lcd.putchar(chr(7))
self.lcd.move_to(x+1,1)
self.lcd.putchar(self.full)
#
def tron_1 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(self.empty)
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(5))
self.lcd.move_to(x,1)
self.lcd.putchar(self.empty)
self.lcd.move_to(x+1,1)
self.lcd.putchar(chr(5))
#
def tron_2 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(0))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(2))
self.lcd.move_to(x,1)
self.lcd.putchar(chr(3))
self.lcd.move_to(x+1,1)
self.lcd.putchar(chr(6))
#
def tron_3 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(0))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(2))
self.lcd.move_to(x,1)
self.lcd.putchar(chr(1))
self.lcd.move_to(x+1,1)
self.lcd.putchar(self.full)
#
def tron_4 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(7))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(1))
self.lcd.move_to(x,1)
self.lcd.putchar(self.empty)
self.lcd.move_to(x+1,1)
self.lcd.putchar(chr(5))
#
def tron_5 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(3))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(6))
self.lcd.move_to(x,1)
self.lcd.putchar(chr(6))
self.lcd.move_to(x+1,1)
self.lcd.putchar(self.full)
#
def tron_6 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(3))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(6))
self.lcd.move_to(x,1)
self.lcd.putchar(chr(3))
self.lcd.move_to(x+1,1)
self.lcd.putchar(self.full)
#
def tron_7 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(0))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(2))
self.lcd.move_to(x,1)
self.lcd.putchar(self.empty)
self.lcd.move_to(x+1,1)
self.lcd.putchar(chr(5))
#
def tron_8 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(3))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(2))
self.lcd.move_to(x,1)
self.lcd.putchar(chr(3))
self.lcd.move_to(x+1,1)
self.lcd.putchar(self.full)
#
def tron_9 (self, _position):
x = 0
if _position == 0:
x = 0
if _position == 1:
x = 2
if _position == 2:
x = 4
if _position == 3:
x = 6
if _position == 4:
x = 8
if _position == 5:
x = 10
if _position == 6:
x = 12
if _position == 7:
x = 14
self.lcd.move_to(x,0)
self.lcd.putchar(chr(3))
self.lcd.move_to(x+1,0)
self.lcd.putchar(chr(2))
self.lcd.move_to(x,1)
self.lcd.putchar(self.empty)
self.lcd.move_to(x+1,1)
self.lcd.putchar(chr(2))
#