Pages: [1]   Go Down
Author Topic: Problem with Time library  (Read 559 times)
0 Members and 1 Guest are viewing this topic.
vancouver, canada
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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) = smiley-cool

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


9181
hour 2
minute 33
second 1
10200
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...?

Thanks
Ned
« Last Edit: December 31, 2010, 06:23:13 pm by seagoon » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


(10200 - 9181) / 60 = 16.9833333

16.9833333 looks suspiciously like the number of minutes between the two values.  Try dividing previousMillis by 1000.
« Last Edit: December 31, 2010, 06:27:07 pm by bcook » Logged

vancouver, canada
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

BINGO!!!

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

Thanks

Ned :-[
Logged

Pages: [1]   Go Up
Jump to: