#include <dht.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#define DHT22_PIN PB1
dht DHT;
void splash() {
oled.setCursor(13, 1);
oled.print(F("ATtiny85 & SSD1306"));
oled.setCursor(12, 7);
oled.print(F("^_^ ^_^ ^_^ ^_^"));
}
float getTemperature() {
return DHT.temperature;
}
float getHumidity() {
return DHT.humidity;
}
void setup() {
pinMode(DHT22_PIN, INPUT);
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT6X8);
// To clear all the memory
oled.on();
splash();
delay (3000);
oled.clear();
}
void loop() {
DHT.read22(DHT22_PIN);
// Update temperature
float temperature = getTemperature();
oled.setCursor(1, 3);
oled.print(F("temperature"));
// Set cursor
oled.setCursor(75, 3);
// Print to display
oled.print(temperature, 1);
oled.print("C");
// Update humidity
float humidity = getHumidity();
oled.setCursor(1, 5);
oled.print(F("humidity"));
// Set cursor
oled.setCursor(75, 5);
// Print to display
oled.print(humidity, 1);
oled.print("%");
}