Two loops possible?

Hi guys,

it worked! I just inserted the blinking example without delay. Now it works smoothly. I have another problem. The blinking rate is connected to a editable number field n5 on nextion display. the specific code is:

uint32_t rateSet = 0;                                   
n5.getValue(&rateSet);   
const long interval = (60/rateSet*1000)/2;  

Because of this the led will only blink when I am on the specific page where n5 is displayed. Is it possible to read n5 all the time? So it doesnt matter on which page you are on the nextion.

this is the code in total:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Nextion.h>
 
#define SENSOR_PIN 28
OneWire oneWire(SENSOR_PIN );
DallasTemperature sensors(&oneWire);

NexWaveform s0 = NexWaveform  (3, 2, "s0");
NexNumber n3 = NexNumber      (3, 6, "n3");
NexNumber n4 = NexNumber      (0, 7, "n4");
NexNumber n5 = NexNumber      (3, 7, "n5");
NexDSButton bt0 = NexDSButton (0, 6, "bt0");

int buzzer = 11;

NexTouch *nex_Listen_List[] =
{
&bt0,
&n4,
&n5,
NULL
};



// HEARTRATE constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin

// HEARTRATE Variables will change:
int ledState = LOW;             // ledState used to set the LED

// HEARTRATE Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated






 
void setup() {
  // HEARTRATE set the digital pin as output:
  pinMode(ledPin, OUTPUT);

  
  pinMode(buzzer,OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  Serial2.begin(9600);
  sensors.begin();
  nexInit();

}
void loop() {
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  
    
  s0.addValue(0, temp);                                       // weergave temperatuur als wavevorm
  n3.setValue(temp);                                          // weergave temperatuur als nummer

  delay( 1 );
  
void bt0PopCallback(void *ptr);                               // Release event for dual state button bt0

  uint32_t alarmTswitch = 0;                                // alarmbutton - Create variable to store value we are going to get
  bt0.getValue(&alarmTswitch);                              // alarmbutton - Read value of dual state button to know the state (0 or 1)

  uint32_t alarmTset = 0;                                   // alarmset temperature- Create variable to store value we are going to get
  n4.getValue(&alarmTset);                                  // alarmset temperature- Read value of dual state button to know the state (0 or 1)

  uint32_t rateSet = 0;                                   // Rate set - Create variable to store value we are going to get
  n5.getValue(&rateSet);                                  // Rate set - Read value of dual state button to know the state (0 or 1)
    
    
      if (temp >= alarmTset && alarmTswitch == 0){                // controleer of temperatuur warmer is dan 26 graden
        digitalWrite(buzzer, HIGH);                         // als de temperatuur warmer is dan 26 graden zet LED aan
                    
    } else {
        digitalWrite(buzzer, LOW);                           // als de temperatuur niet warmer is dan 26 graden zet LED uit

    }

      if (temp >= alarmTset){                // controleer of temperatuur warmer is dan 26 graden
                                            // als de temperatuur warmer is dan 26 graden zet LED aan
        Serial2.print("n3.pco=63488");                      // maak kleur rood
        Serial2.write(0xff);
        Serial2.write(0xff);
        Serial2.write(0xff);

    } else {
                                                    // als de temperatuur niet warmer is dan 26 graden zet LED uit
        Serial2.print("n3.pco=65535");                       // maak kleur wit
        Serial2.write(0xff);
        Serial2.write(0xff);
        Serial2.write(0xff);
    }



  // HEARTRATE constants will change bij input n5:
  const long interval = (60/rateSet*1000)/2;           // interval at which to blink (milliseconds)

  // HEARTRATE here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);


  }
    


}