#include <DHT.h>
#include <Adafruit_SSD1306.h> // Нормальная (надеюсь) библиотека для дисплея
#include <Fonts/Org_01.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define DHTPIN 3
DHT dht(DHTPIN, DHTTYPE);
// 'heart17x16_small', 17x16px
const unsigned char epd_bitmap_heart17x16_small [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
0x1c, 0x00, 0x3e, 0x3e, 0x00, 0x3f, 0xfe, 0x00, 0x1f, 0xfc, 0x00, 0x0f, 0xf8, 0x00, 0x07, 0xf0,
0x00, 0x03, 0xe0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'heart17x16_big', 17x16px
const unsigned char epd_bitmap_heart17x16_big [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x1e, 0x00, 0x7e, 0x3f, 0x00, 0xff,
0xff, 0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0x7f, 0xff, 0x00, 0x3f, 0xfe, 0x00, 0x1f, 0xfc,
0x00, 0x0f, 0xf8, 0x00, 0x07, 0xf0, 0x00, 0x03, 0xe0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x80, 0x00
};
const uint8_t img_therm[16] PROGMEM = {
0b00100000,
0b01110000,
0b01010000,
0b01011000,
0b01010000,
0b01011000,
0b01010000,
0b01011000,
0b01010000,
0b01011000,
0b01010000,
0b01011000,
0b01010000,
0b10001000,
0b10001000,
0b01110000,
};
void setup () {
display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // Инициализация дисплея (0x3C - его адресс)
display.display(); // неоходимо вызывать каждый раз для обновления дисплея
display.clearDisplay();
dht.begin();
display.setTextSize(1);
// display.setFont(&Org_01);
display.setTextColor(WHITE, BLACK);
}
void heartBeat() {
static uint64_t previousMillis;
static bool smallHeart = false;
if (millis() - previousMillis >= 300) {
previousMillis = millis();
smallHeart = !smallHeart;
}
if (smallHeart) {
display.drawBitmap(56, 40, epd_bitmap_heart17x16_small, 17, 16, SSD1306_WHITE);
}
else {
display.drawBitmap(56, 40, epd_bitmap_heart17x16_big, 17, 16, SSD1306_WHITE);
}
}
void loop () {
static uint64_t previousMillis;
float t = dht.readTemperature();
float h = dht.readHumidity();
if (millis() - previousMillis >= 2000) { // Самый простой и правильный с точки зрения
previousMillis = millis(); // работы МК таймер на 2 секунды
// Read temperature as Celsius (the default)
t = dht.readTemperature();
h = dht.readHumidity();
}
display.drawBitmap(5,2, img_therm, 5, 16, SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(17, 3);
display.print("Temperature: " + String(t));
display.setCursor(17, 12);
display.print("Humidity: " + String(h) + " %");
display.setFont(&Org_01);
display.setCursor(0,32);
display.print("Stay safe & drink water");
display.setFont();
heartBeat();
display.display();
display.clearDisplay();
}