diff --git a/hot_fermentation.ino b/hot_fermentation.ino index f0c93b9..7ffdab0 100644 --- a/hot_fermentation.ino +++ b/hot_fermentation.ino @@ -3,6 +3,7 @@ #include #include #include "GyverEncoder.h" // Include the GyverEncoder library +#include // MAX6675 configuration int max_SO = 12; @@ -11,7 +12,8 @@ int max_SCK = 13; MAX6675 thermocouple(max_SCK, max_CS, max_SO); // OLED configuration -GyverOLED oled; +// GyverOLED oled; +GyverOLED oled; // Encoder configuration #define CLK 5 @@ -66,6 +68,7 @@ long totalElapsedTime; long totalProcessTime; long finishTime = 0; long currentTime = 0; +long lastEEPROMWriteTime = 0; bool isComplete = false; const int ssrSwitchInterval = 1000; // SSR switching interval in milliseconds @@ -94,6 +97,10 @@ void handleExecution() { currentTime = millis(); totalElapsedTime = (currentTime - totalStartTime) / 1000; // Total elapsed time in seconds + if ((currentTime - lastEEPROMWriteTime) >= (unsigned int) 10*60*1000) { + writeEEPROM(); + } + getPhaseAndTemperature(); Input = thermocouple.readCelsius(); @@ -144,10 +151,12 @@ void handleProfileSelection() { calculateTotalTime(); inSelectionMode = false; // Switch to execution mode phaseStartTime = totalStartTime = millis(); // Start the timer + totalElapsedTime = 0; myPID.SetMode(AUTOMATIC); myPID.SetOutputLimits(0, 1); // SSR is either ON or OFF - digitalWrite(ssrPin, HIGH); // Start with heater on + // digitalWrite(ssrPin, HIGH); // Start with heater on ssrLastSwitchTime = millis(); + writeEEPROM(); } } @@ -238,7 +247,10 @@ void printPhases() { formatTime((currentTime - finishTime) / 1000, timeBuffer); // Time since completion oled.print(timeBuffer); oled.print(" "); - oled.print((int)Input); + oled.print(Input,1); + oled.print("c"); + oled.print("->"); + oled.print((int)Setpoint); oled.print("c"); } else { oled.setCursor(0, 0); @@ -305,3 +317,13 @@ void formatTime(long seconds, char* buffer) { sprintf(buffer + strlen(buffer), "%ds", secs); } } + +void writeEEPROM() { + lastEEPROMWriteTime = millis(); + EEPROM.put(0, activeProfileIndex); // Store the active profile index + EEPROM.put(4, totalElapsedTime); // Store the total elapsed time + Serial.print("EEPROM written: "); + Serial.print(activeProfileIndex); + Serial.print(" "); + Serial.println(totalElapsedTime); +} \ No newline at end of file