/
LED-Nixie-Christoph-Vanessa-2.15.bas.bak
2019 lines (2019 loc) · 64.2 KB
/
LED-Nixie-Christoph-Vanessa-2.15.bas.bak
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' *************************************
' * LED-NIXIE Clock Demo *
' * LED-Basic >= 15.2.9 required *
' * modified by Vanessa Ver. 2.15 *
' * partially from CJ Ver. C2.10.05 *
' * partially from Doug's ver.D1.02 *
' * partially from Jon's ver.J2.02 *
' *************************************
' * Ver. C2.10.05 CJ�s edits: *
' * Changed default beep *
' * Added beep at startup *
' * Added dedicated alarm sound *
' * Increased light sensor impact *
' * Extended nightmode features *
' * Added extra long button press *
' *************************************
'
' Operations manual:
'
' On startup, the display shows the software version for approx. 2 seconds.
' To reset to factory defaults: as soon as the software version number displays,
' press and hold the button until unit beeps.
'
' Usage:
'
' Three Button Modes:
' � Short press.
' � Long press: hold the button until you�ll hear a beep, then release it.
' � Extra long press: hold the button until you�ll hear a beep, keep holding it you hear a second beep*:
' The clock toggles manually between night/day mode.
' * low beep = nightmode off; high beep = nightmode on
'
' Turn the knob to adjust the display colour.(0-9 solid colour, 10 white, 11 incandecent,
' 12-14 multi colour). Short press knob to switch between Clock and Date display,
' Changing display also ensures colour setting is saved when restarting.
' Date display automatically returns to clock display after approx. 3 seconds.
'
' Long press spinner button during time display to enter settings menu (white).
' Long press button during date display to enter the system menu (blue).
' Turn knob to choose an option, short press to select, long press to exit.
' After 4 seconds inactivity, the unit returns to display mode
' (without saving changes).
'
' Settings menu (white):
' Setting 0: beeper on / off (default 1)
' 0 = off
' 1 = on
' Setting 1: 12 / 24 hour clock display (default 24)
' 12 = 12 hour clock
' 24 = 24 hour clock
' Setting 2: Set the time (24 hour clock)
' Short press changes between hours, minutes, seconds
' long press saves the time
' Setting 3: Date format display (default 0)
' 0 = DDMMYY
' 1 = MMDDYY
' 2 = YYMMDD
' Setting 4: Set the date
' Short press changes between days, months, years
' long press saves the date
' Setting 5: Alarm on / off (default 0)
' 0 = off
' 1 = on
' Setting 6: Set alarm time (24 hour clock, default 12:00)
' Short press changes between hours and minutes
' Long press saves the alarm time
' Setting 7: Auto date display on / off (default 0)
' 0 = off
' 1 = on
' Setting 8: Timer (max 23:59:00)
' Short press changes between hours and minutes
' Long press sets timer duration
' Then short press to start / stop timer
' To exit, long press whilst timer stopped
' Setting 9: Stopwatch (max 23:59:59)
' Short press to start / stop stopwatch
' To exit, long press whilst stopwatch stopped
'
' System menu (blue):
' System 0: adjustness (default 12)
' 1..15 = brightness level,
' 0 = automatic brightness (set using sensor)
' System 1: Minimum brightness for auto brightness (default 2)
' 0...15 = minimum brightness (no brightness level)
' System 2: Time correction offset faster or slower (default 1)
' 0 = slower offset
' 1 = faster offset
' System 3: set Time offset n cycles per 32 sek. (default 0)
' 0...510 = Offset in cycles per 32 sek.
' System 4: Party Mode On / Off (default 0)
' 0 = off
' 1 = on
' System 5: Slot machine mode on / off (default 0)
' 0 = off
' 1 = on
' System 6: Second flipping mode on / off (default 0)
' 0 = off
' 1 = on
' System 7: Digit fade mode (default 3)
' 1..5 = digit fade duration
' 0 = off
' System 8: Set the Night mode duration
' if begin and end are the same, Night mode is disabled.
' Short press changes between begin hour, begin minute (yellow)
' long press saves, then -->
' Short press changes between end hour, end minute (green)
' long press saves
' System 9: adjust nightmode brightness (default 1)
' 1..15 = brightness level,
' 0 = automatic brightness (set using sensor)
'
'
' All settings remain in case of power failure (EEPROM).
' The alarm is prioritised over the timer and stopwatch.
' Softwareversion check on startup.
'
' Slot machine mode: at 4, 8, 14, 18, 24... minutes past the hour, LEDs are lit
' at random for 10 seconds.
' Party mode: every other minute (01, 03, 05...), one of 7 "party 'displays" at
' random are shown for a few seconds.
' Second flipping mode: flipping from '9' to '0', the seconds display
' cycles through 9...8...7... ...0. If on, Fade mode has no function !
' When alarm is On, alarm time displays twice every ten minutes (minutes 02, 06,
' 12, 16, 22...) in red.
' Fade mode: Digits are fading depending on value. NOT working when Second flipping mode is on !
' Night mode: (seperate colour & brightnesssettings)
' if begin and end are the same, Night mode is disabled.
' During Night mode on: Partymode, alarm time display and Slot machine are disabled.
'
'
' If connected to a PC running LED-Basic, the current EEPROM values are
' displayed on the screen at program start for debugging purposes.
'
'******************************************************************************
### L60 CGRB P0 S2 M100 F40
' Set initial EEPROM state (for testing, uncomment to set on run)
' IO.eewrite(0, 215) ' 0 = Softwareversion
' IO.eewrite(1, 11) ' 1 = Time Colour (11)
' IO.eewrite(2, 5) ' 2 = Date Colour (5)
' IO.eewrite(3, 1) ' 3 = Beep (1)
' IO.eewrite(4, 12) ' 4 = Brightness (12)
' IO.eewrite(5, 0) ' 5 = Alarm (0)
' IO.eewrite(6, 12) ' 6 = Alarm Hour (12)
' IO.eewrite(7, 0) ' 7 = Alarm Minute (0)
' IO.eewrite(8, 0) ' 8 = Auto Date Display (0)
' IO.eewrite(9, 0) ' 9 = Party Mode (0)
' IO.eewrite(10, 0) ' 10 = Time Offset (0)
' IO.eewrite(11, 1) ' 11 = Time Offset +/- (1)
' IO.eewrite(12, 2) ' 12 = Min Auto Bright (2)
' IO.eewrite(13, 0) ' 13 = Slot Machine (0)
' IO.eewrite(14, 1) ' 14 = 24 Hour Clock (1)
' IO.eewrite(15, 0) ' 15 = Seconds flip (0)
' IO.eewrite(16, 0) ' 16 = Date format (0)
' IO.eewrite(17, 3) ' 17 = Digits fade (3)
' IO.eewrite(18, 0) ' 18 = Nightmode (0)
' IO.eewrite(19, 0) ' 19 = Begin Nightmode Hour (0)
' IO.eewrite(20, 0) ' 20 = Begin Nightmode Minute(0)
' IO.eewrite(21, 0) ' 21 = End Nightmode Hour (0)
' IO.eewrite(22, 0) ' 22 = End Nightmode Minute (0)
' IO.eewrite(23, 0) ' 23 = Nightmode Time Colour (0)
' IO.eewrite(24, 0) ' 24 = Nightmode Date Colour (0)
' IO.eewrite(25, 1) ' 25 = Nightmode Brightness (1)
'
' Nixie Digit Index
10: data 5,0,6,1,7,2,8,3,9,4
'
' Colour Index (0..14)
20: data 5,20,50,90,130,160,200,260,300,340,1000,1001,1002,1003,1004
'
' Brightness Table
30: data 0,3,6,9,16,25,37,51,68,87,109,133,160,189,221,255
'
' Music Timer / Stopwatch max :-)
40: data 13,200,15,200,17,200,13,200,13,200,15,200,17,200,13
data 200,17,200,18,200,20,400,17,200,18,200,20,400
' alternate uk version
'40: data 15,15,15,18,18,18,19,19,20,20,20,21,21,21,22,22
' data 27,25,0,0,20,22,0,0,32,30,27,30,0,0,37
'
' LED-INDEX SET
led.ihsv(0, 0, 0, 0) ' off
led.ihsv(2, 0, 0, 128) ' white (settings)
led.ihsv(3, 2, 255, 128) ' red (set alarm)
led.ihsv(4, 110, 254, 96) ' green (timer / stopwatch)
led.ihsv(5, 37, 254, 96) ' yellow (set date / time)
led.ihsv(6, 240, 255, 128)' blue (system menu)
LED.blackout() ' turn off all LEDs
'
' Version
'gosub 9100 ' BEEP
LED.iled(2, 10 + read 10, 2)
LED.iled(2, 20 + read 10, 1)
LED.iled(2, 30 + read 10, 5)
LED.iled(2, 40 + read 10, 1)
LED.show()
gosub 9150 ' porka madona, �e en �nops :D
delay 2000
'
' EEPROM INIT
if (IO.eeread(0)) <> 215 or IO.keystate() = 1 gosub 8000 'first time or reset
' EEPROM Output to Terminal
gosub 8050
'
'==============================================================================
' GLOBAL VARS
' c = colour, m = mode, t = temp, i = loop, j = counter, r = temp,
' x = alarm silenced, z = counter, h = hue, v = brightness, b = brightness subtraction
' l = transition brightness, u = last second shown for fade
'==== STARTUP ===================================
'
99:
r = IO.eeread(10) ' Read Offset Value
if (IO.eeread(11)) = 0 then r = r * -1 ' negativ cycles
IO.sys(99, r)
b = 0 ' brightness subtraction
l = 0 ' Transition brightness
u = 11 ' Last second shown
j = 59 ' Initial LED location for seconds flip
m = 0 ' Initially in time display
x = 0 ' Alarm not silenced
goto 190
'==== MAIN LOOP =================================
100:
t = IO.getenc() ' Read Encoder
if t = c goto 105
c = t ' color set (knob turned)
z = 0 ' counter reset
105:
r = IO.getrtc(0) ' seconds
s = IO.getrtc(1) ' minutes
a = IO.getrtc(2) ' hours
if r = 0 then x = 0 ' reset alarm silencer
if r = 0 and (IO.eeread(19)) = (IO.eeread(21)) and (IO.eeread(20)) = (IO.eeread(22)) goto 108 ' no night duration
if r = 0 and (IO.eeread(19)) = a and (IO.eeread(20)) = s gosub 300 ' nightmode on
if r = 0 and (IO.eeread(21)) = a and (IO.eeread(22)) = s gosub 305 ' nightmode off
108:
if x = 0 and (IO.eeread(5)) = 1 and (IO.eeread(6)) = a and (IO.eeread(7)) = s gosub 9150 ' alarm so ringing
if s % 10 = 4 or s % 10 = 8 and r = 2 and m = 0 and (IO.eeread(18)) = 0 and (IO.eeread(13)) = 1 gosub 4000 ' random (slot machine)
if s % 10 = 1 or s % 10 = 3 or s % 10 = 5 or s % 10 = 7 or s % 10 = 9 and m = 0 and (IO.eeread(18)) = 0 and (IO.eeread(9)) = 1 and r = 2 goto 2900 ' party mode
if m = 0 and r = 50 and (IO.eeread(8)) = 1 goto 180 ' date auto display
if s % 10 = 3 or s % 10 = 4 and (IO.eeread(5)) = 1 and (IO.eeread(18)) = 0 and r = 2 and v > 5 gosub 700 ' show alarm time
gosub 9000 ' Get key. 0 = none 1 = short press 2 = long press 3 = extra long press
if k = 1 goto 110 ' short press: change display mode
if k = 3 and (IO.eeread(18)) = 1 goto 310 ' extra long press: nightmode manual off
if k = 3 and (IO.eeread(18)) = 0 goto 315 ' extra long press: nightmode manual on
if k = 2 and m = 1 goto 10100 ' system menu
if k = 2 goto 10000 ' settings menu
goto 200 ' k = 0
110:
'==== SHORT PRESS: MODE SWITCH ====
gosub 9100 ' BEEP
if m = 0 goto 180 ' change time to date display
if m = 1 goto 185 ' change date to time display
180: ' change from time to date display
if (IO.eeread(18)) = 0 and (IO.eeread(m + 1)) <> c then IO.eewrite(m + 1, c) ' saves current time colour to EEPROM
if (IO.eeread(18)) = 1 and (IO.eeread(m + 23)) <> c then IO.eewrite(m + 23, c) ' saves current nightmode time colour to EEPROM
m = 1 ' change to date mode
if k = 1 then x = 1 ' silence alarm when spinner pressed
goto 190 ' done
185: ' change from date to time display
if (IO.eeread(18)) = 0 and (IO.eeread(m + 1)) <> c then IO.eewrite(m + 1, c) ' saves current date colour to EEPROM
if (IO.eeread(18)) = 1 and (IO.eeread(m + 23)) <> c then IO.eewrite(m + 23, c) ' saves current nightmode date colour to EEPROM
m = 0 ' change to time mode
190: 'NB: also entry point from start
if (IO.eeread(18)) = 0 then c = IO.eeread(m + 1) ' sets colour from eeprom if nightmode off
if (IO.eeread(18)) = 1 then c = IO.eeread(m + 23) ' sets colour from eeprom if nightmode on
IO.setenc(c, 14, 0) ' set spinner to 15 colour options + wraparound
z = 0 ' reset counter
200:
if z & 15 <> 0 goto 210 ' only check brightness once per 15 cycles
205:
i = (IO.getldr() * 60) + IO.eeread(12) ' measured brightness + minimum overall brightness
'print "i je tocno takole ";IO.getldr()
'print "i je tocno takole ";v
if i > 254 then i = 254 ' do not exceed max brightness
if (IO.eeread(4)) = 0 then v = i else v = read 30, IO.eeread(4)' Set brightness from auto or EEPROM
if (IO.eeread(18)) = 1 and (IO.eeread(25)) = 0 then v = i ' Set nighmode brightness from sensor
if (IO.eeread(18)) = 1 and (IO.eeread(25)) <> 0 then v = read 30, IO.eeread(25) ' Set nighmode brightness from EEPROM
210:
LED.iall(0) ' Clear display
if m <> 0 goto 220 ' If date mode, skip time display
gosub 500 ' Show time - set LEDs
LED.show() ' Show time - show LEDs
goto 100 ' Back to beginning of loop
220:
if m <> 1 goto 100 ' If not date mode, re-enter loop
gosub 600 ' SHOW DATE - set LEDs
LED.show() ' Show date - show LEDs
if z > 120 goto 185 ' Return to TIME display after ca. 3sec
goto 100 ' Back to beginning of loop
'================================================
' AUTO NIGHTMODE TOGGLE
300:
IO.eewrite(18, 1) ' nightmode on
c = IO.eeread(m + 23)
IO.setenc(c, 14, 0) ' set spinner to 15 colour options + wraparound
return
305:
IO.eewrite(18, 0) ' nightmode off
c = IO.eeread(m + 1)
IO.setenc(c, 14, 0) ' set spinner to 15 colour options + wraparound
return
' MANUAL NIGHTMODE TOGGLE
310:
if (IO.eeread(m + 23)) <> c then IO.eewrite(m + 23, c) ' saves current nightmode colour to EEPROM
IO.eewrite(18, 0) ' nightmode off
m = 0 ' always go back to time display
gosub 9120 ' low beep
goto 190
315:
if (IO.eeread(m + 1)) <> c then IO.eewrite(m + 1, c) ' saves current colour to EEPROM
IO.eewrite(18, 1) ' nightmode on
m = 0 ' always go back to time display
gosub 9100 ' beep
goto 190
'================================================
' handle flip fade animation
400:
if g = 0 goto 410
b = v - l ' set the subtraction value to our transition brightness
if p <> 0 or n <> 0 or (IO.eeread(14)) = 1 gosub 1000
b = l
n = i
410:
if p <> 0 or n <> 0 or (IO.eeread(14)) = 1 gosub 1000
b = 0
return
'================================================
' SHOW TIME routine
' VAR: n, p, j
500:
g = 0
if r % 10 = 9 and (IO.eeread(15)) = 1 goto 510 ' seconds flip
if (IO.eeread(17)) > 0 and (IO.eeread(15)) = 0 then g = 1 ' digit fade if not second flip
n = r % 10
p = 50
' calculate the flip brightness even if we're not using it
if u <> n then l = 0
if u <> n then u = n
i = 6 - IO.eeread(17) ' fade value
l = l + 1 + i * (v / 50) ' increase the level of transition brightness
if l > v then l = v ' don't increase the level beyond the set brightness
' finished calculating brightness
i = n - 1
if i < 0 then i = 9
gosub 400 ' display seconds 1s
if g = 1 and r % 10 = 0 then g = 1 else g = 0' 10s seconds flip if our is a 0
n = r / 10
p = 40
i = n - 1
if i < 0 then i = 5
gosub 400 ' display seconds 10s
j = 59
goto 520 ' to minutes
510:
n = r / 10 ' Seconds Flip routine
p = 40
gosub 1000 ' Seconds 10
n = j % 10
p = 50
gosub 1000 ' Seconds 1
j = j - 1
delay 98 ' approx 0.1 seconds between flips
520:
if g = 1 and r / 10 = 0 then g = 1 else g = 0 'decide if we need to fade this number
n = s % 10
p = 30
i = n - 1
if i < 0 then i = 9
gosub 400 ' Minutes 1
if g = 1 and s % 10 = 0 then g = 1 else g = 0 'decide if we need to fade this number
n = s / 10
p = 20
i = n - 1
if i < 0 then i = 5
gosub 400 ' Minutes 10
if g = 1 and s / 10 = 0 then g = 1 else g = 0 'decide if we need to fade this number
if (IO.eeread(14)) = 0 and a > 12 then a = a - 12 ' 12 hour clock, hours 13-23 changed to 1-11
if (IO.eeread(14)) = 0 and a = 0 then a = 12 ' 12 hour clock, hour 0 = 12
n = a % 10
p = 10
i = n - 1
if i < 0 then i = 9
if (IO.eeread(14)) = 0 and a / 10 = 0 and n = 1 then i = 2 ' roll to 1:00
if (IO.eeread(14)) = 1 and a / 10 = 0 and n = 0 then i = 3 ' roll to 0:00
gosub 400 ' Hours 1
i = 0 ' figure out if we need to flip the time
if (IO.eeread(14)) = 0 and a / 10 = 0 and a % 10 = 1 then i = 1 ' we need to handle the rollover to 1:00
if (IO.eeread(14)) = 1 and a / 10 = 0 and a % 10 = 0 then i = 1 ' we need to handle the rollover to 0:00
if g = 1 and i = 1 then g = 1 else g = 0 ' 10s hours flip if our 1s minute is a 0
n = a / 10
p = 0
i = n - 1
if i < 0 and (IO.eeread(14)) = 0 then i = 1
if i < 0 and (IO.eeread(14)) = 1 then i = 2
gosub 400 ' Hours 10
if z < 32761 then z = z + 1 else z = 0
return
'================================================
' SHOW DATE
' VAR: n, p
600:
s = IO.getrtc(3) 'day
n = s / 10
p = (IO.eeread(16)) * 20 ' Ddmmyy, mmDdyy, yymmDd (IO.eeread(16))=0,1,2
gosub 1000 ' Day 10s
n = s % 10
p = (IO.eeread(16)) * 20 + 10 ' dDmmyy, mmdDyy, yymmdD (IO.eeread(16))=0,1,2
gosub 1000 ' Day units
s = IO.getrtc(4) 'month
n = s / 10
if (IO.eeread(16)) = 1 then p = 0 else p = 20 ' Mmddyy, ddMmyy / yyMmdd
gosub 1000 ' Month 10s
n = s % 10
if (IO.eeread(16)) = 1 then p = 10 else p = 30 ' mMddyy, ddmMyy / yymMdd
gosub 1000 ' Month units
s = IO.getrtc(5) ' year
n = (s % 100) / 10 ' 2 digit year
if (IO.eeread(16)) = 2 then p = 0 else p = 40 ' Yymmdd, ddmmYy / mmddYy
gosub 1000 ' Year 10s
n = s % 10
if (IO.eeread(16)) = 2 then p = 10 else p = 50 ' yYmmdd, ddmmyY/mmddyY
gosub 1000 ' Year units
s = IO.getrtc(1) ' minutes reset to s
z = z + 1
return
'================================================
' SHOW Alarm
' VAR: n, p, s, i
700:
if (IO.eeread(5)) = 1 and (IO.eeread(6)) = a and (IO.eeread(7)) = s return ' alarm ringing so don't display alarm time
LED.iall(0) ' Clear display
t = IO.eeread(6)
for i = 50 downto 10 step 10
LED.iled(3, i + read 10, t / 10)
LED.show()
delay 200
LED.iled(0, i + read 10, t / 10)
next i
LED.iled(3, read 10, t / 10)
for i = 50 downto 20 step 10
LED.iled(3, i + read 10, t % 10)
LED.show() ' display
delay 200 ' cycle 1/5 second
LED.iled(0, i + read 10, t % 10)
next i
LED.iled(3, 10 + read 10, t % 10)
t = IO.eeread(7) ' alarm minutes
for i = 50 downto 30 step 10
LED.iled(3, i + read 10, t / 10)
LED.show()
delay 200
LED.iled(0, i + read 10, t / 10)
next i
LED.iled(3,20 + read 10, t / 10)
for i = 50 downto 40 step 10
LED.iled(3, i + read 10, t % 10)
LED.show()
delay 200
LED.iled(0, i + read 10, t % 10)
next i
LED.iled(3, 30 + read 10, t % 10)
LED.show()
delay 200
LED.iled(3, 50 + read 10,0)
LED.show()
delay 200
LED.iled(0, 50 + read 10,0)
LED.iled(3, 40 + read 10,0)
LED.show()
delay 200
LED.iled(3, 50 + read 10,0)
LED.show()
delay 1500
return
'================================================
' Character display routine for date / time (using set colour mode)
1000:
t = read 20, c ' read colour value from index
if t > 360 goto 1010
LED.ihsv(1, t, 255, v - b) ' set "standard 1 colour" at brightness V
goto 1090
1010:
if t <> 1000 goto 1015 ' position 10 = white
LED.ihsv(1, 0, 0, v - b)
goto 1090
1015:
if t <> 1001 goto 1020 ' position 11 = incandecent
LED.ihsv(1, 25, 205, v - b)
goto 1090
1020:
if t <> 1002 goto 1030 ' position 12 = multi-colour
LED.ihsv(1, h, 255, v - b)
h = (p * 6 + z) % 360 ' set "standard 1" as 6* position + counter mod 360
goto 1090
1030:
if t <> 1003 goto 1040 ' position 13 = gently cycling
LED.ihsv(1, h, 255, v - b) ' set "standard 1" as counter/4 mod 360
h = (z / 4) % 360
goto 1090
1040:
'we assume t = 1004 = position 14 = gently cycling 2
led.ihsv(1, h, 255, v - b)
h = (2 * z + (2 * (50 - p))) % 360
1090:
LED.iled(1, p + read 10, n) ' show character
return
'================================================
' party mode
2900:
if (IO.eeread(5)) = 1 and (IO.eeread(6)) = a and (IO.eeread(7)) = s goto 100 ' alarm ringing so abort
i = random ' choose one of animations at random
if i <= 4096 gosub 3000 ' party mode effect 0
if i > 4096 and i <= 8192 gosub 3100 ' party mode effect 1
if i > 8192 and i <= 12288 gosub 3200 ' party mode effect 2
if i > 12288 and i <= 16384 gosub 3300 ' party mode effect 3
if i > 16484 and i <= 20480 gosub 3400 ' party mode effect 4
if i > 20480 and i <= 24576 gosub 3500 ' party mode effect 5
if i > 24576 and i <= 28672 gosub 3600 ' party mode effect 6
if i > 28672 gosub 3700 ' party mode effect 7
k = IO.getkey() ' key reset if pressed during Party
goto 100 ' main loop
'............................................................
3000: ' pixels turning off and on at random, random colours
for n = 1 to 300
r = random % 360 ' colour
a = random % 60 ' position
led.lhsv(a, r, 255, v) ' set colour
if a - 1 >= 0 then LED.iled(0, a - 1) ' turn off pixel below current
led.show()
delay 50
next n
return
'............................................................
3100: ' two pixels of two random colours cycling and crossing each other
for n = 1 to 3
3110:
a = Random % 360
r = Random % 360
if a = r goto 3110
for i = 0 to 60
LED.iall(0)
led.lhsv(i, a, 255, v) ' Colour
led.lhsv(60 - i, r, 255, v) ' Colour
led.show()
delay 80
next i
next n
return
'............................................................
3200: ' two pairs of two pixels cycling and crossing each other
a = Random % 360
r = Random % 360
n = Random % 360
z = Random % 360
for i = 0 to 249
LED.iall(0)
led.lhsv(i % 60, z, 255, v)
led.lhsv(60 - ((i + 1) % 60), a, 255, v)
led.lhsv((i + 9) % 60, r, 255, v)
led.lhsv(60 - ((i + 10) % 60), n, 255, v)
led.show()
delay 80
next i
return
'............................................................
3300: ' 6 sweeps of random colour, increasing in change per sweep
LED.iall(0)
z = Random % 360
for n = 0 to 5
for i = 60 downto 0
if n % 2 = 0 then led.lhsv(i, (z + n * i) % 360, 255, v) else led.lhsv(60 - i,(z + n * i) % 360, 255, v)
led.show()
next i
next n
return
'............................................................
3400: ' "turbulent" rainbow over all pixels, speeding up
h = random % 360
for i = 1 to 500
LED.rainbow(h, 255, v, 0, 60, 3)
LED.show()
h = (h + i / 10) % 360
next i
return
'............................................................
3500: ' all pixels solid varying, varying in brightness.
for z = 1 to 350
i = random % 100
if i < 75 goto 3565
h = ((random % 129) * v) / 128
LED.ihsv(9,(i * h) % 360, 255, h)
LED.iall(9)
3565:
LED.show()
next z
return
'............................................................
3600: ' all pixels white, varying in brightness.(TV mode)
for z = 1 to 350
i = random % 100
if i < 75 goto 3665
h = ((random % 129) * v) / 128
LED.ihsv(9, 0, 0, h)
LED.iall(9)
3665:
LED.show()
next z
return
'............................................................
3700: ' cycling through all LEDs 0-59 in increasing colours with random white
LED.ihsv(9, 0, 0, v)
g = 0 'Test variable, to exit routine
3701: 'Pixel counter index
data 5,0,6,1,7,2,8,3,9,4,
data 15,10,16,11,17,12,18,13,19,14,
data 25,20,26,21,27,22,28,23,29,24,
data 35,30,36,31,37,32,38,33,39,34,
data 45,40,46,41,47,42,48,43,49,44,
data 55,50,56,51,57,52,58,53,59,54,
3702: 'Main loop
for i = 1 to 59
if i % 20 = 0 then h = random % 4
if i % 20 = 0 then LED.irange(9, 10 * h, 10 * h + 9)
led.ihsv(1, ((i + g) * 7) % 360, 255, v)
LED.iled(1, read 3701, i)
LED.show()
g = g + 1
next i ' cycle through colours
if g < 450 goto 3702 ' continue for 10ish seconds
return
'================================================
' SHOW Slot machine
' VAR: s, n, p, i
4000:
if (IO.eeread(5)) = 1 and (IO.eeread(6)) = a and (IO.eeread(7)) = s return ' alarm sounding so quit
for i = 1 to 100
LED.iall(0) ' Clear display
s = random
n = s % 10 ' random number between 0 and 9
p = 40
gosub 1000 ' 10s Seconds
n = ((s % 100)/10) + 1 ' random number between 1 and 10?
p = 50
gosub 1000 ' Seconds 1s
n = (s % 1000)/100
p = 20
gosub 1000 ' Minutes 10s
n = (s % 100)/10
p = 30
gosub 1000 ' Minutes 1s
n = (s % 10000)/1000
p = 0
gosub 1000 ' Hours 10s
n = ((s % 1000)/100) + 1
p = 10
gosub 1000 ' Hours 1s
z = z + 4 ' colour cycling
LED.show()
delay 10 + i * 2 ' increasingly slow as time goes on
next i
s = IO.getrtc(1) ' temporarily used for random number, reset as minutes
k = IO.getkey() ' key reset if pressed during Slot machine
return
'================================================
' EEPROM INIT
8000:
print "Resetting EEPROM..."
print " "
IO.eewrite(0, 215) ' 0 = Softwareversion
IO.eewrite(1, 11) ' 1 = Time Colour (11)
IO.eewrite(2, 5) ' 2 = Date Colour (5)
IO.eewrite(3, 1) ' 3 = Beep (1)
IO.eewrite(4, 12) ' 4 = Brightness (12)
IO.eewrite(5, 0) ' 5 = Alarm (0)
IO.eewrite(6, 12) ' 6 = Alarm Hour (12)
IO.eewrite(7, 0) ' 7 = Alarm Minute (0)
IO.eewrite(8, 0) ' 8 = Auto Display Date (0)
IO.eewrite(9, 0) ' 9 = Party Mode (0)
IO.eewrite(10, 0) ' 10 = Time Offset (0)
IO.eewrite(11, 1) ' 11 = Time Offset Pos/Neg (1)
IO.eewrite(12, 2) ' 12 = Min Brightness in Auto (2)
IO.eewrite(13, 0) ' 13 = Slot Machine (0)
IO.eewrite(14, 1) ' 14 = 24 Hour Clock (1)
IO.eewrite(15, 0) ' 15 = Seconds flip (0)
IO.eewrite(16, 0) ' 16 = Date format (0)
IO.eewrite(17, 3) ' 17 = Digits fade (3)
IO.eewrite(18, 0) ' 18 = Nightmode (0)
IO.eewrite(19, 0) ' 19 = Begin Nightmode Hour (0)
IO.eewrite(20, 0) ' 20 = Begin Nightmode Minute (0)
IO.eewrite(21, 0) ' 21 = End Nightmode Hour (0)
IO.eewrite(22, 0) ' 22 = End Nightmode Minute (0)
IO.eewrite(23, 0) ' 23 = Nightmode Time Colour (0)
IO.eewrite(24, 0) ' 24 = Nightmode Date Colour (0)
IO.eewrite(25, 1) ' 25 = Nightmode Brightness (1)
print "EEPROM reset."
print " "
IO.beep(35)
delay 500
IO.beep(0)
return
'================================================
' Print out EEPROM to Terminal
8050:
print " LED-NIXIE Clock"
print "by Vanessa, partially from Christoph, Doug and Jon"
for i = 0 to 25 ' EEPROM data output
t = IO.eeread(i)
print "EEP[";i;"] = ";t
next i
return
'================================================
' GETKEY
' VAR: k, i, RET: k
' k: 0 = No Key, 1 = Short, 2 = LONG press, 3 = EXTRA LONG press
9000:
k = IO.getkey()
if k = 0 return
i = 0
9010:
k = IO.keystate()
if i < 50 and k = 0 goto 9015
if i = 50 gosub 9110 ' BEEP MEDIUM
delay 10
i = i + 1
if i < 150 and k = 1 goto 9010
if i >= 150 goto 9020
k = 2 ' LONG PRESS
return
9015:
k = 1 ' SHORT PRESS
return
9020:
k = 3 ' EXTRA LONG PRESS
return
'================================================
' BEEP HIGH
9100:
if (IO.eeread(3)) = 0 return ' no beep if set silent
IO.beep(25)
delay 25
IO.beep(0)
return
' BEEP MEDIUM
9110:
if (IO.eeread(3)) = 0 return ' no beep if set silent
IO.beep(15)
delay 25
IO.beep(0)
return
' BEEP LOW
9120:
if (IO.eeread(3)) = 0 return ' no beep if set silent
IO.beep(5)
delay 25
IO.beep(0)
return
' ALARM
9150:
IO.beep(8)
delay 300
IO.beep(0)
delay 100
IO.beep(3)
delay 100
IO.beep(0)
delay 100
IO.beep(3)
delay 100
IO.beep(0)
delay 100
IO.beep(5)
delay 200
IO.beep(0)
delay 200
IO.beep(3)
delay 200
IO.beep(0)
delay 600
IO.beep(7)
delay 200
IO.beep(0)
delay 200
IO.beep(8)
delay 200
IO.beep(0)
'IO.beep(30)
'delay 50
'IO.beep(0)
'delay 100
'IO.beep(30)
'delay 50
'IO.beep(0)
'delay 100
'IO.beep(20)
'delay 50
'IO.beep(0)
delay 700
return
'================================================
' Settings menu
' VAR p: position, t: temp, y: value
10000:
gosub 9100 ' BEEP
p = 0
10005:
z = 0
IO.setenc(p, 9, 0) ' Set Encoder (Spinner) to give 0-9 positions
10010:
t = IO.getenc() ' Read Encoder
if t = p goto 10020
p = t
z = 0 ' counter reset
10020:
gosub 9000 ' GETKEY
if k = 0 goto 10050
if k = 1 goto 10060
gosub 9100 ' BEEP. K = 2 so long press so exit
goto 99 ' long press so exit
10050:
LED.iall(0) ' Clear display
if z & 15 < 11 then LED.iled(2, read 10, p) ' White first pixel number flashes.
LED.show()
z = z + 1
if z > 300 goto 99 ' Time-out, back to time display
goto 10010
10060:
if p = 0 goto 12000 ' F0: Beep on/off
if p = 1 goto 12400 ' F1: 12/24 hour time display
if p = 2 goto 13000 ' F2: Time set
if p = 3 goto 12600 ' F3: Date format
if p = 4 goto 14000 ' F4: Date set
if p = 5 goto 15000 ' F5: Alarm on / off
if p = 6 goto 16000 ' F6: Alarm time set
if p = 7 goto 17000 ' F7: Auto date display on / off
if p = 8 goto 18000 ' F8: Timer
if p = 9 goto 19000 ' F9: Stopwatch
goto 10010
'================================================
' System menu
' VAR p: position, t: temp, y: value
10100:
gosub 9100 ' BEEP
p = 0
10105:
z = 0 ' counter
IO.setenc(p, 9, 0) ' 0-9 options
10110:
t = IO.getenc() ' Read Encoder
if t = p goto 10120
p = t
z = 0 ' counter reset
10120:
gosub 9000 ' GETKEY
if k = 0 goto 10150
if k = 1 goto 10160
gosub 9100 ' BEEP
goto 99 ' long press so exit
10150:
LED.iall(0) ' Clear display
if z & 15 < 11 then LED.iled(6, read 10, p) ' Blue menu option Flashing
LED.show()
z = z + 1
if z > 300 goto 99 ' RETURN if timed out
goto 10110
10160:
if p = 0 goto 11000 ' S0: Brightness
if p = 1 goto 11200 ' S1: Minimum brightness on auto
if p = 2 goto 12100 ' S2: Time offset polarity
if p = 3 goto 11100 ' S3: Time offset n cycles per 32 sek.
if p = 4 goto 20000 ' S4: Party mode on/off
if p = 5 goto 12200 ' S5: Slot machine on/off
if p = 6 goto 12500 ' S6: Seconds flip on/off
if p = 7 goto 15100 ' S7: Digit fade
if p = 8 goto 21000 ' S8: Night mode duration
if p = 9 goto 23000 ' S9: Night mode brightness
goto 10110
'================================================
' S0: BRIGHTNESS SELECTION
' VAR: y,t,z,k
11000:
gosub 9100 ' BEEP
y = IO.eeread(4) ' Read Brightness Value from EEPROM
11005:
z = 0 ' counter
IO.setenc(y, 15, 0) ' 15 brightness values
11010:
t = IO.getenc()
if t = y goto 11020
y = t
z = 0 ' movement so reset counter
11020:
gosub 9000 ' GETKEY
if k = 0 goto 11050
gosub 9100 ' BEEP
goto 11070 ' short press
11050:
LED.iall(0) ' Clear display
if z & 15 > 10 goto 11060 ' (flashing)
LED.iled(2, 40 + read 10, y / 10) ' brightness display 10s
LED.iled(2, 50 + read 10, y % 10) ' brightness units
11060:
LED.iled(6, read 10, 0) ' show in System 0 i.e. brightness
LED.show()
z = z + 1
if z <= 300 goto 11010 ' timeout
goto 10105 ' return to system menu without save
11070:
if y <> (IO.eeread(4)) then IO.eewrite(4, y) ' Write Brightness Value
goto 10105 ' return to system menu
'================================================
' S3: Time offset n cycles per 32 sek.
' VAR: y,t,z,k
11100:
gosub 9100 ' BEEP
y = IO.eeread(10) ' Read Offset Value
11105:
z = 0
IO.setenc(y, 510, 0) ' choices 0-510
11110:
t = IO.getenc()
if t = y goto 11120
y = t
z = 0
11120:
gosub 9000 ' GETKEY
if k = 0 goto 11150
gosub 9100 ' BEEP
goto 11170 ' short click
11150:
LED.iall(0) ' Clear display
if z & 15 > 10 goto 11160 ' lightpixels only 10 in 15 cycles'
LED.iled(2, 30 + read 10, y / 100) ' light setting 100s
LED.iled(2, 40 + read 10, (y / 10) % 10) ' light setting 10s
LED.iled(2, 50 + read 10, y % 10) ' light setting units
11160:
LED.iled(6, read 10, 3) ' set first pixel blue 3 to indicate menu place
LED.show()
z = z + 1
if z <= 300 goto 11110 ' timeout
goto 10105 ' return to system menu without save
11170:
if y <> (IO.eeread(10)) then IO.eewrite(10, y) ' Write Offset Value to EE
goto 10105 ' return to system menu
'================================================
' S1: MIN BRIGHTNESS for Auto Brightness
' VAR: y,t,z,k
11200:
gosub 9100 ' BEEP
y = IO.eeread(12) ' Read Min Brightness Value from EEPROM
11205:
z = 0
IO.setenc(y, 15, 0) ' range from 0 to 15
11210:
t = (IO.getenc())
if t = y goto 11220
y = t
z = 0
11220:
gosub 9000 ' GETKEY
if k = 0 goto 11250
gosub 9100 ' BEEP, short press one assumes
goto 11270
11250:
LED.iall(0) ' Clear display
if z & 15 > 10 goto 11260 ' light pixels for 10 in 15 cycles
t = y
LED.iled(2, 40 + read 10, t / 10) ' min brightness 10s
LED.iled(2, 50 + read 10, t % 10) ' min brightness units
11260:
LED.iled(6, read 10, 1) ' system menu blue, 1st pos
LED.show()
z = z + 1
if z <= 300 goto 11210 ' time out
goto 10105 ' return to system menu without save
11270:
if y <> (IO.eeread(12)) then IO.eewrite(12, y) ' Write Min Brightness Value
goto 10105
'================================================
' F0: BEEP SETUP on / off
' VAR: y,t,z,k
12000:
gosub 9100 ' BEEP
y = IO.eeread(3) ' Read Beep Setting
12005:
z = 0
IO.setenc(y, 1, 0) ' between 0 and 1
12010:
t = IO.getenc()
if t = y goto 12020
y = t
z = 0
12020:
gosub 9000 ' GETKEY
if k = 0 goto 12050 ' no key
gosub 9100 ' BEEP short press
goto 12070
12050:
LED.iall(0) ' Clear display
if z & 15 > 10 goto 12060 ' light pixel for 10 / 15 cycles (flash)