Kariky
April 6, 2011, 5:45pm
1
If i want to print value once a second far to the future is this OK for it:
Light1 = analogRead(LDR1);
if (TimeNow > PrintTime)
{
Serial.println(Light1);
PrintTime = (TimeNow + 1000);
}
TimeNow = millis();
There will be value overflow sometimes (in every 70 min or what was that)
but does it actually matter in this use ? Or is there easy "proper" way to print it with few lines ?
(PrintTime is also unsigned long, like millis() is)
A subtraction should always be used so the roll-over will have no effect. Here is a rather long posting on the subject:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260223964/1
system
April 6, 2011, 5:54pm
4
is this OK for it:
No. Subtraction s safe. Addition is not.
if(TimeNow - PrintTime > 1000)
{
// print...
PrintTime = TimeNow;
}
There will be value overflow sometimes (in every 70 min or what was that)
millis() overflows in about 49 days. micros() overflows in about 70 minutes.
Kariky
April 6, 2011, 6:02pm
5
Of course it should be done by sutracting ! Thanks for fast replies !
little messed millis and micros too