-
Notifications
You must be signed in to change notification settings - Fork 0
/
NixieTemp.ino
318 lines (285 loc) · 7.55 KB
/
NixieTemp.ino
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
/////////////////////////////////////////////
// //
// Nixie Tube Temperature Display //
// Version 1.0 //
// ------- Austin Gilbert -------- //
// //
// : : : : //
// '. _.__ _.__ _.__ _.__ .' //
// ' | | | | | | | | ' //
// |--- | |/-\ | | /| | ||-- | //
// --= | / | | / | |/_| | ||-- | =-- //
// . | / | |/__*| | | | || | . //
// .' |====| |====| |====| |====| '. //
// -||||- -||||- -||||- -||||- //
// //
/////////////////////////////////////////////
#include <Arduino.h>
#include <Wire.h>
#include <DHT.h>
#include <SPI.h>
#include <Arduino_JSON.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <cmath>
// WiFi
const char* ssid = "MySpectrumWiFi2C-2G";
const char* password = "mastergoal312";
// OpenWeatherMap API
// String latitude = "47.661840";
// String longitude = "-122.308690";
String latitude = "34.178560";
String longitude = "-118.769340";
String units = "imperial";
String apiKey = "c38c04c4dfbd1f8a5710153012af6ae2";
String jsonBuffer;
// Data Retrieval Timer
unsigned long lastTime = 0;
unsigned long timerDelay = 10000; // 3 minutes
bool firstTime = true;
// K155ID1 Decoder Pins
#define A1 2 // Tube 1
#define B1 4
#define C1 5
#define D1 12
#define A2 14 // Tube 2
#define B2 15
#define C2 16
#define D2 17
#define A3 18 // Tube 3
#define B3 19
#define C3 21
#define D3 22
#define A4 23 // Tube 4 (& 2)
#define B4 25
#define C4 26
#define D4 27
#define dec 32
#define temp 13
char A[4] = {A1, A2, A3, A4};
char B[4] = {B1, B2, B3, B4};
char C[4] = {C1, C2, C3, C4};
char D[4] = {D1, D2, D3, D4};
// DHT Temperature Sensor
DHT dht(temp, DHT22);
// Other Variables
bool cycleBool = true;
int fSymbol = 1;
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
dht.begin();
// Connecting to WiFi
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
// Connecting to Sensor
float t = dht.readTemperature(true);
while (isnan(t)&& millis() < 5000) {
Serial.println(F("Failed to read form DHT sensor!"));
}
Serial.print("Temperature");
Serial.print(t);
Serial.println(F("°F"));
// Set Inputs and Outputs
pinMode(A1, OUTPUT);
pinMode(B1, OUTPUT);
pinMode(C1, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(B2, OUTPUT);
pinMode(C2, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(B3, OUTPUT);
pinMode(C3, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(B4, OUTPUT);
pinMode(C4, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(dec, OUTPUT);
pinMode(temp, INPUT_PULLUP);
// Apply Voltages
for (char i = 0; i < 4; i++) {
digitalWrite(A[i], HIGH);
digitalWrite(B[i], HIGH);
digitalWrite(C[i], HIGH);
digitalWrite(D[i], HIGH);
}
// digitalWrite(dec, HIGH);
// decimal(false);
// digitalWrite(temp, LOW);
}
void loop() {
if ((millis() - lastTime) > timerDelay || firstTime) {
if(WiFi.status() == WL_CONNECTED) {
String serverPath = "https://api.openweathermap.org/data/2.5/onecall?lat=" + latitude + "&lon=" + longitude + "&exclude=hourly&appid=" + apiKey + "&units=" + units;
jsonBuffer = httpGETRequest(serverPath.c_str());
JSONVar myObject = JSON.parse(jsonBuffer);
if (JSON.typeof(myObject) == "undefined") {
Serial.println("Parsing input failed!");
return;
}
double onlineTempDouble = myObject["current"]["temp"];
float onlineTemp = (float) onlineTempDouble;
// Cycles Digits to prevent Cathode Poisoning
if (firstTime) {
cycle();
firstTime = false;
}
writevalue(onlineTemp);
Serial.print("Online Temperature: ");
Serial.print(myObject["current"]["temp"]);
Serial.println(F("°F"));
} else {
Serial.println("WiFi Disconnected");
}
float sensorTemp = dht.readTemperature(true);
if (isnan(sensorTemp)) {
Serial.println(F("Failed to read from DHT sensor!"));
} else {
Serial.print("Sensor Temperature: ");
Serial.print(sensorTemp);
Serial.println(F("°F"));
}
lastTime = millis();
}
}
void writevalue(float value) {
int digits {value * 10};
if (digits < 1000) {
int digit1 = digits / 100;
int digit2 = digits / 10 % 10;
int digit3 = digits % 10;
writenumber(0, digit1);
writenumber(1, digit2);
// decimal(true);
writenumber(2, digit3);
writenumber(3, fSymbol);
} else {
digits = round(value);
int digit1 = digits / 100;
int digit2 = digits / 10 % 10;
int digit3 = digits % 10;
writenumber(0, digit1);
writenumber(1, digit2);
digitalWrite(dec, HIGH);
// decimal(false);
writenumber(2, digit3);
writenumber(3, fSymbol);
}
}
String httpGETRequest(const char* serverName) {
HTTPClient http;
// Your IP address with path or Domain name with URL path
http.begin(serverName);
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "{}";
if (httpResponseCode>0) {
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
void writenumber(int a, int b) {
switch (b) {
case 0:
digitalWrite(A[a], LOW);
digitalWrite(B[a], LOW);
digitalWrite(C[a], LOW);
digitalWrite(D[a], LOW);
break;
case 1:
digitalWrite(A[a], HIGH);
digitalWrite(B[a], LOW);
digitalWrite(C[a], LOW);
digitalWrite(D[a], LOW);
break;
case 2:
digitalWrite(A[a], LOW);
digitalWrite(B[a], HIGH);
digitalWrite(C[a], LOW);
digitalWrite(D[a], LOW);
break;
case 3:
digitalWrite(A[a], HIGH);
digitalWrite(B[a], HIGH);
digitalWrite(C[a], LOW);
digitalWrite(D[a], LOW);
break;
case 4:
digitalWrite(A[a], LOW);
digitalWrite(B[a], LOW);
digitalWrite(C[a], HIGH);
digitalWrite(D[a], LOW);
break;
case 5:
digitalWrite(A[a], HIGH);
digitalWrite(B[a], LOW);
digitalWrite(C[a], HIGH);
digitalWrite(D[a], LOW);
break;
case 6:
digitalWrite(A[a], LOW);
digitalWrite(B[a], HIGH);
digitalWrite(C[a], HIGH);
digitalWrite(D[a], LOW);
break;
case 7:
digitalWrite(A[a], HIGH);
digitalWrite(B[a], HIGH);
digitalWrite(C[a], HIGH);
digitalWrite(D[a], LOW);
break;
case 8:
digitalWrite(A[a], LOW);
digitalWrite(B[a], LOW);
digitalWrite(C[a], LOW);
digitalWrite(D[a], HIGH);
break;
case 9:
digitalWrite(A[a], HIGH);
digitalWrite(B[a], LOW);
digitalWrite(C[a], LOW);
digitalWrite(D[a], HIGH);
break;
}
}
//void decimal(bool active) {
// if (active = true) {
// digitalWrite(dec, HIGH);
// } else {
// digitalWrite(dec, LOW);
// }
//}
void cycle() {
int starttime = millis();
int endtime = starttime;
while ((endtime - starttime) <=5000) { // do this loop for 5 seconds
for (int i = 0; i < 10; i++) {
for (int m = 0; m < 4; m++){
writenumber(m, i);
}
delay(20);
}
endtime = millis();
}
}
void off(int a) {
digitalWrite(A[a], HIGH);
digitalWrite(B[a], HIGH);
digitalWrite(C[a], HIGH);
digitalWrite(D[a], HIGH);
}