need help Millis 1 hour

 at the folowing code [code
unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000;  //the value is a number of milliseconds
const byte ledPin = 13;    //using the built in LED

void setup()
{
  Serial.begin(115200);  //start Serial in case we need to print debugging info
  pinMode(ledPin, OUTPUT);
  startMillis = millis();  //initial start time
}

void loop()
{
  currentMillis = millis();  //get the current "time" (actually the number of milliseconds since the program started)
  if (currentMillis - startMillis >= period)  //test whether the period has elapsed
  {
    digitalWrite(ledPin, !digitalRead(ledPin));  //if so, change the state of the LED.  Uses a neat trick to change the state
    startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED state.
  }
}]

if i want to use miilis every 1 hour do i have to write const unsigned long period:

1UL60UL60UL*1000UL

instead : const unsigned long period = 1000;

is it correct ?

3,600,000 milliseconds makes a hour

const unsigned long period = 3600000;

so if let say i want for 6 hours for example i have to use :21600000 and so on is it correct ?

dataoikogarden:
so if let say i want for 6 hours for example i have to use :21600000 and so on is it correct ?

Ok now this is a different question.

The range of values of Arduino unsigned long is between 0-4,294,967,295. As long as your period is between these values you can use the value. If the value is outside this range, you will need to solve for this.

Correct, but by that time we're talking about almost 50 days. And by that time you also have a pretty big error. So a good time to rethink the approach if you want to time > 50 days :smiley:

And for 1 hour, you can indeed use 1UL60UL60UL*1000UL or even 1 *60 * 60 * 1000UL

and if i want more than 52 days ?

dataoikogarden:
and if i want more than 52 days ?

You will have to code to handle this. Do it for number of days, then do again for additional time. However, at this point you might want to consider using an RTC as it will keep time better and allow you to check longer time intervals.

thank you very much for your answers.