writing to eeprom, oled disabled buffer works better

This commit is contained in:
Alexander Belov 2024-08-31 13:28:50 +07:00
parent dc659929dd
commit de4af97026

View File

@ -3,6 +3,7 @@
#include <PID_v1.h>
#include <GyverOLED.h>
#include "GyverEncoder.h" // Include the GyverEncoder library
#include <EEPROM.h>
// 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<SSD1306_128x64> oled;
// GyverOLED<SSD1306_128x64> oled;
GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> 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);
}