Hi
I try to write a control program with a time code
i want to write in the file and on screen the date and time (dd/mm/yyyy hh/mm/ss)
i write this simple program:
#include <TimeLib.h>
// Variable Declaretion -----------------------------------------------------------
//Time And Date Variables ---------------------------------------------------------
String DandT;
int Sec;
int Mint;
int Hr;
int Dy;
int Mnth;
int Yr;
String SSec;
String SMint;
String SHr;
String SDy;
String SMnth;
String SYr;
//----------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
// Clock Setup Only For The First Time ---------------------------------------------
setTime(22, 34, 25, 29, 3, 1982);
//----------------------------------------------------------------------------------
}
void loop() {
// SetUp Time String For Display --------------------------------------------------
Sec=int(second());
Mint=int(minute());
Hr=int(hour());
Dy=int(day());
Mnth=int(month());
Yr=int(year());
if (Sec<10){
SSec="0"+String(Sec);
}else{
SSec=String(Sec);
}
if (Mint<10){
SMint="0"+String(Mint);
}else{
SMint=String(Mint);
}
if (Hr<10){
SHr="0"+String(Hr);
}else{
SHr=String(Hr);
}
if (Dy<10){
SDy="0"+String(Dy);
}else{
SDy=String(Dy);
}
if (Mnth<10){
SMnth="0"+String(Mnth);
}else{
SMnth=String(Mnth);
}
SYr=String(Yr);
DandT=(SDy+"/"+SMnth+"/"+SYr+" "+SHr+":"+SMint+":"+SSec);
//------------------------------------------------------------------------------------
Serial.println (DandT);
delay (500);
}
time_t getTeensy3Time()
{
return Teensy3Clock.get();
}
A 3V battery is connected to the Vb pin and to the GND
but when i delete the set time line it is always go back to 1.1.1970
why?
how can i keep the time from restarted again every time?
thank you
I try to write a control program with a time code
i want to write in the file and on screen the date and time (dd/mm/yyyy hh/mm/ss)
i write this simple program:
#include <TimeLib.h>
// Variable Declaretion -----------------------------------------------------------
//Time And Date Variables ---------------------------------------------------------
String DandT;
int Sec;
int Mint;
int Hr;
int Dy;
int Mnth;
int Yr;
String SSec;
String SMint;
String SHr;
String SDy;
String SMnth;
String SYr;
//----------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
// Clock Setup Only For The First Time ---------------------------------------------
setTime(22, 34, 25, 29, 3, 1982);
//----------------------------------------------------------------------------------
}
void loop() {
// SetUp Time String For Display --------------------------------------------------
Sec=int(second());
Mint=int(minute());
Hr=int(hour());
Dy=int(day());
Mnth=int(month());
Yr=int(year());
if (Sec<10){
SSec="0"+String(Sec);
}else{
SSec=String(Sec);
}
if (Mint<10){
SMint="0"+String(Mint);
}else{
SMint=String(Mint);
}
if (Hr<10){
SHr="0"+String(Hr);
}else{
SHr=String(Hr);
}
if (Dy<10){
SDy="0"+String(Dy);
}else{
SDy=String(Dy);
}
if (Mnth<10){
SMnth="0"+String(Mnth);
}else{
SMnth=String(Mnth);
}
SYr=String(Yr);
DandT=(SDy+"/"+SMnth+"/"+SYr+" "+SHr+":"+SMint+":"+SSec);
//------------------------------------------------------------------------------------
Serial.println (DandT);
delay (500);
}
time_t getTeensy3Time()
{
return Teensy3Clock.get();
}
A 3V battery is connected to the Vb pin and to the GND
but when i delete the set time line it is always go back to 1.1.1970
why?
how can i keep the time from restarted again every time?
thank you