# Timer/for 1 hour

Project where if an input is triggered and if the condition is not cleared after 1 hour a buzzer is triggered. Other routines need to continue to run during the one hour period. what would be some of the methods to accomplish that?

Along these lines:

``````boolean condition = false;

void loop()
{

if (isOn && !condition)
{
// start 1-hour timer;
lastMillis = millis();
condition = true;
}

if (condition && (millis() - lastMillis >= 3600L * 1000))
{
// 1 hour passed; ring the bell;

// reset the condition for a new 1-hour timer;
}

}
``````

florinc Awesome I'll give it a try.

Can I ask what the "L" means in 3600L. I have seen it used before.

L

Navigator_x2:
florinc Awesome I'll give it a try.

Can I ask what the "L" means in 3600L. I have seen it used before.

it tells the compiler to treat 3600 as a long value (32bit) instead of int (16bit).

the compiler will use the smallest possible memory storage to calculate a value, each value is
treated individually, so if you have an equation such as:

``````unsigned long longVar = 1000 * 1000; // you would expect the answer to be 1000000,
// but it longVar would equal 16960 because 1000 will fit in a 16bit int, a 16bit * 16bit = 16bit
// any value that overflows is lost

unsigned long longVar = 1000L * 1000; // causes the compiler to promote all of the constants
// on the right side to longs (32bit) so the answer is now 1000000
``````

Chuck.

florinc:
Along these lines:

``````boolean condition = false;
``````

void loop()
{

if (isOn && !condition)
{
// start 1-hour timer;
lastMillis = millis();
condition = true;
}

if (condition && (millis() - lastMillis >= 3600L * 1000))
{
// 1 hour passed; ring the bell;

// reset the condition for a new 1-hour timer;
}

}

nice snippet of code.
add a RTC and you can chime a clock every hour.
// if (worldEnd=TRUE){ commented out to save the world.
if (worldEnd==TRUE){
end program
}
and it could go on for as long as we are here.

Thanks All

This maybe what I was looking for in this project. I will play with the examples.

All the answers and help is appreciated as always.

Cheers

dave-in-nj:
if (worldEnd=TRUE){
end program
}
and it could go on for as long as we are here.

Oops!
Using a single equals sign will set worldEnd to TRUE.
You don't want that, do you?

odometer:
Oops!
Using a single equals sign will set worldEnd to TRUE.
You don't want that, do you?

YIKES !
the DESTRUCTOR of worlds with 1 line of code.....

dave-in-nj:
nice snippet of code.
add a RTC and you can chime a clock every hour.