#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
// Піни дисплея
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Пін і тип датчика температури
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// Інші сенсори
#define MQ2_PIN A0
#define PHOTO_PIN A1
// Змінні стану
bool normal = true;
bool smoke = false;
bool temp = false;
bool motion = false;
bool light = false;
void setup() {
Serial.begin(9600);
dht.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("Не знайдено дисплей SSD1306"));
for(;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Система завантажується...");
display.display();
delay(2000);
}
void loop() {
display.clearDisplay();
int y = 0;
float temperature = dht.readTemperature();
int smokeValue = analogRead(MQ2_PIN);
int lightValue = analogRead(PHOTO_PIN);
// Тут можна оновити логіку станів
// Наприклад:
normal = true;
if (smokeValue > 400) { smoke = true; normal = false; } else smoke = false;
if (!isnan(temperature) && temperature > 30) { temp = true; normal = false; } else temp = false;
if (lightValue < 300) { light = true; normal = false; } else light = false;
// motion поки не перевіряється (можна додати)
if (normal) {
display.setCursor(0, y);
display.println("Стан нормальний");
y += 10;
} else {
if (smoke) {
display.setCursor(0, y);
display.println("ДИМ! ТРИВОГА!");
y += 10;
}
if (temp) {
display.setCursor(0, y);
display.println("ВИСОКА ТЕМП!");
y += 10;
}
if (motion) {
display.setCursor(0, y);
display.println("РУХ! ТРИВОГА!");
y += 10;
}
if (light) {
display.setCursor(0, y);
display.println("ЗАТЕМНЕННЯ!");
y += 10;
}
}
if (!isnan(temperature)) {
display.setCursor(0, 40);
display.print("Темп: ");
display.print(temperature);
display.println(" C");
}
display.setCursor(0, 50);
display.print("Дим: ");
display.println(smokeValue);
display.setCursor(0, 60);
display.print("Світло: ");
display.println(lightValue);
display.display();
delay(1000);
}