LCD clock + serial export.

I have been off programming my clock… not much improvement,but I have got a few “wall warts” and they are good for powering the board.

Now… I was wondering if someone could take my code and show me how to make the input easier (As in i don’t have to get unix code to input it) and make the clock start with a variable that was already in the code until I have to fix it (so i can use the wall warts and it still have something showing).

#include <Time.h>  
#include <LiquidCrystal.h>// for the lcd

#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message this is why i put a T infront of the UNIX time
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message 

#define backlight 'on' // no caps
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);// I use those pins to keep it orderly...

void setup()  {
  Serial.begin(9600);// for serial comm
 // setSyncProvider( requestSync);  //set function to call when sync required
  Serial.println("Waiting for sync message");
  lcd.begin(16,2);
  lcd.print("Enter Time");// request the time
}


void loop(){    
  
//  if(Serial.available() ) 
//  {
//    processSyncMessage();// if you type something into serial check and see if it looks like a time value
//  }

  if(timeStatus()!= timeNotSet)   // if you get the time SET THE CLOCKS!! lol
  {


   digitalClockDisplay(); 
  if (backlight == 'on'){
    digitalWrite(13,HIGH);}
    
    if (backlight == 'off'){
      digitalWrite(13,LOW);}
    
  }
  
/*    delay(500);
    timeStatus()== timeSet; // old experement...
    Serial.print(timeStatus());
    if (timeStatus() == 0){
      
   digitalWrite(13,HIGH); // on if synced, off if needs refresh  
    }
   if (timeStatus() == 2 ){
     digitalWrite(13,LOW);}*/


}


void digitalClockDisplay(){
  
lcd.setCursor(8 ,0); // all of this is just what to tell the lcd to do and print the time...
int noob = hour();
if (isAM()){
lcd.print("EST A.M."); 


delay(500);
if (isPM()){
lcd.print("EST P.M.");// I used the wrong time to make it my time (EST)

noob = hour()- 12;}
  // digital clock display of the time
  printDigits(noob);
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
    lcd.setCursor(0,0);

lcd.print(noob);
lcd.print(":"); 
lcd.print(minute());
lcd.print(":");
lcd.print(second());
lcd.print(" ");
delay(1);
lcd.setCursor(0,1);
lcd.print(month());
lcd.print("-");
lcd.print(day());
lcd.print("-");
lcd.print(year());



  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);
}

void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
    char c = Serial.read() ; 
    Serial.print(c);  
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();          
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number    
        }
      }   
      setTime(pctime);   // Sync Arduino clock to the time received on the serial port
    }  
  }

}

time_t requestSync()
{
  Serial.print(TIME_REQUEST,BYTE);  
  return 0; // the time will be sent later in response to serial mesg
}

Please help me with this

Now... I was wondering if someone could take my code and show me how to make the input easier (As in i don't have to get unix code to input it) and make the clock start with a variable that was already in the code until I have to fix it (so i can use the wall warts and it still have something showing).

I don't understand the question. If you don't have some kind of Real Time Clock, or access to a PC that does, powering off the Arduino is going to stop the clock regardless of whether you store something in persistent memory (EEPROM) or not.

No code change is going to make a clock out of nothing.

I am wanting to completely redo that code so when I am programming I can save time in variables and then plug it up near that time and instead of asking for the serial it just goes by that time,but if serial starts change to that time...

So you want it to always say "5:00 PM" when it starts up until you send it a Serial message?

Is there anything wrong with just calling the "setTime" function from setup() with a constant value?

If you want to add two "up/down" buttons to your project, you could also (easily) set the time without the Serial connection.

I am hoping to get some buttons... i have two but I will have to do some serious work to get some new parts... I will get some new wire (I have to use jumpers for EVERYTHING) and have almost nothing in my toolbox so it will be a while before i get super serious. I would just like it to have a variable int time = 125959 and it would be set in HHMMSS form and as you said would function off of that time until supplied with a new number via serial...