// #include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_SHT31.h>
#define DHT_PIN 21
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
DHTesp dhtSensor;
Adafruit_SHT31 sht31 = Adafruit_SHT31();
// 'led_off', 50x50px
const unsigned char led_off [] PROGMEM = {
0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x07,
0xf8, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x7e, 0x00,
0x00, 0x00, 0x1f, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
0x3c, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x78, 0x00,
0x00, 0x07, 0x80, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03,
0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0xc0, 0x00,
0x00, 0xf0, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xf0,
0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00,
0x03, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x03, 0xc0,
0x00, 0x00, 0xf0, 0x3f, 0xff, 0x03, 0xc0, 0x00, 0x00, 0xf0, 0x7f, 0xff, 0x83, 0xc0, 0x00, 0x00,
0xf0, 0x7f, 0xff, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x7f, 0xff, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78,
0x07, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07, 0x83,
0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07, 0x83, 0xc0, 0x00,
0x00, 0xf0, 0x78, 0x07, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07, 0x83, 0xc0, 0x00, 0x00, 0xf0,
0x78, 0x07, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07, 0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07,
0x83, 0xc0, 0x00, 0x00, 0xf0, 0x78, 0x07, 0x83, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc0,
0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x7c, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x78,
0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x78, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x78, 0x07, 0x80,
0x00, 0x00, 0x00, 0x00, 0x78, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x78, 0x07, 0x80, 0x00, 0x00,
0x00, 0x00, 0x78, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x07, 0x00, 0x00, 0x00
};
// 'led_on', 50x50px
const unsigned char led_on [] PROGMEM = {
0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x01,
0xf0, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x70, 0x00,
0x00, 0x03, 0x80, 0x00, 0x00, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x80, 0x00, 0x00,
0x00, 0x00, 0xf8, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x03,
0xc0, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x70, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00,
0x78, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x38, 0x00,
0x00, 0x00, 0x07, 0x00, 0x00, 0x38, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x00, 0x38, 0x07, 0xc0, 0xfc,
0x0f, 0x00, 0x00, 0x3c, 0x07, 0xc0, 0xfc, 0x0f, 0x00, 0x00, 0x3c, 0x07, 0xc0, 0x00, 0x0f, 0x00,
0x00, 0x3c, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x3c,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x3c, 0x00, 0x00,
0x00, 0x0f, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x3f,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x3f, 0xff, 0xff,
0xff, 0x00, 0x00, 0x00, 0x1d, 0xff, 0xff, 0xee, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00,
0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00,
0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe0,
0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00,
0x00, 0x00, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
if (!sht31.begin(0x44)) {
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
}
// int count1 = 1;
// int count2 = 2;
// int count3 = 0;
void loop() {
float t = sht31.readTemperature();
if( t < 28){
display.drawBitmap(40, 5, led_on, 128, 64, 1); //หน้าหนาว
ShowTemp();
display.display();
delay(2000); // Pause for 2 seconds
display.clearDisplay();
} else {
display.drawBitmap(40, 5,led_on, 128, 64, 1);
ShowTemp();
display.display();
delay(1000); // Pause for 1 second
display.clearDisplay();
}
}
void ShowTemp() {
float temperature = sht31.readTemperature();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(45, 0);
display.print(temperature);
display.println("C");
}