#include <Wire.h>
#include <oled.h>
#include <DHT.h>


// create an OLED display object connected to I2C

OLED display(21,22,NO_RESET_PIN,OLED::W_128,OLED::H_64,OLED::CTRL_SH1106,0x3C);

String  displayString;
String  displayString2;
String  grzalka;
String  wiatrak;


#define DHTPIN 14
#define DHTPIN2 27
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);

float hum1;  //Stores humidity value
float temp1; //Stores temperature value
float hum2;  //Stores humidity value
float temp2; //Stores temperature value

unsigned long aktualnyCzas = 0;
unsigned long zapamietanyCzasW = 0;
unsigned long zapamietanyCzasG = 0;



void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  // --- temp/hum sensor --//
  dht.begin();
  dht2.begin();
  // --- temp/hum sensor --//
  
  display.begin();

  // --- led --//
  pinMode(23, OUTPUT);
  digitalWrite(23, LOW);
  pinMode(19, OUTPUT);
  digitalWrite(19, LOW);
  wiatrak = "wiatrak    off"; 
  grzalka = "grzalka    off"; 
  // --- led --//

delay(2000);         // wait two seconds for initializing

}

void loop() {

  aktualnyCzas = millis();
    //Read data and store it to variables hum and temp
  //hum1 = dht.readHumidity();
  temp1 = dht.readTemperature();
  //hum2 = dht2.readHumidity();
  temp2 = dht2.readTemperature();
    //Print temp and humidity values to serial monitor
/*    Serial.print("Humidity: ");
    Serial.print(hum1);
    Serial.print(" %, Temp: ");
    Serial.print(temp1);
    Serial.println(" Celsius");
    Serial.print("Humidity: ");
    Serial.print(hum2);
    Serial.print(" %, Temp: ");
    Serial.print(temp2);
    Serial.println(" Celsius");
*/

  // -- warunek wiatrak/grzalka
  
  if (isnan(temp2) || isnan(temp1))
    displayString = "Failed temp sypialnia";
  else {
  if (temp1 < 21 ){
    if (temp2 > 23){
        digitalWrite(19, HIGH);
        wiatrak = "wiatrak    on";        
        zapamietanyCzasW = aktualnyCzas;
        if ((grzalka = "grzalka    on")){
            digitalWrite(23, LOW);
            grzalka = "grzalka    off";
        }
      }
    else{
      digitalWrite(19, HIGH);
      wiatrak = "wiatrak    on";
      zapamietanyCzasW = aktualnyCzas;
      digitalWrite(23, HIGH);
      grzalka = "grzalka    on";
      zapamietanyCzasG = aktualnyCzas;
      }
    }

  if (aktualnyCzas - zapamietanyCzasW >= 10000UL){

    if ((digitalRead(23) == HIGH) && (digitalRead(19) == HIGH)){
      digitalWrite(23, LOW);
      grzalka = "grzalka    off";
    }
    if ((digitalRead(23) == LOW) && (digitalRead(19) == HIGH) && (aktualnyCzas - zapamietanyCzasG >= 15000UL)){
      digitalWrite(19, LOW);
      wiatrak = "wiatrak    off";
    }

  }
  }
  // -- oled info
    displayString = "Sypialnia: ";
    displayString += String(temp1, 1); // one decimal places
    displayString += " C";
    displayString2 = "Salon:     ";
    displayString2 += String(temp2, 1); // one decimal places
    displayString2 += " C";

    oledDisplay2(displayString, displayString2, grzalka, wiatrak);

  delay(1000);
}

void oledDisplay2(String text, String text2, String text3, String text4) {
  display.clear();
  display.draw_line(0,0,127,0);
  display.draw_line(0,0,0,63);
  display.draw_line(0,63,127,63);
  display.draw_line(127,0,127,64);
  display.setCursor(13,12);
  display.print(text);
  display.setCursor(13,22);
  display.print(text2);
  display.setCursor(13,32);
  display.print(text3);
  display.setCursor(13,42);
  display.print(text4);
  display.display();
}
Loading
ssd1306