function clash and return?

I’m wanting to make a brew fridge temp controller for a friend. I think the code is pretty self explanatory. sorry for the lack of commenting.
Question (A) Is the “blue” comparators going to clash with the “green” ? I feel like they will but I’m not sure how to organize the code to make it not clash…
Question (B) I’ve never use a return before and I think it’s write as per the “how to” section via the Arduino website.
I have not built anything for this project yet. It’s all on paper still. I would appreciate suggestions if y’all are bored. Thanks.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int SensorPin = A0;
int SetPin = A1;

int sensorVal;
int setVal;

int sensorTemp;
int setTemp;

int tempDiffPos;
int tempDiffNeg;
int count;

int LED_B = 9;    // PWM capable
int LED_G = 10;   // PWM capable
int LED_R = 11;   // PWM capable
int relayPin = 3; // PWM capable
const byte relaySensor = 4;
const byte button = 2;

void setup() {

  pinMode(LED_B, OUTPUT);
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(SetPin, INPUT);
  pinMode(SensorPin, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(relaySensor, INPUT);
  pinMode(button, INPUT);
  count = 0;
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print(" !  Mmmmmmmm  ! ");
  lcd.setCursor(0, 1);
  lcd.print("  KOEL'D  BEER  ");
  delay(2000);
  lcd.clear();
}

void loop() {
  // put your main code here, to run repeatedly:
  sensorVal = analogRead(SensorPin);
  sensorTemp = map (sensorVal, 200, 800, 30, 80);   // test with sensor

  // setVal = analogRead(SetPin);
  // setTemp = map (setVal, 0.0, 1024.0, 29.0, 80.0);   // pot

  tempDiffPos = (sensorTemp - setTemp);
  tempDiffNeg = (setTemp - sensorTemp);

  lcd.setCursor(0, 0);
  lcd.print("SENSOR    ");
  lcd.setCursor(10, 0);
  lcd.print(sensorTemp);
  lcd.setCursor(0, 1);
  lcd.print("  SET     ");
  lcd.setCursor(10, 1);
  lcd.print(setTemp);

  //**************************************************  BLUE FUNCTION  **********************************************
  // turn cooling on and check cooling circuit in the mains power.  if an issue is found in the mains power, log the fault and display fault

  while (digitalRead(button) == LOW) {
    SetTempVal();
  }

  if (sensorTemp - setTemp > 0) {
    digitalWrite(LED_G, LOW);
    digitalWrite(LED_R, LOW);
    digitalWrite(relayPin, HIGH);
    delay(100);

    while (digitalRead(relaySensor) == HIGH ) {
      for (int b = 15; b <= 255; b++) {
        analogWrite(LED_B, b);
        delay(5);
      }
      for (int b = 255; b >= 15; b--) {
        analogWrite(LED_B, b);
        delay(5);
      }
    }

    if (digitalRead(relaySensor) == LOW) {
      count++;
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("     SYSTEM     ");
      lcd.setCursor(0, 1);
      lcd.print("     FAULT!      ");
      for (int i = 0; i <= count; i++) { 
        countDisplay(); 
      }
      delay(1250);
    }
  }

  //************************************************  GREEN FUNCTION **********************************************

  // if statement uses digital read so that green function doesnt clash with blue function.  also display fault log if applicable

  if (((tempDiffPos <= 1.3) && digitalRead(relaySensor) == LOW) || ((tempDiffNeg >= 1.3) && digitalRead(relaySensor) == LOW))  {
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_R, LOW);

    for (int g = 15; g <= 255; g++) {
      analogWrite(LED_G, g);
      delay(5);
    }
    for (int g = 255; g >= 15; g--) {
      analogWrite(LED_G, g);
      delay(5);
    }
    if (count > 0) {
      for (int i = 0; i <= count; i++) { 
        countDisplay(); 
      }
      delay(1250);
    }
  }

  //********************************************* RED FUNCTION ********************************************
  // display fault log if applicable and show there is no cooling action taking place

  if (tempDiffNeg >= 1.4) {
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_G, LOW);
    if (count > 0) {
      for (int i = 0; i <= count; i++) { 
        countDisplay(); 
      }
      delay(1250);
    }
    for (int r = 15; r <= 255; r++) {
      analogWrite(LED_R, r);
      delay(5);
    }
    for (int r = 255; r >= 15; r--) {
      analogWrite(LED_R, r);
      delay(5);
    }
  }

  //  ********************************************************************************

  else {
    digitalWrite(relayPin, LOW);
    digitalWrite(LED_B, LOW);
    digitalWrite(LED_G, LOW);
    digitalWrite(LED_R, LOW);

  }
}

// *****************************************  FUNCTIONS   ***********************************

void countDisplay() {
  digitalWrite(LED_R, HIGH);
  delay(350);
  digitalWrite(LED_R, LOW);
  delay(350);
}

int SetTempVal() {
  // lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("  KOEL'D  BEER  ");
  lcd.setCursor(0, 1);
  setVal = analogRead(SetPin);
  setTemp = map (setVal, 0.0, 1024.0, 29.0, 80.0);   // pot
  lcd.print(setTemp);
  return (setTemp);
}

setTemp is declared as a global variable and as such it’s manipulation inside SetTempVal is already exposed. You can make that function void and delete the return statement.

Under other circumstances, when you declare a function of type_t you generally work on local variables that lose scope as soon as the function exits. The return variable; (no parentheses) statement passes the value to the variable declared when calling the function: type_t variable = function();. In tour case, the attempt at returning setTemp was fruitless as the only call to SetTempVal() in the BLUE FUNCTION while loop did not assign the value.

A common example of the is the often use test if(Serial.available()) you proceed (or not) with a Serial.read. What most understand is that this test will pass if there is data in the buffer and fail otherwise, the test case resulting in a non-zero or zero response. What many don’t realize is that if, at any time, one were to include to statement such as buffer_contents = Serial.available();, buffer_contents would then contain the number of chaeacters in the input buffer.

Back to your issue, what is connected to button, pin2 (obviously a button), and how is it being triggered?

the button is an on/off switch. I was attempting to create a condition that the user has to press the button and then set the desired temp via pot and then turn the button off and in that process the value be “saved”

You do realize that the program will sit in this loop forever if the button isn't pushed?

How so? Because of no break statement? Or would it depend on how I wire the switch. Normally high or normally low

while (digitalRead(button) == LOW) { SetTempVal(); }

This will keep repeating until button is HIGH.

Yes, understood.... I'll change to pinMode(INPUT_PULLUP)