Arduino uno pid isn't working properly

Hello! I want to make an apparatus that uses a dfrobot lcd keypad shield (6 buttons:up, down, left, right, select, reset) , a 4 module relay, a Peltier device and and arduino uno to maintain a certain temperature. I want the user to be able to set the temperature and then press select and the PID control to activate the relay modules so that the temperature reaches the set values and keeps it steady until the select button is pressed again.
It only works while the button is pressed.

#include <DHT.h>
#include <DHT_U.h>
#include <PID_v1.h>
#include <LiquidCrystal.h>
#include <max6675.h>


byte on_i[] = {
  B11111,
  B11111,
  B11011,
  B10001,
  B01010,
  B01010,
  B01110,
  B10001
};

byte on[] = {
  B00000,
  B00000,
  B00100,
  B01110,
  B10101,
  B10101,
  B10001,
  B01110
};
byte celsius[] = {
  B11000,
  B11000,
  B00010,
  B00101,
  B01000,
  B01000,
  B00101,
  B00010
};
byte separator[] = {
  B01110,
  B01010,
  B01110,
  B01010,
  B01110,
  B01010,
  B01110,
  B01010
};



 int a; //used for moving the cursor left or right. 
 float temp;
 byte nr[4];  // This will hold 4 bytes, and if global, will init to all zeros
 byte i;  //This will hold an index to the array. If global, it will init to 0
 int enteredValue;  // this will hold the final value entered
 double  Setpoint, Input, Output;
 int WindowSize = 5000;
 unsigned long windowStartTime;
  

MAX6675 thermocouple(A4, 3, 2);//thermoCLK, thermoCS, thermoDO
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // (rs,enable,d4,d5,d6,d7)
PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, DIRECT);//Kp, Ki, Kd
//DHT dht(3, DHT11); //DHTPIN, DHTTYPE


void heat(){
  stopRelay();
  digitalWrite(A1,LOW);  //turn on heat relay
  digitalWrite(A3,LOW);  // turn on power relay
}

void cool(){
  stopRelay();
  digitalWrite(A2,LOW);  //turn on cool relay
  digitalWrite(A3,LOW);  // turn on power relay
}

void stopRelay(){         //shuts down all relays
  digitalWrite(A1,HIGH); 
  digitalWrite(A2,HIGH);
  digitalWrite(A3,HIGH);
}

void pidSetup(){
  windowStartTime = millis();
  //initialize the variables we're linked to
  Setpoint = temp;
  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);
  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}

void lcdSetup(){
  lcd.begin(16, 2);
  lcd.clear();
  lcd.createChar(1,on);
  lcd.createChar(2,celsius);
  lcd.createChar(3,separator);
  lcd.createChar(4,on_i);
  lcd.setCursor(0,0);
  lcd.print("Welcome!");
  delay(2000);
  lcd.clear();
  lcd.print("Set Temp");
  lcd.write(3);
  lcd.print("Actual\n");
  lcd.setCursor(0,1);
  lcd.print("00.00");
  lcd.write(2);
  lcd.setCursor(8,1);
  lcd.write(1);

}


void setup() {
  Serial.begin(9600);
  pidSetup();
//  dht.begin();
  lcdSetup();
  pinMode(A1,OUTPUT);
  pinMode(A2,OUTPUT);
  pinMode(A3,OUTPUT);
  pinMode(A4,OUTPUT);
  pinMode(A5,INPUT);
  delay(500);    // wait for MAX chip to stabilize
}

void loop() {
 
  Input = thermocouple.readCelsius;
  lcd.setCursor(10,1);
  lcd.print(Input);
  
  int x;
  
  int ok=0;  
   stopRelay();
  x = analogRead (0);
  lcd.setCursor(a,1);

  if (x < 50) {
   //right button
   if (i < 3 ) { 
     i++;
     a++;
     if(a==2)a++;
   }
      
  }
  else if (x < 150) {
  //up button
   if (nr[i] < 9 ) {
     nr[i]++;
    lcd.print(nr[i]);
   }

    
  }
  else if (x < 300){
  //down button
    if (nr[i] > 0 ) {
    nr[i]--;
    lcd.print(nr[i]);
    }

  }
   else if (x < 450){
   //left button
     if (i > 0) {
     i--;
     a--;
      if(a==2)a--;
     }

     
  }
  else if (x < 800){ 
    ok=ok+1;
    temp = nr[0]*10+nr[1]+nr[2]/10+nr[3]/100;     //save temp value 
    Setpoint = temp;
    myPID.Compute();
   // Serial.print(Setpoint);
  }
  if(ok%2!=0){ 
    //set "power on" icon
        lcd.setCursor(8,1);
        lcd.write(4);
        lcd.setCursor(a,1);
         
    if (millis() - windowStartTime > WindowSize)
  { //time to shift the Relay Window
    windowStartTime += WindowSize;
  }
      //start PID procedure
  if (Output < millis() - windowStartTime) heat();
  else  cool();
  }
   
      else{         //pressing "select" button again closes the loop and 
                    //allows user to change the temperature
      
    //set "power off" icon
        lcd.setCursor(8,1);
        lcd.write(1);
        lcd.setCursor(a,1);
      }
    
  

 delay(200);
}

That's because you asked it to behave like that.

The PID has to run all the time, not only when the setpoint changes.

so i should put it in the void setup() function?
Won't that cause it to to activate the relays continuously?

setup() runs only once, doesn't help to keep the PID running.

