You have 2 other options to the setInterval()
function:
delay()
(blocking)
millis()
(non-blocking)
Both of these functions deal with an unsigned long
which has 32 bits = (2^32)-1 = 4,294,967,295. Doing the sums (and considering that both are in milliseconds), this will last for 49 days and 17 hours.
1 second = 1000 milliseconds
1 minute = 60 seconds
1 hour = 60 minutes
12 hours = 12 * 60 * 60 * 1000 = 43,200,000
delay(x)
will delay for x number of milliseconds. The delay function is blocking, meaning that while it is running/delaying you can't do any other task. The code would be:
delay(43200000);
millis()
on the other hand is non-blocking and returns the number of milliseconds since power-up. This can be implemented with the following code:
#define TWELVE_HRS 43200000UL
unsigned long startTime;
setup()
{
startTime = millis();
}
loop()
{
if (millis() - startTime > TWELVE_HRS)
{
// Put your code that runs every 12 hours here
startTime = millis();
}
}
int setInterval(long d, timer_callback f)
.