//#include <Wire.h>// I2C devices communication
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>//Monochrome OLEDs, diff Width/Hight
#include <DHT.h>
#define DHT_PIN 2
DHT dht(DHT_PIN, DHT22);
Adafruit_SSD1306 oled(128, 64, &Wire, -1); //-1= OLED_RESET
void setup() { Serial.begin(9600); dht.begin();
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //I2C address 0x3C
Serial.println(F("failed to start")); while (1); }
delay(2000); /* oled.clearDisplay(); */ }
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
oled.setTextSize(1);/*1.5 даёт тоже самое*/ oled.setTextColor(WHITE);
oled.setCursor(0, 20); // (x,y)
oled.print("Temperature"); oled.setCursor(80, 20); oled.print(temperature);
oled.setCursor(120,20); oled.print("C");
oled.setCursor(0,45);
//oled.setFont(BigNumbers); Нужна "OLED_I2C.h" Key0 wokwi OLED_I2C.h
//oled.setFont(RusFont); oled.print("DSCJNF",CENTER,0); //Надпись "ВЫСОТА",поЦентру
oled.print("Humidity"); oled.setCursor(80,45); oled.print(humidity);
oled.setCursor(120,45); oled.print("%");
oled.display();
if (!isnan(temperature) && !isnan(humidity)) {
Serial.print("Temperature (°C): "); Serial.println(temperature);
Serial.print("Humidity (%): "); Serial.println(humidity);
} else Serial.println("Error reading from DHT sensor");
delay(2000); oled.clearDisplay();
}
Loading
ssd1306
ssd1306