Pages: 1 [2]   Go Down
Author Topic: Possible to print millis in [HH:MM:SS] format?  (Read 3442 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So how can I test this?  I'm trying to test it in serial before inserting into my tweeting sketch.

This seems so basic to have some sort of run time clock on an arduino device.  Why is this so difficult?
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 6
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This seems so basic to have some sort of run time clock on an arduino device.  Why is this so difficult?

Because you mess around. Back to your original code sample, when applying the hint you got about the Time library, you might get something like this:

Code:
sprintf(tweet,"%2.2d:%2.2d:%2.2d Sensor Reading S1=%e S2=%e",
 hour(), minute(), second(),
 (float)temp_f, (float)real_humidity);

And don't forget to include the Time library at the top of your sketch with this:
Code:
#include <Time.h>

Does that look like a start? If you want to have time match the real time closer, you can set it anywhere in your program with:
Code:
setTime(hr,min,sec,day,month,yr);
This leaves only the small detail of getting good values for the variables hr, min, sec, day, month and yr. This can be achieved in various ways, but that we can leave for later. For experimenting you always can put that line in your setup() function:
Code:
setTime(10,55,0,22,11,2010);

Korman

« Last Edit: November 21, 2010, 07:16:35 pm by Korman » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This seems so basic to have some sort of run time clock on an arduino device.  Why is this so difficult?
You are starting from a false assumption. For 99% of embedded projects, the current time as relayed by your wall clock is completely irrelevant.

Think of a washing machine. The controller needs to turn the motor on and off at specific times, and to open and close water valves at specific times. Those times are not based on the wall clock, though, They are relative to the time you push the start button.

Does the dishwasher or microwave need to know what time it is. No. Everything they need to do is based on the time you press the go button.

You are the one trying to force a device that doesn't know about wall clocks to pretend that it does.

If you read this page:
http://arduino.cc/en/Reference/HomePage
you will see what each function does, and how they can, and can not, be combined to produce useful results.
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 168
Posts: 12433
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reaction on your code feew postings back :

You should declare functions outside the loop(). Try this code
Code:
void setup()
{
   Serial.begin(9600); // Open serial connection to report values to host
   Serial.println("Starting up");
}

void loop()
{
  char *s;
  s = TimeToString(millis()/1000);
  Serial.println(s);
  delay(456);
}


// t is time in seconds = millis()/1000;
char * TimeToString(unsigned long t)
{
  static char str[12];
  long h = t / 3600;
  t = t % 3600;
  int m = t / 60;
  int s = t % 60;
  sprintf(str, "%04ld:%02d:%02d", h, m, s);
  return str;
}

 
« Last Edit: November 22, 2010, 09:18:52 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
 delay(456);
456? What significance does that value have?
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 168
Posts: 12433
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
456? What significance does that value have?
none, I just didn't want to wait 10 seconds to see it work smiley
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Because you mess around. Back to your original code sample, when applying the hint you got about the Time library, you might get something like this:

Korman, you are the man!  Thank you so much.  It's working flawlessly after 24 hours now.  Thank you so much!

www.twitter.com/myhumidor
« Last Edit: November 23, 2010, 11:56:27 am by .jacob » Logged

Pages: 1 [2]   Go Up
Jump to: