We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I normally use millis()
to time animations, but now I'm working on a piece that will be installed in a gallery for three months. It will be powered on every morning and shut down at night, so it needs to run all day for about 12 hours without crashing.
In this context, could the very large value of millis()
cause any problems? (For example, could this exceed the capacity of a standard int
?) Are there other approaches to timing events that don't rely on measuring total running time, but simply relative time (e.g. trigger another event in 1 minute from now, as opposed to in 123 minutes from when the sketch started running)?
Would love to hear thoughts from anyone else using Processing for installation work.
Answers
An
int
capacity is from -2^31 to 2^31 - 1. Of course millis() starts out at 0. So, let's ignore the negative range! :(|)But if you wanna know what happens after the highest positive
int
is extrapolated, it becomes -2^31! 8-XAnyways, I've made Processing give us the answer. Function millis() spits out positive values up to 24 days (3/4th months)! :-bd
Since it's turned off at night, only 1/24th is used up. Function millis() is zeroed at each run anyways! :!!
Sure any timer will do that, the general idea is:
@_vk Function millis() returns an
int
value. @alignedleft was just worried about how many milliseconds there are! >-)About alternative approaches, there's some from this forum below:
http://forum.processing.org/two/discussion/1725/millis-and-timer
Here's my own take there:
@GoToLoop Perfect, thank you! So, this is only cause for worry if you were to have an installation running for 24+ days nonstop.
If anyone has suggestions for how to handle that kind of long-term installation scenario, I'd love to hear about it. I suppose you'd just need to check for negative values (for when
millis()
wraps around to -2^31).TimerTask doesn't depend on previous values and uses
long
rather thanint
for how many milliseconds to trigger! o->For a simpler approach, but w/ more preciseness, go w/ System.currentTimeMillis():
docs.oracle.com/javase/7/docs/api/java/lang/System.html#currentTimeMillis%28%29
Or even System.nanoTime(), which millis() idea is based upon. But the former uses
long
instead ofint
:docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime%28%29
Super, thanks!
sorry. : P