how to break a loop to add in a new setpoint

I am designing a temperature controller but i am now trying to add it a loop/break within a loop to change the setpoint via an ir remote but it keeps looping out, how can i stop the program until i enter the new setpoint and press a button to return to the main loop?

#include <LiquidCrystal.h>
#include <EEPROM.h>
#include "IRremote.h"

int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 3

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

const long enter_button = 0xFFA25D;


  
int tempPin = 0;
//                BS  E  D4 D5  D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define White = 4;
float settemp = 25; // make a variable called tem

 
void setup()
{
  lcd.begin(16, 2);
  pinMode(4, OUTPUT);
   EEPROM.read (1);
   Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  
 
}
void loop()

{

  int tempReading = analogRead(tempPin);
  // This is OK
  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK );       //  Temp Kelvin
  float tempC = tempK - 273.15;            // Convert Kelvin to Celcius
  float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  /*  replaced
    float tempVolts = tempReading * 5.0 / 1024.0;
    float tempC = (tempVolts - 0.5) * 10.0;
    float tempF = tempC * 9.0 / 5.0 + 32.0;
  */
 
  EEPROM.write(1,settemp);
  // Display Temperature in C
  lcd.setCursor(0, 0);
  lcd.print("Temp        C  ");
  // Display Temperature in F
  //lcd.print("Temp:         F  ");
  lcd.setCursor(6, 0);
  // Display Temperature in C
  lcd.print(tempC);
  lcd.setCursor(0, 1);
   lcd.print("Setpoint       C ");
  lcd.setCursor(9, 1);
  lcd.print(settemp);
 
  if (tempC > settemp ){
     digitalWrite(4, HIGH);
     delay(1000);
  }
  else if(tempC<settemp){
    digitalWrite(4, LOW);
    delay(1000);
  }
  
if (irrecv.decode(&results)) {   // results is an instance of a decode_results class, decode() returns an int
    //Serial.println(results.value, HEX);
    if( enter_button)
      {lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Enter Setpoint:");
  //   switch(results.value){
      //    case 0xFF6897:
       //   Serial.println("0");
         // break ;  
         // case 0xFF30CF:
         // Serial.println("1");
         // break ;
         // case 0xFF18E7:
          //Serial.println("2");
         // break ;
         // case 0xFF7A85:
         // Serial.println("3");
         // break ;
         // case 0xFF10EF:
         // Serial.println("4");
         // break ;
         // case 0xFF38C7:
         // Serial.println("5");
         // break ;
        //  case 0xFF5AA5:
         // Serial.println("6");
        //  break ;
         // case 0xFF42BD:
         // Serial.println("7");
        //  break ;
         // case 0xFF4AB5:
         // Serial.println("8");
         // break ;
        //  case 0xFF52AD:
        //  Serial.println("9");
        //  break ; }
     
   // lcd.print(results.value);
   // lcd.setCursor(1, 1);
   // lcd.print("            ");
   // lcd.setCursor(0, 1);
   // lcd.print(results.value);
     
    // irrecv.resume(); // Receive the next value;
      delay(1000);
  }
    

  //else if(tempC>=settemp & tempC<settemp){
 // digitalWrite(4,LOW)
 // }
  
  delay(500);
}
}

DEEKS: how can i stop the program until i enter the new setpoint and press a button to return to the main loop?

I suspect that should not be necessary.

And I think the problem is your use of delay() in several places because the Arduino can do nothing during a delay()

Have a look at how millis() is used to manage timing without blocking in Several things at a time. With that approach your program should be able to receive the new data without needing to be paused.

...R

Your code is unreadable, please strip out all the commented lines and show a proper minimal test case.

Important: You must remove the eeprom write function call from the loop subroutine. Eeprom can only withstand about 100,000 write cycles after that it will either fail outright or become flaky. You only write to eeprom when the data changes, not every loop through the program.

#include <LiquidCrystal.h>
#include <EEPROM.h>
#include "IRremote.h"

int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 3

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

const long enter_button = 0xFFA25D;


  
int tempPin = 0;
//                BS  E  D4 D5  D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define White = 4;
float settemp = 25; // make a variable called tem

 
void setup()
{
  lcd.begin(16, 2);
  pinMode(4, OUTPUT);
   EEPROM.read (1);
   Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  
 
}
void loop()

{

  int tempReading = analogRead(tempPin);
  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK );       //  Temp Kelvin
  float tempC = tempK - 273.15;            // Convert Kelvin to Celcius
  float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
  /*  replaced
    float tempVolts = tempReading * 5.0 / 1024.0;
    float tempC = (tempVolts - 0.5) * 10.0;
    float tempF = tempC * 9.0 / 5.0 + 32.0;
  */
 
  EEPROM.write(1,settemp);
  lcd.setCursor(0, 0);
  lcd.print("Temp        C  ");
  lcd.setCursor(6, 0);
  lcd.print(tempC);
  lcd.setCursor(0, 1);
   lcd.print("Setpoint       C ");
  lcd.setCursor(9, 1);
  lcd.print(settemp);
 
  if (tempC > settemp ){
     digitalWrite(4, HIGH);
     delay(1000);
  }
  else if(tempC<settemp){
    digitalWrite(4, LOW);
    delay(1000);
  }
  
if (irrecv.decode(&results)) {  
    if( enter_button)
      {lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Enter Setpoint:");
 
      delay(1000);
  }
    

  
  delay(500);
}
}

i will remove the eeprom, had it in there for when i was in putting my new setpoint

You don’t need to have a loop() breaking function to change your setpoint. Simply update the variable settemp as needed within the loop() and roll with the updated value. Simple fix