#include <DHT.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 disp(SCREEN_WIDTH,SCREEN_HEIGHT,&Wire,OLED_RESET);
#define DHT22PIN 18
DHT dht(DHT22PIN,DHT22);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
dht.begin();
if(!disp.begin(SSD1306_SWITCHCAPVCC,SCREEN_ADDRESS))
{
Serial.println("SSD allocation fialed");
for(;;);
}
}
void loop() {
// put your main code here, to run repeatedly:
float humi = dht.readHumidity();
float temp = dht.readTemperature();
Serial.println('Humidty:');
Serial.println(humi);
Serial.println('Temperature:');
Serial.println(temp);
disp.clearDisplay();
disp.setTextSize(2);
disp.setCursor(6,0);
disp.setTextColor(SSD1306_WHITE);
disp.print("Humi");
disp.println(humi);
disp.println(temp);
disp.display();
delay(1000); // this speeds up the simulation
}