-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathartvfd.lua
executable file
·416 lines (352 loc) · 8.59 KB
/
artvfd.lua
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
--------------------------------------------------------------------------------
--
-- Some art effects to test eLua VFD module on IV-18 tubes
--
-- More info @ www.eluaproject.net
--
-- Dado Sutter, Fernando Araújo, Marcelo Politzer, Téo Benjamin
--
-- Fev 2010
--
--------------------------------------------------------------------------------
require("vfd")
vfd.init()
-- Blink all segments of all digits
function blinkall()
local k
dly = 160000
repeat
vfd.setall()
tmr.delay( 1, dly )
vfd.clear()
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
end
-- Wide dashes going up & down
function art1()
local k
dly = 100000
repeat
for i = 0, 7 do
vfd.set( 0x60, bit.bit( i ) )
tmr.delay( 1, dly )
end
for i = 7, 1, -1 do
vfd.set( 0x60, bit.bit( i ) )
tmr.delay( 1, dly )
end
vfd.clear()
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
end
-- Wide dashes going up and paralell dashes comming down
function art2()
local k
dly = 100000
repeat
for i = 0, 7 do
vfd.set( 0x60, bit.bit( i ) )
tmr.delay( 1, dly )
end
vfd.set( 0x02, 0x100 )
tmr.delay( 1, dly )
for i = 6, 1, -1 do
vfd.set( 0x90, bit.bit( i ) )
tmr.delay( 1, dly )
end
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- As art2() but digits are kept lit while going up or down
function art3()
local v
local k
dly = 100000
repeat
v = 0
for i = 0, 7 do
v = bit.bor( bit.bit( i ), v )
vfd.set( 0x60, v )
tmr.delay( 1, dly )
end
v = 0
for i = 7, 0, -1 do
v = bit.bor( bit.bit( i ), v )
vfd.set( 0x90, v )
tmr.delay( 1, dly )
end
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- Vertical dashes dancing
function art4()
local k
dly = 200000
repeat
vfd.set( 0x02, 0x55 )
tmr.delay( 1, dly )
vfd.set( 0x02, 0xAA )
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- A dash going all arround the digits' edges
function art5()
local k
dly = 100000
repeat
for i = 0, 7 do
vfd.set( 0x10, bit.bit( i ) )
tmr.delay( 1, dly )
end
vfd.set( 0x08, 0x80 )
tmr.delay( 1, dly )
vfd.set( 0x04, 0x80 )
tmr.delay( 1, dly )
for i = 7, 0, -1 do
vfd.set( 0x80, bit.bit( i ) )
tmr.delay( 1, dly )
end
vfd.set( 0x40, 0x01 )
tmr.delay( 1, dly )
vfd.set( 0x20, 0x01 )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- A dash going all arround the digits' edges and centers
function art6()
local k
dly = 100000
repeat
for i = 0, 7 do -- go up on left
vfd.set( 0x10, bit.bit( i ) )
tmr.delay( 1, dly )
end
vfd.set( 0x08, 0x80 ) -- go right 1 on up
tmr.delay( 1, dly )
for i = 7, 0, -1 do -- go down on middle
vfd.set( 0x02, bit.bit( i ) )
tmr.delay( 1, dly)
end
vfd.set( 0x40, 0x01 ) -- go right 2 on bottom
tmr.delay( 1, dly )
for i = 0, 7 do -- go up on right
vfd.set( 0x80, bit.bit( i ) )
tmr.delay( 1, dly )
end
vfd.set( 0x04, 0x80 ) -- go left 2 on up
tmr.delay( 1, dly )
for i = 7, 0, -1 do -- go down on middle
vfd.set( 0x02, bit.bit( i ) )
tmr.delay( 1, dly)
end
vfd.set( 0x20, 0x01 ) -- go left 1 on bottom
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- Show simultaneously each possible segment in a different digit
function art7()
repeat
for i = 0, 7 do
vfd.set( bit.bit(i), bit.bit(i) )
end
vfd.set ( 0x03, 0x100 )
k = term.getchar( term.NOWAIT )
until k == term.KC_ESC
vfd.clear()
end
-- Bubbles going "up" in random side positions
function bubble1()
local k
local t = { 0x3A, 0xC6 }
-- bl = 0x3A -- bubble left, the lower round of a digit
-- br = 0xC6 -- bubble right, the upper round of a digit
dly = 80000
repeat
for i = 0, 7 do
vfd.set( t[ math.random( 1, 2 ) ], bit.bit( i ) )
tmr.delay( 1, dly )
end
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- Bubles on random sides and on random digit positions
function bubble2()
local k
local t = { 0x3A, 0xC6 }
-- bl = 0x3A -- bubble left, the lower round of a digit
-- br = 0xC6 -- bubble right, the upper round of a digit
dly = 200000
repeat
vfd.set( t[ math.random( 1, 2 ) ], math.random( 1, 0xFF ) )
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- Random seg pattern in a random digit position
function random1()
local k
dly = 400000
repeat
vfd.set( math.random( 0, 0xFF ), bit.bit( math.random( 0, 7 ) ) )
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- Random seg patterns in random digit positions
function random2()
local k
dly = 400000
repeat
vfd.set( math.random( 0, 0xFF ), math.random( 0, 0x1FF ) )
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- One dot, bouncing between the edges
function dots1()
local k
dly = 100000
repeat
for i = 0, 7 do
vfd.set( 0x01, bit.bit( i ) )
tmr.delay( 1, dly )
end
for i = 8, 1, -1 do
vfd.set( 0x01, bit.bit( i ) )
tmr.delay( 1, dly )
end
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- One dot at a random digit position
function dots2()
local k
dly = 200000
repeat
vfd.set( 0x01, bit.bit( math.random( 0, 8 ) ) )
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- Random number of dots at random digits positions
function dots3()
local k
dly = 200000
repeat
vfd.set( 0x01, math.random( 0, 0x1FF ) )
tmr.delay( 1, dly )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- eLua written statically in the middle
function elua1()
local k
local e = 0x9E
local l = 0x1C
local u = 0x7C
local a = 0xEE
repeat
vfd.set( e, 0x20 )
vfd.set( l, 0x10 )
vfd.set( u, 0x08 )
vfd.set( a, 0x04 )
k = term.getchar( term.NOWAIT )
handlekbd( k )
until k == term.KC_ESC
vfd.clear()
end
-- eLua scrolls in both directions
function elua2()
local k
local e = 0x9E
local l = 0x1C
local u = 0x7C
local a = 0xEE
repeat
for i = 3, 6 do
for j = 1, 30 do
vfd.set( e, bit.bit( i ) )
vfd.set( l, bit.bit( i - 1 ) )
vfd.set( u, bit.bit( i - 2 ) )
vfd.set( a, bit.bit( i - 3 ) )
end
k = term.getchar( term.NOWAIT )
handlekbd( k )
end
for i = 7, 4, -1 do
for j = 1, 30 do
vfd.set( e, bit.bit( i ) )
vfd.set( l, bit.bit( i - 1 ) )
vfd.set( u, bit.bit( i - 2 ) )
vfd.set( a, bit.bit( i - 3 ) )
end
k = term.getchar( term.NOWAIT )
handlekbd( k )
end
until k == term.KC_ESC
vfd.clear()
end
-- Letters comming one by one from right to left
function elua3()
local k
local t = { 0x9E, 0x1C, 0x7C, 0xEE } -- ELUA chars on IV-18 VFD
while true do
for i = 0, 35 do -- 26 is enough, 35 adds some extra time at the end
for j = 1, 10 do
vfd.set( t[ 1 ], bit.bit( math.min( i, 7 ) ) )
vfd.set( t[ 2 ], bit.bit( math.min( i - 8, 6 ) ) )
vfd.set( t[ 3 ], bit.bit( math.min( i - 15, 5 ) ) )
vfd.set( t[ 4 ], bit.bit( math.min( i - 21, 4 ) ) )
end
k = term.getchar( term.NOWAIT )
handlekbd( k )
if k == term.KC_ESC then
vfd.clear()
return
end
end
end
end
----- Auxiliar Functions -----
-- Adjust delay with terminal kbd keys
function handlekbd( k )
if k == 119 then -- k = w ?
dly = dly + 20000
print( "Current step delay = " .. dly .. "us" ) -- Print current delay in microseconds on terminal (for debugging)
elseif k == 122 then -- k = z ?
dly = dly - 20000
if dly < 0 then
dly = 0
end
print( "Current step delay = " .. dly .. "us" ) -- Print current delay in microseconds on terminal (for debugging)
end
end