/* functions associated with the RTC */ /************************************************ only needed to default set the time ************************************************/ void set_default_time(tmElements_t tm){ Serial.println("Setting default time"); // create a bogus time and date tm.Hour = 20; tm.Minute = 45; tm.Second = 0; tm.Day = 3; tm.Month = 9; tm.Year = 2016; RTC.write(tm); } /************************************************ returns true if it is am ************************************************/ bool is_am() { int hour, minute, second; bool ret_val; if (RTC.read(tm)) { // time can be read hour = tm.Hour; if (hour >= 12) { hour -= 12; ret_val = false; //Set am as yellow } else { ret_val = true; } } return ret_val; } /************************************************ update time ************************************************/ bool update_time() { int hour, minute, second; bool ret_val = false; if (RTC.read(tm)) { // time can be read hour = tm.Hour; if (hour > 12) { hour -= 12; AM = true ; //Set am as yellow } else { AM = false; } minute = tm.Minute; second = tm.Second; Serial.print(hour); Serial.print(":"); Serial.print(minute); Serial.print(":"); Serial.print(second); Serial.println(); analogWrite(HOURS_PIN, hour * (255 / 11)); analogWrite(MINUTES_PIN, minute * (255 / 59)); analogWrite(SECONDS_PIN, second * (255 / 59)); } else { // chip is there, but time can't be read, set it to default if (RTC.chipPresent()) { Serial.println("Chip found but time not set"); set_default_time(tm); ret_val = true; } else { // we are hosed Serial.println("DS1307 read error! Please check the circuitry."); Serial.println(); ret_val = true; } delay(1000); // wait 9 seconds and try again } return ret_val; }