Watch in arduino


I wonder if it is any watch that you can use when you are programming in arduino duemilanove?

Do you mean getting time from an external source? Or having the arduino act as a watch? Or having a way to measure leapsed time?

All are possible, please explain more what you want to do.

Acting like a watch, so if your are using a IF loop, you can refer to that specific watch.

That the arduino have an watch itself that you can refer to.

Yes, there are two functions for keep track of time elapsed.
millis(), milliseconds gone by since your sketch started.
micros(), microseconds gone by since your sketch started.
variable associated with time calculations are of type long unsigned, that is 32 bit numbers between 0 and 2^32.

To use, do something like this.

start_time = millis();
end_time = millis();
elapsed_time = end_time - start_time;
duration = 1000UL; // for example.  

while (elapsed_time <= duration) {  // // stay in this mini-loop until time has elapsed

// do whatever it is you are doing

end_time = millis(); '// check the time
duration = end_time - start_time;  // see how long it has been
}  // keep going after duration is met

Similarly, if you want to do it as an if condition as part of a larger loop:

if (triggering_event_occurred){
event_started_flag = HIGH;
start_time = millis();  // capture the time
duration = 1000UL; // for example. 

end_time = millis;// capture the time
elapsed_time = end_time - start_time;  //see how much has gone by

if ((event_started_flag == HIGH) && (elapsed_time <= duration){
// do something in here once, then again next  time thru, and so on
// when done, clear the flag
    if (end_condition is met){
    event_started_flag = LOW;}

Hopefully this will give you some ideas.

ANd furthermore there is a TimeLibrary -

Thanks allot guys. ;) I will try to do so and look up that 'Time library' also. :)

When I was trying to program the arduino, I was wearing a Casio Baby-G BGF-130. It has an infrared capability that allows another such watch (which I’ve yet to see) to exchange ‘data’ via the built-in infrared. Nobody knows the protocol.

If you want to track time longer than a few days or between arduino power on and off, you need a real time clock with battery back up. It keeps year/month/day/day of week/hour/minute/second.

Take a look at this alarm clock I made with arduino and Phi-1 shield: