Go Down

Topic: Problem with Time library (Read 1 time) previous topic - next topic


Jan 01, 2011, 12:19 am Last Edit: Jan 01, 2011, 12:23 am by seagoon Reason: 1
Hi Guys

I'm having difficulty understanding how to use the Time library. In particular... I have a variable "previous_read_millis" which records the last time I read the sensors. I then want to do some further logic based on the hour and minutes of the time recorded as per the following line of code...

if(hour(previous_read_millis) = 8)

This didn't produce the desired result, so I tried outputting a test sketch to the serial monitor to see what was happening...

 Serial.println (previousMillis);
 Serial.print ("hour ");
 Serial.println (hour(previousMillis));
 Serial.print ("minute ");
 Serial.println (minute(previousMillis));
 Serial.print ("second ");
 Serial.println (second(previousMillis));

This code returned the following output

hour 2
minute 33
second 1
hour 2
minute 50
second 0

but surely this is wrong... I was expecting...

hour 0
minute 0
second 10

What am I doing wrong...?


Coding Badly

Jan 01, 2011, 12:26 am Last Edit: Jan 01, 2011, 12:27 am by bcook Reason: 1

(10200 - 9181) / 60 = 16.9833333

16.9833333 looks suspiciously like the number of minutes between the two values.  Try dividing previousMillis by 1000.



Now why didn't I spot that....?


Ned :-[

Go Up