Which PID library are you using? Doesn't it come with examples?

That generates an error and won't compile.

This will at least compile. You will run into a problem when your output is very near your setpoint since you have heating and cooling. They will toggle back and forth quite a bit. The original example of the PID relay was more for a sketch that only had a heater. It turns on for a while and then turns off. You may need to add some hysteresis, but get this working first.

also note, you need to use floating point numbers when you convert your digits to a new setpoint or else you get integer math so nr[2] /10 and nr[3] / 100 will always be 0.

#include <DHT.h>
#include <DHT_U.h>
#include <PID_v1.h>
#include <LiquidCrystal.h>
#include <max6675.h>


byte on_i[] = {
  B11111,
  B11111,
  B11011,
  B10001,
  B01010,
  B01010,
  B01110,
  B10001
};

byte on[] = {
  B00000,
  B00000,
  B00100,
  B01110,
  B10101,
  B10101,
  B10001,
  B01110
};
byte celsius[] = {
  B11000,
  B11000,
  B00010,
  B00101,
  B01000,
  B01000,
  B00101,
  B00010
};
byte separator[] = {
  B01110,
  B01010,
  B01110,
  B01010,
  B01110,
  B01010,
  B01110,
  B01010
};



int a; //used for moving the cursor left or right.
int cursorIdx;

float temp;
byte nr[4];  // This will hold 4 bytes, and if global, will init to all zeros
//byte i;  //This will hold an index to the array. If global, it will init to 0
byte nrIndex;

bool isRunning = false;

double  Setpoint, Input, Output;
const int WindowSize = 5000;
unsigned long windowStartTime;


MAX6675 thermocouple(A4, 3, 2);//thermoCLK, thermoCS, thermoDO
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // (rs,enable,d4,d5,d6,d7)
PID myPID(&Input, &Output, &Setpoint, 2, 5, 1, DIRECT);//Kp, Ki, Kd
//DHT dht(3, DHT11); //DHTPIN, DHTTYPE


void heat() {
  digitalWrite(A1, LOW); //turn on heat relay
  digitalWrite(A2, HIGH); //turn off cool relay
  digitalWrite(A3, LOW); // turn on power relay
}

void cool() {
  digitalWrite(A1, HIGH); //turn off heat relay
  digitalWrite(A2, LOW); //turn on cool relay
  digitalWrite(A3, LOW); // turn on power relay
}

void stopRelay() {        //shuts down all relays
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  digitalWrite(A3, HIGH);
}

void pidSetup() {
  windowStartTime = millis();
  //initialize the variables we're linked to
  Setpoint = temp;
  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);
  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}

void lcdSetup() {
  lcd.begin(16, 2);
  lcd.clear();
  lcd.createChar(1, on);
  lcd.createChar(2, celsius);
  lcd.createChar(3, separator);
  lcd.createChar(4, on_i);
  lcd.setCursor(0, 0);
  lcd.print("Welcome!");
  delay(2000);
  lcd.clear();
  lcd.print("Set Temp");
  lcd.write(3);
  lcd.print("Actual\n");
  lcd.setCursor(0, 1);
  lcd.print("00.00");
  lcd.write(2);
  lcd.setCursor(8, 1);
  lcd.write(1);

}


void setup() {
  Serial.begin(9600);
  pidSetup();
  //  dht.begin();
  lcdSetup();
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, INPUT);
  stopRelay();
  delay(500);    // wait for MAX chip to stabilize
}

void loop() {

  Input = thermocouple.readCelsius();
  lcd.setCursor(10, 1);
  lcd.print(Input);

  myPID.Compute();
  if (millis() - windowStartTime > WindowSize) {
    //time to shift the Relay Window
    windowStartTime += WindowSize;
  }

  if ( isRunning == true ) {
    //start PID procedure
    if (Output < millis() - windowStartTime) {
      heat();
    }
    else {
      cool();
    }
  }

  int buttonState = analogRead(A0);
  lcd.setCursor(cursorIdx, 1);

  if (buttonState < 50) {
    //right button, advance to next digit
    if (nrIndex < 3 ) {
      nrIndex++;
      cursorIdx++;
      if (cursorIdx == 2) cursorIdx++;
    }
  }
  else if (buttonState < 150) {
    //up button, increment digit if below 9
    if (nr[nrIndex] < 9 ) {
      nr[nrIndex]++;
      lcd.print(nr[nrIndex]);
    }
  }
  else if (buttonState < 300) {
    //down button, decrement digit if above 0
    if (nr[nrIndex] > 0 ) {
      nr[nrIndex]--;
      lcd.print(nr[nrIndex]);
    }
  }
  else if (buttonState < 450) {
    //left button, move to previous digit
    if (nrIndex > 0) {
      nrIndex--;
      cursorIdx--;
      if (cursorIdx == 2) cursorIdx--;
    }
  }
  else if (buttonState < 800) {
    // select button, compute new setpoint
    temp = nr[0] * 10.0 + nr[1] + nr[2] / 10.0 + nr[3] / 100.0; //save temp value
    Setpoint = temp;
    // Serial.print(Setpoint);
    isRunning = !isRunning;   // toggle running status
    lcd.setCursor(8, 1);
    if (isRunning == true) {
      //set "power on" icon
      lcd.write(4);
    }
    else {
      //set "power off" icon
      lcd.write(1);
    }
  }
  delay(200);
}

What if I would only use the heating function?
Would that make the code better?

It would make it look just like the example code from the PID library