This commit is contained in:
Alexander Belov 2024-09-06 11:27:26 +07:00
parent 673fbc03d8
commit 8f9584a818

View File

@ -3,7 +3,6 @@
#define TempSensorDallas
#include <Wire.h>
#include <PID_v1.h>
#include <GyverOLED.h>
#include "GyverEncoder.h"
@ -80,9 +79,12 @@ bool isInTransition = false;
bool inSelectionMode = true;
// PID Control variables
// double Kp = 0.5, Ki = 1, Kd = 0.05;
// PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
#include "GyverPID.h"
double Setpoint, Input, Output;
double Kp = 0.5, Ki = 1, Kd = 0.05;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
GyverPID regulator(1, 0.5, 0, 1000);
// Timing variables
long phaseStartTime;
@ -118,9 +120,9 @@ void setup() {
oled.init(); // Initialize the OLED
oled.clear(); // Clear the display
readEEPROM();
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(0, 100);
// myPID.SetSampleTime(1000);
regulator.setDirection(NORMAL); // направление регулирования (NORMAL/REVERSE). ПО УМОЛЧАНИЮ СТОИТ NORMAL
regulator.setLimits(0, 100); // пределы (ставим для 8 битного ШИМ). ПО УМОЛЧАНИЮ СТОЯТ 0 И 255
regulator.setpoint = 0;
#ifdef TempSensorDallas
sensors.begin();
@ -296,7 +298,10 @@ void handleExecution() {
if (isnan(Input)) {
Input = 0;
}
myPID.Compute();
regulator.input = (float)Input;
regulator.setpoint = Setpoint;
regulator.getResult();
Output = regulator.output;
if (isComplete && currentPhase >= activeProfile.numPhases && !finishTime) {
finishTime = currentTime;
@ -311,8 +316,7 @@ void startExecution() {
inSelectionMode = false; // Switch to execution mode
phaseStartTime = totalStartTime = millis(); // Start the timer
totalElapsedTime = 0;
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(0, 100); // SSR is either ON or OFF
regulator.setpoint = 0;
// digitalWrite(ssrPin, HIGH); // Start with heater on
ssrLastSwitchTime = millis();
calculateTotalTime();