-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVirtual_Nixie_Clock-master.ino
More file actions
371 lines (315 loc) · 9.6 KB
/
Copy pathVirtual_Nixie_Clock-master.ino
File metadata and controls
371 lines (315 loc) · 9.6 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
365
366
367
368
369
370
371
/* -------------------------------------------------------------------------
Virtual Nixie Tube Clock is built on RGB Led Matrix 64x64.
Library: PxMatrix.
Led matrix: P2.5 RGB 64x64
------------------------------------------------------------------------- */
#define double_buffer
#include <PxMatrix.h>
// WIFI SETUP
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
const char* ssid = "FPTTelecom"; // SSID of local network
const char* password = "12345678"; // Password on network
#define NTP_OFFSET 25200 // In seconds - Time offset
#define NTP_INTERVAL 60 * 1000 // In miliseconds
#define NTP_ADDRESS "1.asia.pool.ntp.org"
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, NTP_ADDRESS, NTP_OFFSET, NTP_INTERVAL);
#define DISPLAY_DRAW_TIME 10
unsigned long samplingtime = 0;
unsigned long samplingtimes0 = 0;
unsigned long samplingtimes1 = 0;
unsigned long samplingtimem0 = 0;
unsigned long samplingtimem1 = 0;
unsigned long samplingtimeh0 = 0;
unsigned long samplingtimeh1 = 0;
int s0, s1, m0, m1, h0, h1;
int prves0, prves1, prvem0, prvem1, prveh0, prveh1;
bool dotstate=1;
#ifdef ESP32
#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 5
#define P_E 15
#define P_OE 2
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
#endif
#ifdef ESP8266
#include <Ticker.h>
Ticker display_ticker;
#define P_LAT 16
#define P_A 5
#define P_B 4
#define P_C 15
#define P_D 12
#define P_E 0
#define P_OE 2
#endif
// Pins for LED MATRIX
PxMATRIX display(64,64,P_LAT, P_OE,P_A,P_B,P_C,P_D,P_E);
uint16_t myRED = display.color565(255, 0, 0);
uint16_t myGREEN = display.color565(0, 255, 0);
uint16_t myBLUE = display.color565(0, 0, 255);
uint16_t myMAGENTA = display.color565(255, 0, 255);
uint16_t myYELLOW = display.color565(255, 255, 0);
uint16_t myCYAN = display.color565(0, 255, 255);
uint16_t myBLACK = display.color565(0, 0, 0);
uint16_t myWHITE = display.color565(255, 255, 255);
uint16_t myCOLORS[7]={myRED, myGREEN, myCYAN, myMAGENTA, myYELLOW, myBLUE, myWHITE};
#ifdef ESP8266
// ISR for display refresh
void display_updater()
{
display.display(DISPLAY_DRAW_TIME);
}
#endif
#ifdef ESP32
void IRAM_ATTR display_updater() {
display.display(DISPLAY_DRAW_TIME);
}
#endif
/* The Nixie Numbers Code */
#include "NixieNumbers.h"
NixieNumbers NixieNumbers(&display);
/* Small Nixie Number*/
const uint16_t *Numbers_S[10] = {
Nixie_20x31_0,
Nixie_20x31_1,
Nixie_20x31_2,
Nixie_20x31_3,
Nixie_20x31_4,
Nixie_20x31_5,
Nixie_20x31_6,
Nixie_20x31_7,
Nixie_20x31_8,
Nixie_20x31_9,
};
/* Big Nixie Number*/
const uint16_t *Numbers_B[10] = {
Nixie_32x61_0,
Nixie_32x61_1,
Nixie_32x61_2,
Nixie_32x61_3,
Nixie_32x61_4,
Nixie_32x61_5,
Nixie_32x61_6,
Nixie_32x61_7,
Nixie_32x61_8,
Nixie_32x61_9,
};
void setup()
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
timeClient.begin();
//Serial.begin(115200);
display.begin(32);
display.setMuxDelay(1,1,1,1,1); // Delay multiplexing - Important for some panel with slow multiplexer
display.setFastUpdate(true);
display.clearDisplay();
#ifdef ESP8266
display_ticker.attach(0.002, display_updater);
#endif
#ifdef ESP32
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &display_updater, true);
timerAlarmWrite(timer, 2000, true);
timerAlarmEnable(timer);
#endif
}
void loop()
{
timeClient.update();
int rawTime = timeClient.getEpochTime();
int hours = (rawTime % 86400L) / 3600;
int minutes = (rawTime % 3600) / 60;
int seconds = rawTime % 60;
h1 = ((hours/10));
h0 = (hours%10);
m1 = ((minutes/10));
m0 = (minutes%10);
s1 = ((seconds/10));
s0 = (seconds%10);
if (seconds>=0 && seconds<=30) // Show all digits when seconds is from 0 ~ 30 in Small Nixie Number.
{
if (seconds==0)
{
NixieNumbers.clearNumber(0, 0, NUMBER_WIDTH_B, NUMBER_HEIGHT_B); // Clear Big Nixie Number
NixieNumbers.clearNumber(32, 0, NUMBER_WIDTH_B, NUMBER_HEIGHT_B); // Clear Big Nixie Number
}
Nixie_S0();
Nixie_S1();
Nixie_M0();
Nixie_M1();
Nixie_H0();
Nixie_H1();
}
else // Show seconds from 31 ~ 59 in Big Nixie Number.
{
if (seconds==31)
{
NixieNumbers.clearNumber(0, 0, NUMBER_WIDTH_S, NUMBER_HEIGHT_S); // Clear Small Nixie Number
NixieNumbers.clearNumber(0, 33, NUMBER_WIDTH_S, NUMBER_HEIGHT_S); // Clear Small Nixie Number
NixieNumbers.clearNumber(22, 0, NUMBER_WIDTH_S, NUMBER_HEIGHT_S); // Clear Small Nixie Number
NixieNumbers.clearNumber(22, 33, NUMBER_WIDTH_S, NUMBER_HEIGHT_S); // Clear Small Nixie Number
NixieNumbers.clearNumber(44, 0, NUMBER_WIDTH_S, NUMBER_HEIGHT_S); // Clear Small Nixie Number
NixieNumbers.clearNumber(44, 33, NUMBER_WIDTH_S, NUMBER_HEIGHT_S); // Clear Small Nixie Number
}
Nixie_S0_B();
Nixie_S1_B();
}
/* Show the contents of buffer to led matrix screen */
display.showBuffer();
}
void Nixie_S1()
{
if ((unsigned long) (micros() - samplingtimes1) > 101)
{
if (s1 != prves1)
{
//display.clearDisplay();
NixieNumbers.clearNumber(44, 0, NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
NixieNumbers.drawNumber(44, 0, Numbers_S[s1], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
prves1 = s1;
}
else
{
NixieNumbers.drawNumber(44, 0, Numbers_S[prves1], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
}
samplingtimes1 = micros();
}
}
void Nixie_S0()
{
if ((unsigned long) (micros() - samplingtimes0) > 99)
{
if (s0 != prves0)
{
//display.clearDisplay();
NixieNumbers.clearNumber(44, 33, NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
NixieNumbers.drawNumber(44, 33, Numbers_S[s0], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
prves0 = s0;
}
else
{
NixieNumbers.drawNumber(44, 33, Numbers_S[prves0], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
}
samplingtimes0 = micros();
}
}
void Nixie_M1()
{
if ((unsigned long) (micros() - samplingtimem1) > 105)
{
if (m1 != prvem1)
{
//display.clearDisplay();
NixieNumbers.clearNumber(22, 0, NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
NixieNumbers.drawNumber(22, 0, Numbers_S[m1], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
prvem1 = m1;
}
else
{
NixieNumbers.drawNumber(22, 0, Numbers_S[prvem1], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
}
samplingtimem1 = micros();
}
}
void Nixie_M0()
{
if ((unsigned long) (micros() - samplingtimem0) > 103)
{
if (m0!=prvem0)
{
//display.clearDisplay();
NixieNumbers.clearNumber(22, 33, NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
NixieNumbers.drawNumber(22, 33, Numbers_S[m0], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
prvem0 = m0;
}
else
{
NixieNumbers.drawNumber(22, 33, Numbers_S[prvem0], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
}
samplingtimem0 = micros();
}
}
void Nixie_H1()
{
if ((unsigned long) (micros() - samplingtimeh1) > 109)
{
if (h1 != prveh1)
{
//display.clearDisplay();
NixieNumbers.clearNumber(0, 0, NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
NixieNumbers.drawNumber(0, 0, Numbers_S[h1], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
prveh1 = h1;
}
else
{
NixieNumbers.drawNumber(0, 0, Numbers_S[prveh1], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
}
samplingtimeh1 = micros();
}
}
void Nixie_H0()
{
if ((unsigned long) (micros() - samplingtimeh0) > 107)
{
if (h0 != prveh0)
{
//display.clearDisplay();
NixieNumbers.clearNumber(0, 33, NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
NixieNumbers.drawNumber(0, 33, Numbers_S[h0], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
prveh0 = h0;
}
else
{
NixieNumbers.drawNumber(0, 33, Numbers_S[prveh0], NUMBER_WIDTH_S, NUMBER_HEIGHT_S);
}
samplingtimeh0 = micros();
}
}
void Nixie_S1_B()
{
if ((unsigned long) (micros() - samplingtimes1) > 101)
{
if (s1 != prves1)
{
//display.clearDisplay();
NixieNumbers.clearNumber(0, 0, NUMBER_WIDTH_B, NUMBER_HEIGHT_B);
NixieNumbers.drawNumber(0, 0, Numbers_B[s1], NUMBER_WIDTH_B, NUMBER_HEIGHT_B);
prves1 = s1;
}
else
{
NixieNumbers.drawNumber(0, 0, Numbers_B[prves1], NUMBER_WIDTH_B, NUMBER_HEIGHT_B);
}
samplingtimes1 = micros();
}
}
void Nixie_S0_B()
{
if ((unsigned long) (micros() - samplingtimes0) > 99)
{
if (s0 != prves0)
{
//display.clearDisplay();
NixieNumbers.clearNumber(32, 0, NUMBER_WIDTH_B, NUMBER_HEIGHT_B);
NixieNumbers.drawNumber(32, 0, Numbers_B[s0], NUMBER_WIDTH_B, NUMBER_HEIGHT_B);
prves0 = s0;
}
else
{
NixieNumbers.drawNumber(32, 0, Numbers_B[prves0], NUMBER_WIDTH_B, NUMBER_HEIGHT_B);
}
samplingtimes0 = micros();
}
}