-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathST7920_DHT22.ino
60 lines (46 loc) · 1.09 KB
/
ST7920_DHT22.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
#include <DHT.h>
#include <U8g2lib.h>
#include <U8x8lib.h>
#define DHTTYPE DHT22
char temperature [5];
char humidity [5];
const char DEGREE_SYMBOL[] = { 0xB0, '\0' };
DHT dht(7, DHTTYPE);
U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8);
void setup() {
dht.begin();
Serial.begin(9600);
u8g2.begin();
u8g2.enableUTF8Print();
u8g2.setFont(u8g2_font_helvB10_tf);
u8g2.setColorIndex(1);
}
void loop() {
u8g2.firstPage();
do {
draw();
} while( u8g2.nextPage() );
}
void draw(){
readTemperature();
readHumidity();
u8g2.drawFrame(0,0,128,31);
u8g2.drawFrame(0,33,128,31);
u8g2.drawStr( 15, 13, "Temperature");
u8g2.drawStr( 35, 28, temperature);
u8g2.drawUTF8(70, 28, DEGREE_SYMBOL);
u8g2.drawUTF8(76, 28, "C");
u8g2.drawStr(30,46, "Humidity");
u8g2.drawStr( 37, 61, humidity);
u8g2.drawStr(75,61, "%");
}
void readTemperature()
{
float t = dht.readTemperature();
dtostrf(t, 3, 1, temperature);
}
void readHumidity()
{
float h = dht.readHumidity();
dtostrf(h, 3, 1, humidity);
}