forked from leCandas/M5Stamp-C3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
461 lines (397 loc) · 18 KB
/
main.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
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
#include <SPIFFS.h>
#include <FS.h>
#include "WiFi.h"
#include "ESPAsyncWebServer.h"
#include <Wire.h>
#include <SSVTimer.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <AM232X.h>
#include <Adafruit_MCP23X17.h>
#include <RTClib.h>
// define variables
#define I2C_SDA 1 // I2C
#define I2C_SCL 0 // I2C
#define sensorPin 3 // LDR
#define buzzPin 6
int sensor;
float temp;
float hum;
String dataMessage; // to collect data before print to log
String timeStamp; // to collect time now before print to log
#define BUTTON 9
int lastState = HIGH;
int currentState;
#define wait 1 // probing interval in minute
// Set LED GPIO
int ledPin = 2; // MCP23017 pin LED
String ledState;
// Replace with your network credentials
const char* ssid = "EAsy-Access-Point";
const char* password = "1234";
// Create instances for
AsyncWebServer server(80); // AsyncWebServer object on port 80
SSVTimer timer1; // timer
RTC_PCF8523 rtc; // clock RTC
AM232X AM2320; // sensor H+T
Adafruit_MCP23X17 mcp; // MCP
// Replaces placeholder with LED state value
String processor(const String& var){
Serial.println(var);
if(var == "STATE"){
if(mcp.digitalRead(ledPin)){
ledState = "ON";
}
else{
ledState = "OFF";
}
Serial.print(ledState);
return ledState;
}
return String();
}
// SPIFFS functions
#pragma region ///////////////////////////////////////////// to shrink SPIFFS lines in VS code
#define FORMAT_SPIFFS_IF_FAILED true
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\r\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("- failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println(" - not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.path(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print("\tSIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\r\n", path);
File file = fs.open(path);
if(!file || file.isDirectory()){
Serial.println("- failed to open file for reading");
return;
}
Serial.println("- read from file:");
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\r\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("- failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("- file written");
} else {
Serial.println("- write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\r\n", path);
File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("- failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("- message appended");
} else {
Serial.println("- append failed");
}
file.close();
}
#pragma endregion
// define OLED
#pragma region ///////////////////////////////////////////// to shrink Oled lines in VS code
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define x1 5
#define y1 40
#define x2 72
#define y2 y1
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// 'splashNico', 128x64px
const unsigned char epd_bitmap_splashNico [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xe8, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7c, 0x01, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0x03, 0x80, 0x03, 0x80, 0x01, 0xf8, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0x03, 0x80, 0x03, 0x80, 0x07, 0xff, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0x83, 0x80, 0x03, 0x80, 0x0f, 0xff, 0x80, 0x00, 0x1f, 0xff, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x7b, 0xc3, 0x80, 0x03, 0x80, 0x0f, 0xdf, 0xc0, 0x00, 0x3c, 0x07, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x78, 0xe3, 0x80, 0x03, 0x80, 0x1c, 0x03, 0x80, 0x00, 0xf8, 0x01, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x78, 0xe3, 0x80, 0x03, 0x80, 0x3c, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x78, 0x73, 0x80, 0x03, 0x80, 0x3c, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x00,
0x00, 0x00, 0x78, 0x7b, 0x80, 0x03, 0xc0, 0x78, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x70, 0x00, 0x00,
0x00, 0x00, 0x38, 0x3f, 0x80, 0x03, 0x80, 0x78, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x70, 0x00, 0x00,
0x00, 0x00, 0x38, 0x1f, 0x80, 0x03, 0x80, 0x78, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x70, 0x00, 0x00,
0x00, 0x00, 0x38, 0x0f, 0x80, 0x01, 0x80, 0x78, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x70, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x0f, 0x80, 0x03, 0x80, 0x78, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x60, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x0f, 0x80, 0x03, 0x80, 0x78, 0x00, 0x00, 0x03, 0xc0, 0x00, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x07, 0x80, 0x03, 0x80, 0x78, 0x00, 0x00, 0x03, 0xc0, 0x00, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x07, 0x80, 0x07, 0x80, 0x3c, 0x00, 0x00, 0x03, 0xc0, 0x00, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x07, 0xc0, 0x07, 0x00, 0x1f, 0x00, 0x20, 0x03, 0xe0, 0x01, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x03, 0xc0, 0x07, 0x00, 0x1f, 0xe0, 0xf0, 0x01, 0xe0, 0x01, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x1e, 0x01, 0xc0, 0x07, 0x00, 0x0f, 0xff, 0xe0, 0x00, 0xf0, 0x03, 0x80, 0x00, 0x00,
0x00, 0x00, 0x1e, 0x01, 0xc0, 0x07, 0x80, 0x03, 0xff, 0xc0, 0x00, 0x70, 0x7e, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0e, 0x00, 0x80, 0x03, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 1040)
const int epd_bitmap_allArray_LEN = 1;
const unsigned char* epd_bitmap_allArray[1] = {
epd_bitmap_splashNico
};
#pragma endregion
// read sensor value function
void probe() {
DateTime now = rtc.now();
timeStamp = String(now.year(), DEC) + "/" + String(now.month(), DEC) + "/" + String(now.day(), DEC) + " " + String(now.hour(), DEC)+ ":" + String(now.minute(), DEC) + ":" + String(now.second(), DEC);
int status = AM2320.read();
switch (status)
{
case AM232X_OK:
Serial.println(">>>>> I AM2320 awake ᕙ(`▿´)ᕗ");
break;
default:
Serial.println(status);
break;
}
sensor = analogRead(sensorPin);
temp = AM2320.getTemperature();
hum = AM2320.getHumidity();
Serial.print("Time: "); Serial.println(timeStamp);
Serial.print("Light: "); Serial.print(sensor);
Serial.print(" , Temperature: "); Serial.print(temp); Serial.print("°C , Humidity:"); Serial.print(hum,1); Serial.println("%");
dataMessage = String(timeStamp) + "," + String(sensor) + "," + String(temp) + "," + String(hum) + "," + "<br>" + "\r\n";
// Note: the “\r\n” at the end ensures the next reading is written on the next line.
appendFile(SPIFFS, "/log.html", dataMessage.c_str());
}
void setup() {
Serial.begin(115200);
Wire.begin(I2C_SDA,I2C_SCL);
AM2320.begin();
mcp.begin_I2C();
pinMode(sensorPin, INPUT);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(buzzPin, OUTPUT);
mcp.pinMode(ledPin, OUTPUT);
mcp.digitalWrite(ledPin, LOW);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.initialized() || rtc.lostPower()) {
Serial.println("RTC is NOT initialized, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
//
// Note: allow 2 seconds after inserting battery or applying external power
// without battery before calling adjust(). This gives the PCF8523's
// crystal oscillator time to stabilize. If you call adjust() very quickly
// after the RTC is powered, lostPower() may still return true.
}
rtc.start();
// start SPIFFS
if(!SPIFFS.begin()){
// if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){ // to format partition
Serial.println("SPIFFS Mount Failed");
return;
}
writeFile(SPIFFS, "/log.html", "timeStamp, LDR, Temperature, Humidity, <br> \r\n"); // to create the file
// Note: the “\r\n” at the end ensures the next reading is written on the next line.
listDir(SPIFFS, "/", 0);
timer1.SetEnabled(true);
timer1.SetInterval((wait)*60*1000);
timer1.SetOnTimer(probe);
if (! AM2320.begin() ) {
Serial.println("Sensor not found");
while (1);
}
delay(3000);
// Connect to Wi-Fi network with SSID and password
Serial.println("Setting AP (Access Point)…");
// Remove the password parameter, if you want the AP (Access Point) to be open
//WiFi.softAP(ssid, password);
WiFi.softAP(ssid);
// Print AccessPoint IP address and start web server
IPAddress IP = WiFi.softAPIP();
Serial.print("Page on this IP address: ");
Serial.println(IP);
#pragma region ///////////////////////////////////////////// config web server
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/index.html", String(), false, processor);
});
// Route to load style.css file
server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/style.css", "text/css");
});
// Route to set GPIO to HIGH
server.on("/on", HTTP_GET, [](AsyncWebServerRequest *request){
mcp.digitalWrite(ledPin, HIGH);
request->send(SPIFFS, "/index.html", String(), false, processor);
});
// Route to set GPIO to LOW
server.on("/off", HTTP_GET, [](AsyncWebServerRequest *request){
mcp.digitalWrite(ledPin, LOW);
request->send(SPIFFS, "/index.html", String(), false, processor);
});
// Route to show log.html
server.on("/html", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/log.html", "text/html");
});
// Route to show text.txt
server.on("/quote", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/quote.html", "text/html");
});
// Route to show text.txt
server.on("/data", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/log.txt", "text/plain");
});
#pragma endregion
server.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10, 45);
// Display static text
display.println("the awesome logger");
Serial.println("Oled monitor online");
display.drawBitmap(0, -5, epd_bitmap_splashNico, 128, 64, 1);
// drawBitmap() method that accepts the following arguments (x, y, image array, image width, image height, rotation)
display.display();
delay(100);
AM2320.wakeUp();
int status = AM2320.read();
switch (status)
{
case AM232X_OK:
Serial.println("AM2320 sensor OK");
break;
default:
Serial.println(status);
break;
}
delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
timer1.RefreshIt();
currentState = digitalRead(BUTTON);
if(lastState == LOW && currentState == HIGH) {
Serial.println("Button Pressed!");
tone(buzzPin, 125, 100);
tone(buzzPin, 250, 125);
tone(buzzPin, 100, 100);
tone(buzzPin, 250, 125);
tone(buzzPin, 750, 100);
tone(buzzPin, 250, 250);
tone(buzzPin, 100, 100);
// clear display
display.clearDisplay();
delay(100);
noTone(buzzPin);
// show logo
display.drawBitmap(0, -5, epd_bitmap_splashNico, 128, 64, 1);
// display temperature
display.setTextSize(1);
display.setCursor(x1,y1);
display.print("Temp: ");
display.setTextSize(2);
display.setCursor(x1,(y1+10));
display.print(AM2320.getTemperature(),0);
//display.print(" ");
display.setTextSize(1);
display.cp437(true); // To display the º symbol, we use the Code Page 437 font
display.write(167); // to display your chosen character. The º symbol corresponds to character 167.
display.setTextSize(2);
display.print("C");
// display humidity
display.setTextSize(1);
display.setCursor(x2, y2);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(x2, (y2+10));
display.print(hum,0);
display.setTextSize(2);
display.print("%");
display.display();
readFile(SPIFFS, "/log.html");
}
lastState = currentState;
delay(100);
}