-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtemp.h
83 lines (70 loc) · 1.52 KB
/
htemp.h
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
/*
Humidity and Temperature DHT22 sensor
*/
#include <DHT.h>
#include <DHT_U.h>
#define DHTTYPE DHT22
#define DHT22_PIN 11
DHT dht(DHT22_PIN, DHTTYPE);
class HTSensor {
private:
float h;
float t;
float hic;
public:
String humPreStr = "H: ";
String humPostStr = "%";
String tempPreStr = "T: ";
String tempPostStr = "\xDF";
String feelPreStr = "Feels: ";
void htSetup(){
dht.begin();
}
void htLoop(){
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h = dht.readHumidity();
// Read temperature as Celsius (the default)
t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
return;
}
// Compute heat index in Celsius
hic = dht.computeHeatIndex(t, h, false);
}
String hRead(){
String buf;
buf += humPreStr;
buf += String(h,0);
buf += humPostStr;
return buf;
}
String tRead(){
String buf;
buf += tempPreStr;
buf += String(t,0);
buf += tempPostStr;
return buf;
}
String fRead(){
String buf;
buf += feelPreStr;
buf += String(hic,0);
buf += tempPostStr;
return buf;
}
void displayValues(){
lcd.clear();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(hRead());
lcd.setCursor(0,1);
lcd.print(tRead());
lcd.setCursor(0,3);
lcd.print(fRead());
delay(5000);
lcd.noBacklight();
}
};
HTSensor ht;