Skip to content

Commit 0be6cc0

Browse files
authored
Merge pull request #78 from mystster:writeCurrentTemp
add write current temp.
2 parents f717229 + 230e7c9 commit 0be6cc0

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

Arduino/WeatherDisplay/WeatherDisplay.ino

+33-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// include library, include base class, make path known
55
#include <GxEPD.h>
66
#include <GxGDEW029T5/GxGDEW029T5.h> // 2.9" b/w IL0373
7+
#include <Fonts/FreeMonoBold9pt7b.h>
78

89
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
910
#include <GxIO/GxIO.h>
@@ -37,10 +38,12 @@ DHT dht(DHTPIN, DHTTYPE);
3738

3839
const uint32_t getWeatherInfoPeriod = 10 * 60 * 1000;
3940
const uint32_t getCurrentTempPeriod = 1 * 60 * 1000;
41+
const uint32_t writeCurrentTempPeriod = 5 * 60 * 1000;
4042

4143
struct {
4244
uint64_t getWeatherInfoJpeg;
4345
uint64_t getCurrentTemp;
46+
uint64_t writeCurrentTemp;
4447
} lastExecDate;
4548

4649

@@ -50,6 +53,8 @@ void setup()
5053
Serial.println();
5154
Serial.println("setup");
5255
display.init(74880); // enable diagnostic output on Serial
56+
display.setFont(&FreeMonoBold9pt7b);
57+
display.setTextColor(GxEPD_BLACK);
5358

5459
WiFi.begin(SECRET_SSID, SECRET_SSID_PASSWORD);
5560

@@ -89,13 +94,22 @@ void loop()
8994
Serial.println("getWeatherInfoJpeg()");
9095
getWeatherInfoJpeg();
9196
lastExecDate.getWeatherInfoJpeg = now;
97+
Serial.println("writeCurrentTemp()");
98+
writeCurrentTemp();
99+
lastExecDate.writeCurrentTemp = now;
92100
}
93101
if (lastExecDate.getCurrentTemp == 0 || now - lastExecDate.getCurrentTemp > getCurrentTempPeriod)
94102
{
95103
Serial.println("getCurrentTemp()");
96104
getCurrentTemp();
97105
lastExecDate.getCurrentTemp = now;
98106
}
107+
if (lastExecDate.writeCurrentTemp == 0 || now - lastExecDate.writeCurrentTemp > writeCurrentTempPeriod)
108+
{
109+
Serial.println("writeCurrentTemp()");
110+
writeCurrentTemp();
111+
lastExecDate.writeCurrentTemp = now;
112+
}
99113
}
100114

101115
void getWeatherInfoJpeg(){
@@ -139,4 +153,22 @@ void getCurrentTemp()
139153
ambient.set(1, t);
140154
ambient.set(2, h);
141155
ambient.send();
142-
}
156+
}
157+
158+
void writeCurrentTemp() {
159+
int posX = 180;
160+
int posY = 124;
161+
int boxW = 100;
162+
int boxH = 20;
163+
164+
float t = dht.readTemperature();
165+
float h = dht.readHumidity();
166+
Serial.printf("temp:%.1f, humi:%.1f\n", t, h);
167+
168+
display.setRotation(3);
169+
display.setCursor(posX, posY);
170+
display.fillRect(posX, posY - boxH , boxW, boxH + 2, GxEPD_WHITE);
171+
display.printf("%.1fC/%.0f%%", t, h);
172+
display.updateWindow(posX, posY - boxH, boxW, boxH + 2, true);
173+
display.powerDown();
174+
}

0 commit comments

Comments
 (0)