debugging and all good

This commit is contained in:
Alexander Belov 2024-08-31 01:38:49 +07:00
parent 1270e487fa
commit f23b6c3938
2 changed files with 91 additions and 34 deletions

7
README.md Normal file
View File

@ -0,0 +1,7 @@
## TODO
* check the ai suggestion
* time after completion is not displayed
* eeprom saving every 5 minutes and resuming
* profile selection

View File

@ -1,7 +1,8 @@
#include <max6675.h> #include <max6675.h>
#include <Wire.h> #include <Wire.h>
#include <PID_v1.h> #include <PID_v1.h>
#include <GyverOLED.h> // Include the GyverOLED library #include <GyverOLED.h>
#include "GyverEncoder.h" // Include the GyverEncoder library
// MAX6675 configuration // MAX6675 configuration
int max_SO = 12; int max_SO = 12;
@ -12,6 +13,12 @@ MAX6675 thermocouple(max_SCK, max_CS, max_SO);
// OLED configuration // OLED configuration
GyverOLED<SSD1306_128x64> oled; GyverOLED<SSD1306_128x64> oled;
// Encoder configuration
#define CLK 5
#define DT 6
#define SW 7
Encoder enc1(CLK, DT, SW, TYPE2);
// SSR pin configuration // SSR pin configuration
const int ssrPin = 7; const int ssrPin = 7;
@ -36,13 +43,15 @@ Profile profiles[] = {
{"Фитаза/Протеаза", 2, {{47, 120}, {53, 120}, {65, 150}, {72, 60}, {90, 105}, {50, 60}}, 6}, {"Фитаза/Протеаза", 2, {{47, 120}, {53, 120}, {65, 150}, {72, 60}, {90, 105}, {50, 60}}, 6},
}; };
// Select active profile (constant at this point) // Global variables for profile selection and execution
const int activeProfileIndex = 0; // Index of the active profile, starting from 0 int activeProfileIndex = 100; // 100 indicates no profile selected yet
Profile activeProfile = profiles[activeProfileIndex]; int selectedProfileIndex = 0; // Index of the currently selected profile in the selection mode
Profile activeProfile; // The active profile once selected
// Global variables for current phase, setpoint, and transition state // Global variables for current phase, setpoint, and transition state
int currentPhase; int currentPhase;
bool isInTransition = false; bool isInTransition = false;
bool inSelectionMode = true;
// PID Control variables // PID Control variables
double Setpoint, Input, Output; double Setpoint, Input, Output;
@ -67,22 +76,15 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
oled.init(); // Initialize the OLED oled.init(); // Initialize the OLED
oled.clear(); // Clear the display oled.clear(); // Clear the display
oled.setScale(2); // Set text scale to 2 for better visibility displaySelection();
oled.print("Starting...");
oled.update();
oled.setScale(1); // Set text scale back to 1 for more detailed information
calculateTotalTime();
// Begin the first phase
phaseStartTime = totalStartTime = millis();
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(0, 1); // SSR is either ON or OFF
digitalWrite(ssrPin, HIGH); // Start with heater on
ssrLastSwitchTime = millis();
} }
void loop() { void loop() {
enc1.tick(); // Mandatory encoder update function
if (inSelectionMode) {
handleProfileSelection(); // Handle profile selection mode
} else {
unsigned long currentTime = millis(); unsigned long currentTime = millis();
totalElapsedTime = (currentTime - totalStartTime) / 1000; // Total elapsed time in seconds totalElapsedTime = (currentTime - totalStartTime) / 1000; // Total elapsed time in seconds
@ -108,6 +110,54 @@ void loop() {
delay(1000); // Update every second delay(1000); // Update every second
} }
}
void handleProfileSelection() {
bool click = enc1.isClick();
bool turn = enc1.isTurn();
if (!click && !turn) {
return;
}
// Handle encoder input for selecting the profile
if (enc1.isRight()) {
selectedProfileIndex = (selectedProfileIndex + 1) % (sizeof(profiles) / sizeof(profiles[0]));
} else if (enc1.isLeft()) {
selectedProfileIndex = (selectedProfileIndex - 1 + (sizeof(profiles) / sizeof(profiles[0]))) % (sizeof(profiles) / sizeof(profiles[0]));
}
displaySelection();
// Start the selected profile on button press
if (click) {
activeProfileIndex = selectedProfileIndex;
activeProfile = profiles[activeProfileIndex];
calculateTotalTime();
inSelectionMode = false; // Switch to execution mode
phaseStartTime = totalStartTime = millis(); // Start the timer
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(0, 1); // SSR is either ON or OFF
digitalWrite(ssrPin, HIGH); // Start with heater on
ssrLastSwitchTime = millis();
}
}
void displaySelection() {
oled.clear();
// Display all profiles with the selected one highlighted
for (int i = 0; i < (int) (sizeof(profiles) / sizeof(profiles[0])); i++) {
if (i == selectedProfileIndex) {
oled.invertText(true); // Highlight the selected profile
}
oled.setCursor(0, i); // Set cursor to the correct row
oled.print(profiles[i].name);
oled.invertText(false); // Reset text inversion for other profiles
}
oled.update();
}
void calculateTotalTime() { void calculateTotalTime() {
// Calculate total process time, including transitions // Calculate total process time, including transitions
@ -136,9 +186,9 @@ void getPhaseAndTemperature(unsigned long elapsedSeconds) {
if (elapsedSeconds < accumulatedTime + transitionDuration) { if (elapsedSeconds < accumulatedTime + transitionDuration) {
isInTransition = true; isInTransition = true;
currentPhase = i; currentPhase = i - 1; // Keep currentPhase as the previous phase
int timeInTransition = elapsedSeconds - accumulatedTime; int timeInTransition = elapsedSeconds - accumulatedTime;
Setpoint = previousTemp + ((targetTemp > previousTemp ? (double)timeInTransition / 60 : -(double)timeInTransition / 60) / (double)activeProfile.transitionMinutesPerDegree); Setpoint = previousTemp + (double)timeInTransition / (60 * activeProfile.transitionMinutesPerDegree) * (targetTemp > previousTemp ? 1 : -1);
return; return;
} }