Go Down

Topic: Time comparision (Read 1 time) previous topic - next topic

Delta_G




850 / 60 = 14,166666667

14 are the hours
0,166666667 x 60 are the minutes (14:10 hours)

But then I have to figure out how I can fill variable HOUR with all the things before the comma, and variable MINUTES with al the thing after the comma... (and I don't know how to do this)

So your idea is better :)

Thanks!!





Look at the modulous "%" operator.  It will do exactly what you want.

850 / 60 = 14 hours (using ints no decimals rounds down)

850 % 60 = 10 minutes

Jack Christensen




But after +/- 50 days the millis counter goes back to 0, so in that case you also have to "test" the value to make a good timing to power on the LED.


Actually not!



How do you mean?
From: http://arduino.cc/en/Reference/Millis

Quote
Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.



Of course it does overflow, but because it's an unsigned (long) integer any two values can be subtracted and will give the right answer, as long as you're not trying to time a delta of more than ~50 days.

Quote

One more alternative is the Time library, the time_t data type is seconds since 01Jan1970.
Quote


Thanks!! Also a good one.
That must be a large number in these days :smiley-mr-green:



Yep, about 1316107515 right now ... see http://www.unixtimestamp.com/. There are parties when it hits a notable value, like 1234567890.

Quote

Now I'm stuck again:

How can I "test" a number let's say 11 if it's at least 2 digits/counts away from another number?

So if I have a = 11

and b = 14 OR for example b = 10

how can I "check" if a is > b+2 OR a < b-2

At the moment I use

Code: [Select]
if (SprMinute< minuten +2 || SprMinute> minuten -2){

but this doesn't seem to work.
This is also for "checking" the time...

Thanks!!

Atmoz

[edit]

I found it. I had to swap + and - :)


Or use the abs() function.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Atmoz


Of course it does overflow, but because it's an unsigned (long) integer any two values can be subtracted and will give the right answer, as long as you're not trying to time a delta of more than ~50 days.


Thanks for the explanation!!

Quote

Yep, about 1316107515 right now ... see http://www.unixtimestamp.com/. There are parties when it hits a notable value, like 1234567890.


Quote

Or use the abs() function.


Also thanks for that one.
I had looked at this before, but didn't directly understand how it works.
I'll have a look at it tomorrow!!


@Delta_G

THANKS!

That I was searching.
very very long ago I already uses this, but I was completely forgotten it.

Everything is working how it should be.

Very nice 8) Thanks :D

Atmoz

emilyskopp

Anyone have advice for a working clock?  I have an RTC module, but I don't know how to program it to remember time.

jwatte

The RTC module needs a battery to "remember" time. Once you insert the battery, it will remember time (and keep it ticking) even when turned off. Just make sure you don't re-write a bad time in your setup() function!

Also, I've found that, when dealing with timed events, it's better to compare seconds intervals than specific times. So, for example, if you want to turn something on 15 minutes after something else, then calculate the seconds (epoch) value for the first time, add 15*60, and then when the seconds (epoch) value goes past that value, you turn on the thing. You can check this each time the timer changes, and there's no chance you will miss it -- even if the chip is turned off, and then turned on in the middle of the timer interval, the check will then see "oh, it's greater than start time -- turn on!"

Go Up