The Planted Tank Forum - View Single Post - Guide: Arduino based LED controller for Current Satellite LED+
View Single Post
Old 08-31-2013, 04:34 AM   #344
Dahammer
Algae Grower
 
PTrader: (0/0%)
Join Date: Oct 2010
Location: Mississippi
Posts: 118
Default

Here is the debug code I used. If you want to try it replace the loop() & syncprovider() functions with the ones below and add cseconds and pseconds to the global variables at the top somewhere.
Code:
unsigned int cseconds = 0;
unsigned int pseconds = 0;

void loop()
{
  cseconds = millis() / 1000;
  if (Serial.available() > 0) {
    delay(5); //Wait for transmission to finish
    TestCodes(SerialReadInt());  // Go grab IR code and send it
  }
  Alarm.delay(100);   // Service alarms & wait (msec)
  lcd.setCursor(0,0);
  fprintf(&lcdout, "%02d:%02d", hour(), minute());  // Print the time HH:MM to the lcd
  if (cseconds - pseconds >= 60)
  {
    printf("Arduino Time: %02d:%02d:%02d\n", hour(), minute(), second());
    pseconds = cseconds;
  }
}

time_t syncProvider()
{
  printf("Arduino sync'ed to RTC: %02d:%02d:%02d\n", RTC.now().hour(), RTC.now().minute(), RTC.now().second());
  return RTC.now().unixtime();
}
Calling hour() or minute() inside syncProvider() locks the Arduino up, so I moved the Arduino time to loop() and did a counter to display it every minute.
Dahammer is offline   Reply With Quote