philip.porhammer
Well-known member
I need to manually set the RTC on the Teency 3.6 as it is going to my used by non-tekies.
the .h file had this:
//void setTime(int hr,int min,int sec,int day, int month, int yr);
so I did this in the setup:
setTime(3,22,46,1,2,23);
hourFormat12();
it does not retain the manually set time.
the code:
/*
* TimeRTC.pde
* example code illustrating Time library with Real Time Clock.
*
*/
//void setTime(int hr,int min,int sec,int day, int month, int yr);
#include <TimeLib.h>
//int led = 13;
void setup() {
// pinMode(led, OUTPUT);
// set the Time library to use Teensy 3.0's RTC to keep time
setSyncProvider(getTeensy3Time);
Serial.begin(115200);
while (!Serial); // Wait for Arduino Serial Monitor to open
delay(100);
//if (timeStatus()!= timeSet) {digitalWrite(led, HIGH);//fail
//delay(500);
// digitalWrite(led, LOW);
//}
// else {digitalWrite(led, HIGH);//pass
// delay(500);
// digitalWrite(led, LOW);
// delay(500);
// digitalWrite(led, HIGH);}
//********************************I wouls think that I only need the next line to manualy set the time:
// h m s
setTime(3,22,46,1,2,23);
hourFormat12(); // the hour now in 12 hour format
}
void loop() {
// if (Serial.available()) {
// time_t t = processSyncMessage();
// if (t != 0) {
// Teensy3Clock.set(t); // set the RTC
// setTime(t);
// }
// }
digitalClockDisplay();
delay(100);
}
void digitalClockDisplay() {
// digital clock display of the time
Serial.print(" h: "); Serial.print(hour());
Serial.print(" M: "); Serial.print(minute());
Serial.print(" S: "); Serial.print(second());
// printDigits(minute());
// printDigits(second());
Serial.print(" ");
// Serial.print(day());
// Serial.print(" ");
// Serial.print(month());
// Serial.print(" ");
// Serial.print(year());
Serial.println();
}
time_t getTeensy3Time()
{
return Teensy3Clock.get();
}
/* code to process time sync messages from the serial port
#define TIME_HEADER "T" // Header tag for serial time sync message
unsigned long processSyncMessage() {
unsigned long pctime = 0L;
const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013
if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
return pctime;
if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
pctime = 0L; // return 0 to indicate that the time is not valid
}
}
return pctime;
}
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);
}
*/
the .h file had this:
//void setTime(int hr,int min,int sec,int day, int month, int yr);
so I did this in the setup:
setTime(3,22,46,1,2,23);
hourFormat12();
it does not retain the manually set time.
the code:
/*
* TimeRTC.pde
* example code illustrating Time library with Real Time Clock.
*
*/
//void setTime(int hr,int min,int sec,int day, int month, int yr);
#include <TimeLib.h>
//int led = 13;
void setup() {
// pinMode(led, OUTPUT);
// set the Time library to use Teensy 3.0's RTC to keep time
setSyncProvider(getTeensy3Time);
Serial.begin(115200);
while (!Serial); // Wait for Arduino Serial Monitor to open
delay(100);
//if (timeStatus()!= timeSet) {digitalWrite(led, HIGH);//fail
//delay(500);
// digitalWrite(led, LOW);
//}
// else {digitalWrite(led, HIGH);//pass
// delay(500);
// digitalWrite(led, LOW);
// delay(500);
// digitalWrite(led, HIGH);}
//********************************I wouls think that I only need the next line to manualy set the time:
// h m s
setTime(3,22,46,1,2,23);
hourFormat12(); // the hour now in 12 hour format
}
void loop() {
// if (Serial.available()) {
// time_t t = processSyncMessage();
// if (t != 0) {
// Teensy3Clock.set(t); // set the RTC
// setTime(t);
// }
// }
digitalClockDisplay();
delay(100);
}
void digitalClockDisplay() {
// digital clock display of the time
Serial.print(" h: "); Serial.print(hour());
Serial.print(" M: "); Serial.print(minute());
Serial.print(" S: "); Serial.print(second());
// printDigits(minute());
// printDigits(second());
Serial.print(" ");
// Serial.print(day());
// Serial.print(" ");
// Serial.print(month());
// Serial.print(" ");
// Serial.print(year());
Serial.println();
}
time_t getTeensy3Time()
{
return Teensy3Clock.get();
}
/* code to process time sync messages from the serial port
#define TIME_HEADER "T" // Header tag for serial time sync message
unsigned long processSyncMessage() {
unsigned long pctime = 0L;
const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013
if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
return pctime;
if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
pctime = 0L; // return 0 to indicate that the time is not valid
}
}
return pctime;
}
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);
}
*/