#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <DHTesp.h>
// OLED 設定
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// DHT22 設定
#define DHTPIN 4 // DHT22 數據腳位,連接到 GPIO4
DHTesp dht;
// LOGO 位圖資料
const unsigned char logoo[] PROGMEM = {
0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xe0,
0x3f, 0xff, 0x80, 0x07, 0xff, 0xff, 0xc0, 0x1f, 0xff, 0x00, 0x01, 0xff, 0xff, 0x80, 0x0f, 0xfe,
0x00, 0x00, 0xff, 0xff, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x03, 0xf8, 0x00, 0x00,
0x7f, 0xfc, 0x00, 0x01, 0xf0, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0xff, 0xf0,
0x00, 0x3f, 0xe0, 0x00, 0x01, 0xff, 0xe0, 0x00, 0x7f, 0xe0, 0x00, 0x03, 0xff, 0xc0, 0x01, 0xff,
0xf0, 0x00, 0x03, 0xff, 0x80, 0x01, 0xff, 0xf0, 0x00, 0x07, 0xff, 0x80, 0x03, 0xff, 0xf8, 0x00,
0x0f, 0xff, 0x80, 0x07, 0xff, 0xf8, 0x00, 0x0f, 0xff, 0x00, 0x0f, 0xff, 0xfc, 0x00, 0x1f, 0xff,
0x00, 0x0f, 0xff, 0xfc, 0x00, 0x3f, 0xff, 0x00, 0x1f, 0xff, 0x06, 0x00, 0x3f, 0xff, 0x00, 0x3f,
0xfe, 0x02, 0x00, 0x7f, 0xfd, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x7f, 0xf9, 0x00, 0x7f, 0xf8, 0x00,
0x00, 0xff, 0xf9, 0x00, 0xff, 0xf8, 0x00, 0x01, 0xff, 0xf1, 0x00, 0xff, 0xf0, 0x00, 0x01, 0xff,
0xf1, 0x01, 0xff, 0xe0, 0x00, 0x03, 0xff, 0xe1, 0x03, 0xff, 0xe0, 0x00, 0x07, 0xff, 0xc0, 0x03,
0xff, 0xc0, 0x00, 0x07, 0xff, 0xc0, 0x07, 0xff, 0xc0, 0x00, 0x0f, 0xff, 0x80, 0x0f, 0xff, 0x80,
0x00, 0x0f, 0xff, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x1f, 0xff, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x3f,
0xfe, 0x00, 0x3f, 0xfe, 0x00, 0x00, 0x3f, 0xfc, 0x01, 0x3f, 0xfc, 0x00, 0x00, 0x7f, 0xfc, 0x01,
0x7f, 0xfc, 0x00, 0x00, 0xff, 0xf8, 0x01, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf0, 0x01, 0xff, 0xf8,
0x00, 0x01, 0xff, 0xf0, 0x01, 0xff, 0xf0, 0x02, 0x03, 0xff, 0xe0, 0x01, 0xff, 0xe0, 0x01, 0x87,
0xff, 0xc0, 0x01, 0xff, 0xe0, 0x01, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xc0, 0x01, 0xff, 0xff, 0x80,
0x03, 0xff, 0x80, 0x00, 0xff, 0xff, 0x00, 0x03, 0xff, 0x80, 0x00, 0xff, 0xfe, 0x00, 0x07, 0xff,
0x00, 0x00, 0x7f, 0xfe, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x0f, 0xfe, 0x00, 0x00,
0x3f, 0xf8, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0xf7, 0x80,
0x00, 0x1f, 0xfe, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x7f,
0xff, 0x80, 0x0f, 0xfc, 0x00, 0x00, 0x7f, 0xff, 0xc0, 0x1f, 0xfe, 0x00, 0x00, 0xff, 0xff, 0xe0,
0x3f, 0xff, 0x00, 0x03, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xc0, 0x07, 0xff, 0xff, 0xf8, 0xff, 0xff,
0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
void setup() {
Serial.begin(115200);
dht.setup(DHTPIN, DHTesp::DHT22);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 initialization failed!"));
for (;;);
}
display.clearDisplay();
display.display();
}
void loop() {
TempAndHumidity data = dht.getTempAndHumidity();
display.clearDisplay();
// 顯示 LOGO
display.drawBitmap(32, 8, logoo, 64, 48, SSD1306_WHITE);
// 顯示溫濕度數據
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Temp: ");
display.print(data.temperature);
display.println("C");
display.setCursor(0, 10);
display.print("Humidity: ");
display.print(data.humidity);
display.println("%");
display.setTextSize(1);
display.setCursor(0, 48); // Adjust the y-coordinate as needed
display.print("吳凱崴");
display.setCursor(0, 56); // Adjust the y-coordinate as needed
display.print("4B2G0037");
display.display();
delay(2000);
}