-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMenCaveMonitor.ino
More file actions
136 lines (101 loc) · 2.7 KB
/
MenCaveMonitor.ino
File metadata and controls
136 lines (101 loc) · 2.7 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
#include <esp_now.h>
#include <WiFi.h>
#include <TFT_eSPI.h>
#include "BAT.h"
#include "font.h"
#define gray 0xBDD7
#define yel 0xFEC0
TFT_eSPI tft = TFT_eSPI();
const int pwmFreq = 5000;
const int pwmResolution = 8;
const int pwmLedChannelTFT = 5;
typedef struct struct_message {
int h;
int m;
int s;
int wd;
int mo;
int da;
int ye;
float tmpC;
float tmpF;
float pre;
float hum;
} struct_message;
struct_message myData;
String minutes, seconds, hours,days,months;
String Wdays[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
bool metric=1;
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
if(myData.m<10)
minutes="0"+String(myData.m);
else
minutes=String(myData.m);
if(myData.s<10)
seconds="0"+String(myData.s);
else
seconds=String(myData.s);
if(myData.h<10)
hours="0"+String(myData.h);
else
hours=String(myData.h);
if(myData.da<10)
days="0"+String(myData.da);
else
days=String(myData.da);
if(myData.mo<10)
months="0"+String(myData.mo);
else
months=String(myData.mo);
tft.setTextColor(yel,TFT_BLACK);
tft.drawString(Wdays[myData.wd-1],172,88,2);
tft.drawString(days+"/"+months,172,104,2);
tft.drawString("YoutubeChannel",92,214,2);
tft.setFreeFont(&DSEG14_Classic_Bold_18);
tft.setTextColor(gray,TFT_BLACK);
tft.drawString(seconds,132,100);
tft.setFreeFont(&DSEG7_Classic_Bold_30);
tft.setTextColor(gray,TFT_BLACK);
tft.drawString(hours+":"+minutes,18,88);
tft.setFreeFont(&DSEG7_Classic_Bold_36);
if(metric==1)
tft.drawString(String((int)myData.tmpC),12,166 );
else
tft.drawString(String((int)myData.tmpF),12,166 );
tft.drawString(String((int)myData.hum)+"%",100,180,4);
tft.drawString(String((int)myData.pre)+"hPa",174,176,2);
tft.drawCircle(76,162,3,gray);
}
void setup() {
pinMode(12,INPUT_PULLUP);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_register_recv_cb(OnDataRecv);
ledcSetup(pwmLedChannelTFT, pwmFreq, pwmResolution);
ledcAttachPin(17, pwmLedChannelTFT);
ledcWrite(pwmLedChannelTFT, 120);
tft.init();
tft.setRotation(0);
tft.setSwapBytes(true);
tft.fillScreen(TFT_BLACK);
tft.pushImage(0,0,240,240,BAT);
}
int pom=0;
void loop() {
if(digitalRead(12)==0)
{
if(pom==0)
{
pom=1;
metric=!metric;
delay(200);
}
}else pom=0;
}