#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "esp_sleep.h"
#define DHTPIN 15
#define DHTTYPE DHT22
#define BUTTON_PIN 4
bool lastButtonState = HIGH;
bool sundayTriggered = false;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 columns, 2 rows
void setup() {
Serial.begin(115200);
dht.begin();
lcd.init();
lcd.backlight();
pinMode(BUTTON_PIN, INPUT_PULLUP);
lcd.setCursor(0, 0);
lcd.print("System Booting...");
delay(2000);
lcd.clear();
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
Serial.print("Wakeup reason: ");
Serial.println(wakeup_reason);
}
void loop() {
bool currentButtonState = digitalRead(BUTTON_PIN);
// Detect falling edge (HIGH to LOW)
if (lastButtonState == HIGH && currentButtonState == LOW && !sundayTriggered) {
sundayTriggered = true; // prevent retriggering
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("😴 Sunday Mode");
lcd.setCursor(0, 1);
lcd.print("Sleeping 24 hrs");
Serial.println("😴 Sunday detected. Going to deep sleep for 24 hours...");
delay(1000); // allow LCD to update
esp_sleep_enable_timer_wakeup(86400000000ULL); // 24 hours
esp_deep_sleep_start();
}
lastButtonState = currentButtonState;
// Skip the rest if Sunday mode was triggered
if (sundayTriggered) return;
float temp = dht.readTemperature();
if (isnan(temp)) {
Serial.println("Failed to read from DHT sensor!");
lcd.setCursor(0, 0);
lcd.print("Sensor Error ");
delay(2000);
return;
}
Serial.print("🌡️ Temperature: ");
Serial.print(temp);
Serial.println(" °C");
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C ");
if (temp > 35.0) {
burnoutRecoveryLoop();
}
delay(5000);
}
void burnoutRecoveryLoop() {
Serial.println("🔥 Engineer Burnout Detected! Entering Recovery Mode...");
lcd.setCursor(0, 1);
lcd.print("Burnout Mode... ");
for (int i = 0; i < 3; i++) {
Serial.println("[Core Dump] Recovering from burnout.");
fixBugs();
breakThings();
fixAgain();
delay(10);
}
lcd.setCursor(0, 1);
lcd.print("Recovery Done ");
Serial.println("✅ Recovery complete. Resuming normal operation.");
}
void fixBugs() {
Serial.println("🔧 Fixing bugs...");
}
void breakThings() {
Serial.println("💥 Oops! Something broke.");
}
void fixAgain() {
Serial.println("🔁 Fixing again...");
}