#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHTesp.h"
#include "RTClib.h"
const int DHT_PIN = 16;
RTC_DS1307 rtc;
DHTesp dhtSensor;
#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 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 50
#define LOGO_WIDTH 50
static const unsigned char love1_bmp[] =
{ // 'love', 50x50px
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff,
0xff, 0x8f, 0xff, 0x0f, 0xff, 0xc0, 0xff, 0xfc, 0x01, 0xf8, 0x03, 0xff, 0xc0, 0xff, 0xf8, 0x00,
0xf0, 0x00, 0xff, 0xc0, 0xff, 0xe0, 0x00, 0x60, 0x00, 0x7f, 0xc0, 0xff, 0xe0, 0x00, 0x00, 0x00,
0x7f, 0xc0, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x3f, 0xc0,
0xff, 0xc0, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0xff, 0x80, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0xff, 0x80,
0x00, 0x00, 0x00, 0x1f, 0xc0, 0xff, 0x80, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0xff, 0x80, 0x00, 0x00,
0x00, 0x1f, 0xc0, 0xff, 0x80, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0xff, 0x80, 0x00, 0x00, 0x00, 0x1f,
0xc0, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0xff,
0xc0, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0xff, 0xe0, 0x00,
0x00, 0x00, 0x7f, 0xc0, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0xff, 0xf0, 0x00, 0x00, 0x00,
0xff, 0xc0, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0xff, 0xf8, 0x00, 0x00, 0x01, 0xff, 0xc0,
0xff, 0xfc, 0x00, 0x00, 0x03, 0xff, 0xc0, 0xff, 0xfe, 0x00, 0x00, 0x03, 0xff, 0xc0, 0xff, 0xfe,
0x00, 0x00, 0x07, 0xff, 0xc0, 0xff, 0xff, 0x00, 0x00, 0x0f, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00,
0x1f, 0xff, 0xc0, 0xff, 0xff, 0xe0, 0x00, 0x3f, 0xff, 0xc0, 0xff, 0xff, 0xf0, 0x00, 0xff, 0xff,
0xc0, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xfe, 0x07, 0xff, 0xff, 0xc0, 0xff,
0xff, 0xff, 0x0f, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0 };
static const unsigned char light_bmp[] =
{ // 'light', 50x50px
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff,
0xc0, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0xc0, 0xff,
0xfc, 0x00, 0x3f, 0xff, 0xff, 0xc0, 0xff, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xc0, 0xff, 0xc0, 0x00,
0x1f, 0xff, 0xff, 0xc0, 0xff, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xc0, 0xfe, 0x00, 0x00, 0x0f, 0xff,
0xff, 0xc0, 0xfc, 0x00, 0x00, 0x07, 0xff, 0xff, 0xc0, 0xfc, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0,
0xfe, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xc0,
0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xe0, 0x00, 0x03, 0xff, 0xff, 0xc0, 0xff, 0xf8, 0x00, 0x01,
0xff, 0xff, 0xc0, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xff, 0xc0, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xff,
0xc0, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xc0, 0xff, 0xfc, 0x00, 0x00, 0x1f, 0xff, 0xc0, 0xff,
0xfe, 0x00, 0x00, 0x0f, 0xff, 0xc0, 0xff, 0xff, 0x00, 0x00, 0x07, 0xff, 0xc0, 0xff, 0xff, 0xc0,
0x00, 0x07, 0xff, 0xc0, 0xff, 0xff, 0xf0, 0x00, 0x0f, 0xff, 0xc0, 0xff, 0xff, 0xf8, 0x00, 0x0f,
0xff, 0xc0, 0xff, 0xff, 0xfe, 0x00, 0x0f, 0xff, 0xc0, 0xff, 0xff, 0xfc, 0x00, 0x07, 0xff, 0xc0,
0xff, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xc0, 0xff, 0xff, 0xfe, 0x00, 0x01, 0xff, 0xc0, 0xff, 0xff,
0xff, 0x00, 0x01, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xe0,
0x00, 0x7f, 0xc0, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xc0, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x1f,
0xc0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1f, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0xc0, 0xff,
0xff, 0xff, 0xff, 0xf0, 0x07, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x07, 0xc0, 0xff, 0xff, 0xff,
0xff, 0xfe, 0x07, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0 };
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup() {
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
//display.display();
//delay(2000); // Pause for 2 seconds
// Clear the buffer
// display.clearDisplay();
}
void loop() {
// TempAndHumidity data = dhtSensor.getTempAndHumidity();
// DateTime now = rtc.now();
// Serial.println("Temp:" + String(data.temperature, 2) + "°C");
// Serial.println("Humidity:" + String(data.humidity, 1) + "%");
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(1);
display.setCursor(0, 0);
TempAndHum();
time();
display.display();
// display.drawBitmap(80, 10, love1_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
// display.display();
// delay(100);
// display.drawBitmap(80, 10, light_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
// display.display();
// delay(100);
}
void TempAndHum()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
display.println("Temp:" + String(data.temperature, 2) + "C");
display.println("Humidity:" + String(data.humidity, 1) + "%");
delay(500);
}
void time()
{
DateTime now = rtc.now();
display.print("Current time:");
display.println(String(now.year(), DEC) + "/" + String(now.month(), DEC) + "/" + String(now.day(), DEC));
display.println(daysOfTheWeek[now.dayOfTheWeek()]);
display.println(String(now.hour(), DEC) + ":" + String(now.minute(), DEC) + ":" + String(now.second(), DEC));
delay(500);
}