I’m trying to use the time and date library and i’m getting odd results - probably something i don’t understand. I can use the setTime with a single argument of seconds since 1970 but when i try to use it with multiple arguments [setTime(hr,min,sec,day,month,yr)] I get anomalous results.
The following is adapted from the serial example - it should show the same time twice(I thought) but no such luck. I tried it on arduino 21 just in case but no change.
/*
* TimeSerial.pde
* you can send the number on the next line to set the clock to noon Jan 1 2010
1262347200
*/
#include <Time.h>
void setup() {
Serial.begin(115200);
Serial.println("Testing Time Setting Functions");
setTime(1262347200); // seconds since jan 1 1970
digitalClockDisplay();
setTime(12,0,0,1,1,2010); // another way to set the time setTime(hr,min,sec,day,month,yr)
digitalClockDisplay();
}
void loop(){
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
ok, took me a while to get a fresh 328 burned but the issue is the particular chip i was using. i suspect maybe a bad memory patch that only showed up with a more complex program. huh!
vidya_ACSPL:
I want to display date and time on 16*4 lcd . i download DateTime.h library. but code was not complied. reply please
The DateTime library in the playground is obsolete and was replaced by newer code four years ago. There is a note on the web page for the old DateTime code that provides the link to the latest version: http://playground.arduino.cc/Code/Time.
A little time searching in this forum or with google should turn up a number of examples of LCD clocks built using the Time library.
here is one example: Siliconfish: Arduino LCD Countdown Clock