#include <dht.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#define DHT22_PIN PB1
dht DHT;
void splash() {
oled.clear();
oled.setCursor(18, 2);
oled.print(F("Station 001"));
}
void prepareDisplay() {
unsigned int i, k;
unsigned char ch[5];
oled.clear();
oled.begin();
oled.setCursor(18, 0);
oled.print(F("Station 001"));
}
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(FONT8X16);
// To clear all the memory
oled.clear();
oled.on();
splash();
delay(1600);
prepareDisplay();
}
void loop() {
static long startTime = 0;
long currentTime;
DHT.read22(DHT22_PIN);
// Get current time
currentTime = millis();
// Checks 1 second passed
if ((currentTime - startTime) > 1000) {
startTime = currentTime;
// Update temperature
float temperature = getTemperature();
// Set cursor
oled.setCursor(12, 28);
// Print to display
oled.print(temperature, 1);
oled.print("C");
// Update humidity
float humidity = getHumidity();
// Set cursor
oled.setCursor(80, 28);
// Print to display
oled.print(humidity, 1);
oled.print("%");
}
}