Whats the best way to showcase changing values on a display

Hello community :slight_smile:

I'd like to gather some thoughts on how to make this project work in the most efficient way.

Hardware:
Im using an Arduino Nano with a Grove-LCD RGB Backlight Display V4.

Project in general:
I have a Display which is showcasing the following text in a cycle of 3 sec.

1st

Temperature:
Setpoint: 28°C

2nd

Temperature:
Measured: 29°C

My thought is to change the setpoint with a potentiometer. So if the potentiometer value changes another kind of text should be displayed, which shows the setpoint and displays the current value.

Setpoint Setting:
potentiometer_val

After this setting, it should just jump back to displaying the temperature in cycles.

#include <Wire.h>
#include "rgb_lcd.h"
#include <PID_v1.h>

const int colorR = 100;
const int colorG = 100;
const int colorB = 100;

int LM35 = A0;
int PWM_PIN = 3;
int poti = A1;

int pwmval = 0;
int sensorwert;
float messwert;
int sollwert;
double Setpoint ; 
double Input; 
double Output ; 
//PID parameters
double Kp=5, Ki=10, Kd=0; 

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
rgb_lcd lcd;
void setup() 
{
    // set up the LCD's number of columns and rows:
    lcd.begin(2, 16);
    
    lcd.setRGB(colorR, colorG, colorB);

    //PID
    Setpoint = 30;
    myPID.SetMode(AUTOMATIC);
    myPID.SetTunings(Kp, Ki, Kd);
    
    pinMode(Button1, INPUT);
    pinMode(PWM_PIN,OUTPUT);
    
}

void loop() 
{
    showTemperature(getTemperature(), sollwert);
    myPID.Compute();
    setPwmValue(Output);
    
}

void showTemperature(int messwert, int sollwert){

    String option1 = "Sollwert: ";
    option1+= sollwert;
    option1+= " C";
    String option2 = "Messwert: ";
    option2+= messwert;
    option2+= " C";
     
    lcd.setCursor(0,0);
    lcd.print("Temperature:");

    lcd.setCursor(0,1);
    lcd.print(option1);
    delay(3000);
    lcd.clear();

    lcd.setCursor(0,0);
    lcd.print("Temperature:");

    lcd.setCursor(0,1);
    lcd.print(option2);
    delay(3000);
}

int getTemperature(){
    sensorwert=analogRead(LM35); //Auslesen des Sensorwertes.
    messwert = ((sensorwert * 5000.0) / 1024.0)/10;
    //Serial.println(messwert);
    return(messwert);
}

void showSetpointScreen(){
  
}

void setPwmValue(int value){
  analogWrite(PWM_PIN, value);
}


/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

Here you can see my code. I know its really basic and probably pretty bad, i learned arduino like 5 years ago and this is my first project since.
I think the basic problem with this is my showTemp function. Since it has a 2 delays of 3 secs in it. I've tried using an interrupt, which should have cleared the screen and showcased the setpoint, but with that my display just crashed. I really dont know why.
So basically, my question is, how to simultaneously have my showTemp function showing and still react to the changing values of the potentiometer.

If something isnt clear, please ask.

I'd really need some help, thanks in advance.

The functions delay() and delayMicroseconds() block the Arduino until they complete. And an interrupt is not the correct solution.

Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R