Delay for xx minutes

I have the following code, which does compile and upload. I have not seen any errors appear yet, but is it the correct / acceptable way to code this ?

I want to wait / delay a number of minutes ( 5 in the example code, but may be up to 60 minutes when added to a project ).

long DVRpauseMIN = 5; 
long DVRpauseMil = 0;


void setup(void) {

    DVRpauseMil = millis();

}


void loop(void){ 

    unsigned long currentMillis = millis();

    if (currentMillis - DVRpauseMil >= (DVRpauseMIN * 60000)){
        Serial.println("Time has expired");
    }

}

Yes as Mr Punch would say "that's the way to do it".

Many Thanks GM

Hope you have a Happy Day.

Make all the variable types unsigned long

and use 60000UL as well.

As written, once the if-condition is met, you will get a steady stream of "time has expired" messages unless you do something to make the test fail when loop starts again; millis() keeps increasin, so your condition will remain true.

As written, once the if-condition is met, ....

Yes I know that, I took it to mean the general principal of what he was doing. Anyway that is probably what he wanted to do.

CrossRoads: Make all the variable types unsigned long

and use 60000UL as well.

As written, once the if-condition is met, you will get a steady stream of "time has expired" messages unless you do something to make the test fail when loop starts again; millis() keeps increasin, so your condition will remain true.

Thanks. Yes, as GM mentioned, it was just for the principal that I wrote the code.

In reality, I would set the DVRpauseMil to zero after the condition was met. In order to restart the delay timer again from anywhere in the code, I would simply re-assign the millis value to DVRpauseMil again ( so it is a non-zero value, and it contains the starting millis )

I have added the 'unsigned' but not too sure about the "UL". I googled and I see that it means 'unsigned long" - are you saying that we are basically forcing the 60000 to be an unsigned long, so that there are no data type clashes because all the other variables used in the equation are also UL ?

My code is now :

unsigned long DVRpauseMIN = 5; 
unsigned long DVRpauseMil = 0;


void setup(void) {

    DVRpauseMil = millis();

}


void loop(void){ 

    unsigned long currentMillis = millis();

    if (DVRpauseMil != 0 && currentMillis - DVRpauseMil >= (DVRpauseMIN * 60000UL)){
        Serial.println("Time has expired");
        DVRpauseMil = 0;
    }

}

"are you saying that we are basically forcing the 60000 to be an unsigned long, so that there are no data type clashes because all the other variables used in the equation are also UL " Yes.