#include "U8glib.h"
#include <DHT.h>
#define DHTPIN A1
#define DHTTYPE DHT11
float hum_float;
DHT dht(DHTPIN, DHTTYPE);
U8GLIB_ST7920_128X64_1X u8g(6, 7, 8, 9, 10, 11, 12, 13, 2, 4, 3, 5);
void setup() {
dht.begin();
if (u8g.getMode() == U8G_MODE_R3G3B2) {
u8g.setColorIndex(255); // white
}
else if (u8g.getMode() == U8G_MODE_GRAY2BIT) {
u8g.setColorIndex(3); // max intensity
}
else if (u8g.getMode() == U8G_MODE_BW) {
u8g.setColorIndex(1); // pixel on
}
else if (u8g.getMode() == U8G_MODE_HICOLOR) {
u8g.setHiColorByRGB(255, 255, 255);
}
}
void loop() {
u8g.firstPage();
do {
draw();
} while (u8g.nextPage());
}
void draw() {
float h = dht.readHumidity();
float t = dht.readTemperature();
u8g.setFont(u8g_font_6x10);
u8g.drawFrame(0, 0, 128, 31); // upper frame
u8g.drawFrame(0, 33, 128, 31); // lower frame
u8g.drawStr(15, 13, "Temperature");
u8g.drawStr(15, 45, "Humidity");
u8g.setPrintPos(75, 27); // set position
u8g.print(t);
u8g.print("'C");
u8g.setPrintPos(75, 60); // set position
u8g.print(h);
u8g.print(" %");
}