-
Notifications
You must be signed in to change notification settings - Fork 11
/
NixieTubeTest.cpp
152 lines (121 loc) · 3.31 KB
/
NixieTubeTest.cpp
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
#include "NixieTubeTest.h"
#include "VFDTube.h"
#define TUBE_COUNT 1
VFDTube tube(4, 5, 6, 7, TUBE_COUNT);
// DIN on pin #4, OE on pin #5, STCP on pin #6, SHCP on pin #7,
// TUBE_COUNT stands for sections count in serial
// Pin #5 is with PWM output on UNO, so the brightness is adjustable
const uint8_t PROGMEM STROCK_ORDER[] = { 2, 4, 7, 5, 1, 0, 8, // 0
1, 5, 8, 8, 8, 8, 8, // 1
0, 1, 3, 4, 7, 8, 8, // 2
0, 1, 3, 5, 7, 8, 8, // 3
2, 3, 1, 5, 8, 8, 8, // 4
2, 3, 5, 7, 0, 8, 8, // 5
0, 2, 4, 7, 5, 3, 8, // 6
0, 1, 5, 8, 8, 8, 8, // 7
1, 0, 2, 4, 7, 5, 3, // 8
0, 2, 3, 1, 5, 7, 8, // 9
};
void transformBlink(byte index, byte dest) {
byte tmp = tube.getPattern(index);
for (byte j = 0; j < 4; j++) {
tube.setPattern(index, tmp);
tube.display(0x20);
tube.setPattern(index, dest);
tube.display(0x20);
}
}
void transformHalf(byte index, byte dest) {
byte tmp = tube.getPattern(index);
tube.setPattern(index, tmp & 0x07);
tube.display(0x60);
tube.setPattern(index, (tmp & 0x07) | (dest & 0xe8));
tube.display(0x60);
tube.setPattern(index, dest & 0xb8);
tube.display(0x60);
}
void transformOneThird(byte index, byte dest) {
byte mask[2] = { 0xab, 0x22 };
for (byte i = 0; i < 2; i++) {
tube.setPattern(index, tube.getPattern(index) & mask[i]);
tube.display(0x60);
}
tube.setPattern(index, 0x00);
tube.display(0x60);
for (byte i = 0; i < 2; i++) {
tube.setPattern(index, dest & mask[1 - i]);
tube.display(0x60);
}
}
void transformAnd(byte index, byte dest) {
tube.setPattern(index, tube.getPattern(index) & dest);
tube.display(0xc0);
}
void transformOr(byte index, byte dest) {
tube.setPattern(index, tube.getPattern(index) | dest);
tube.display(0xc0);
}
void transformRoll(byte index, byte dest) {
byte mask[4] = { 0xbe, 0xb8, 0xb0, 0x80 };
for (byte i = 0; i < 4; i++) {
tube.setPattern(index, tube.getPattern(index) & mask[i]);
tube.display(0x40);
}
tube.setPattern(index, 0x00);
tube.display(0x40);
for (byte i = 0; i < 4; i++) {
tube.setPattern(index, dest & (~mask[i] & 0xdf));
tube.display(0x40);
}
}
void transformTypeDigit(byte index, byte src, byte dest) {
byte tmp = tube.getPattern(index);
for (byte i = 0; i < 7; i++) {
byte c = pgm_read_byte_near(STROCK_ORDER + 7 * src + 6- i);
if (c < 8)
bitClear(tmp, c);
tube.setPattern(index, tmp);
tube.display(0x40);
}
for (byte i = 0; i < 7; i++) {
byte c = pgm_read_byte_near(STROCK_ORDER + 7 * dest + i);
if (c < 8)
bitSet(tmp, c);
tube.setPattern(index, tmp);
tube.display(0x40);
}
}
void (*pTransform[6])(byte, byte)=
{
transformBlink,
transformHalf,
transformAnd,
transformOr,
transformRoll,
transformOneThird,
};
void setup() {
tube.clear();
}
void loop() {
tube.setBackgroundColor(Black);
for (byte i = 0; i < 10; i++) {
tube.setPattern(0, pgm_read_byte_near(VFDTUBE_FONT+i));
tube.display(1000);
}
for (byte k = 0; k < 6; k++) {
tube.setBackgroundColor(0, (Color) ((k + 1) % 7));
for (byte i = 0; i < 10; i++) {
tube.setPattern(0, pgm_read_byte_near(VFDTUBE_FONT+i));
tube.display(1000);
(*pTransform[k])(0, pgm_read_byte_near(VFDTUBE_FONT+(i+1)%10));
}
delay(0x80);
}
tube.setBackgroundColor(White);
for (byte i = 0; i < 10; i++) {
tube.setPattern(0, pgm_read_byte_near(VFDTUBE_FONT+i));
tube.display(1000);
transformTypeDigit(0, i, (i + 1) % 10);
}
}