Can't get delay to work for more than 1 place in code

Hi

I have a code where I have delay added 3 times. It all works nicely in the beginning as long as the if sentence is false and it uses delay (6000); in the end of the code. When the if sentence is valid it then halts for the first delay for 1 second but it just skips all other delays, even if the if sentence is not valid anymore. Anyone have any esy suggestions on what could be wrong, I have tried to look around in the internet but can't seem to find a solution.

int analogPin = A3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int val = 0;           // variable to store the value read
int delay1 = 6000;
int delay2 = 1000000;

//Pumpemotor
int pinOut = 10;

//Vannmengdemaaler
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;                               
int hallsensor = 2;    //The pin location of the sensor

void rpm ()     //This is the function that the interupt calls 
{ 
 NbTopsFan++;  //This function measures the rising and falling edge of the 
}

void setup()
{
  //Pumpe
  pinMode(10, OUTPUT);
  
  
  Serial.begin(9600);              //  setup serial

  //Vannmengdemaaler
    pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input initialised,
    attachInterrupt(0, rpm, RISING); //and the interrupt is attached
}

void loop()
{
  delay (6000);
  val = analogRead(analogPin);     // read the input pin
  Serial.println(val);             // debug value
  
  //pumpemotor
  if (val >= 430){    
    digitalWrite(pinOut, HIGH);
    Serial.print ("Slår på pumpe og venter 10 sekunder\r\n");
    //Vannmengdemaaler
    NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
    sei();            //Enables interrupts
    delay (1000);      //Wait 1 second This delay always works
    cli();            //Disable interrupts
    Calc = (NbTopsFan / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L hour
    Serial.print (Calc, DEC); //Prints the number calculated above
    Serial.print (" L/minute\r\n"); //Prints "L/minute" and returns a  new line
    digitalWrite(pinOut, LOW);
    Serial.print ("Before delay\r\n");
    delay (delay2);   //This delay never works
    Serial.print ("After delay\r\n");
   }
  else { 
    Serial.print ("Ok fuktighet, venter 60 sekund\r\n");
    delay(6000); //This delay works until the if sentence above is valid, after the if sentence has been valid once it does not work anymore
  }
}

You have delay2 declared as an int and initialized to a value of 1,000,000.

Did you get any compiler warnings when building this?

No, the number 1,000,000 was just picked to have a loooong delay just to make sure I wasn't messing around and somehow got microseconds or anything. I have tried with 1000 also with the same issue.

...
Serial.print ("Slår på pumpe og venter 10 sekunder\r\n");
    //Vannmengdemaaler
    NbTopsFan = 0;      //Set NbTops to 0 ready for calculations
    sei();            //Enables interrupts
    delay (1000);      //Wait 1 second This delay always works
    cli();            //Disable interrupts
...

Delay requires that interrupts be enabled. I see a cli() after your 1-sec delay but you don't enable them again afterwards. Intentional?

(BTW, even if you wanted a huge delay for testing 1E+06 doesn't fit into a 16-bit int.)

That sounds like a correct solution. I will test it later tonight. I took the code from various places and somehow that part slipped my eyes. I won't miss it next time!