#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <DHT.h>
#include <RTClib.h>
#define DHTPIN 7 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302) sensor type
DHT dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 lcd(128, 64, &Wire, 4);
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200);
lcd.begin(SSD1306_SWITCHCAPVCC, 0x3C);
rtc.begin();
dht.begin();
}
void loop() {
displayHomeScreen();
delay(1000); // Update screen every second
}
void displayHomeScreen() {
lcd.clearDisplay();
lcd.setTextSize(1);
lcd.setTextColor(WHITE);
// Display current time at the top center
DateTime now = rtc.now();
int hour = now.hour();
int minute = now.minute();
String period = (hour < 12) ? "AM" : "PM";
if (hour > 12) hour -= 12;
lcd.setCursor(42, 0);
if (hour < 10) lcd.print("0");
lcd.print(hour);
lcd.print(':');
if (minute < 10) lcd.print("0");
lcd.print(minute);
lcd.print(" ");
lcd.print(period);
// Draw temperature circle
lcd.fillCircle(23, 21, 19, WHITE);
lcd.setTextColor(BLACK); // Set text color to black
lcd.setCursor(9, 17);
lcd.print(dht.readTemperature(), 1); // Display temperature with one decimal point
lcd.print("c");
// Draw humidity circle
lcd.fillCircle(107, 21, 19, WHITE);
lcd.setTextColor(BLACK); // Set text color to black
lcd.setCursor(95, 17);
lcd.print(dht.readHumidity(), 1); // Display humidity with one decimal point
lcd.print("%");
// Draw "Cure Time"
lcd.setTextColor(WHITE); // Set text color to white
lcd.setTextSize(1);
lcd.setCursor(42, 40);
lcd.print("Cure Time");
lcd.display();
}