Master Clock MK2    Atomic Time Synchronisation Circuit     Slave Clocks      Calendar Clock Slave         Master Clock         Voltmeter Clock          Guestbook

LCD Master Bracket Clock

This clock is designed to backup my Master Clock should it fail or need maintenance and is portable with battery backup.

This clock uses an Arduino 328 Microprocessor to decode Time from the DCF77 "Atomic" Clock in Mainflingen near Frankfurt Germany.

Time is displayed on a skeleton clock and a Blue 4x20 LCD display. Clock pulses to drive slave dials are monitored on an LED panel.

3 x 1.5volt AA cells provide battery backup when disconnected from the mains.

The main board has a USB to UART connector so the clock software can be updated from a PC or even a Mac.

Serial code is included for monitoring over the USB but is commented out.

Code editing in Windows

The open-source Arduino environment makes it easy to write or edit the code and upload it to the USB board on the back of the clock.

It runs on Windows, Mac OS X, and Linux.

The environment is written in Java and based on Processing, avr-gcc, and other open source software.

The code for this clock can be downloaded at the bottom of this page and can be edited using the Arduino software.

Arduino hardware (board, Microprocessor and all components) can purchased prebuilt ready to work from the Arduino Store or you can purchase the microprocessor

and components separately and build them into your own boards as I have done here.

 

This clock chimes on the quarter hour only with hour chimes sounding from the main Master Clock and Voltmeter Clock. As all the clocks are in sync the hour chime

will start after the quarter chime is completed.

 

 

 

 

Cutaway showing 3x AA standby batteries in the roof of the case.

 

 

The LCD display is from a company called 4tronix

 

The LCD display has the following specs.

  Operating voltage: 5V
  Alphanumeric character set
  4 lines of 20 characters
  Blue Backlight
  Module size: 98 x 60 x12mm
  Display size: 75 x 25mm
  I2C 2-wire connection
  Built-in Contrast Adjustment

 

 

 

On start-up the clock attempts to decode the DCF77 signal and will show the "Waiting DCF77 Sync" screen below.

 

 

Once the signal is decoded the display switches to full time, date and data display.

 

  

 

 

             

The LCD display shows;

Time and Date

Last time the clock sync'd to the DCF77 signal

The sync status

Last time the clock missed a pulse ( and was corrected by adding a pulse)

Number of pulses missed in last 24hrs

Pulse length 100ms = 1, 200ms = 2

Cycle length 1000ms and EOF (end of field) indicator

 

The clock will shutdown the LCD after midnight and will turn back on at 06:00hrs. This can be easily changed if required by editing the code.

 

 

 

 

LED panel shows the slave clock and chime pulses output from the clock.

 

 

 

 

Clock at night

 

I removed the SMD LED from the I2C module and connected a large blue LED to light the inside of the case at night.

 

The skeletal clock is an old quartz unit with the quartz circuit board cut out and wires soldered to the motor terminals.

An alternating 1 second pulse from the Arduino drives the clock.

The skeletal clock seconds including mins and hours hands can be stopped and then stepped on second by second by 2 switches at the back.

The hour and minute hands are set by the standard knob on the rear of the clock.

 

 

Original Latern

The case is a modified BORRBY candle lantern from Ikea.

 

Clock Case Mod

 

 

How to modify the lamp (drawings not to scale)

                                                                       

1

Drill out the welds holding the top to the main frame

2

Remove the top

 

3

Cut out the ventilation grill on the front to make space for the LCD display

4

Cut wood or metal sheet to fill the ventilation grills that remain

 

5

Fill gaps between base and frame with wooden strips.

The base circuit board sits on this wood.

Remove candle spike from base and add four feet.

6

Add a new plywood top and fix with hindges a the back.

A recess will need to be cut in the top to take the top of the

LCD circuit board that protrudes from the base.

 

 

 

7

Add a handle and cut a hole in the base for the cables.

 

 

 

 

 

8

Fix LCD display in cutout

 

 

 

 

 

 

9

Fix Skeleton Clock movement by suspending from top

 

10

Slide in PCB and LED display panel

 

     
     

 

 

 

Short Video clip showing the clock operating and chiming from 23:59:55 to 00:00:32

 

 

 

 

Schematic

The 2 x ULN2803A ICs are remote from the clock and are connected as required depending on slaves. The clock software is updated via the USB to UART

The DCF77 is wired remote from the clock and is powered by a 3.3v DC to Dc converter mounted on the main clock board

 

 

Vero Board layout

The cut out on the right of the board goes to the back of the case and allows cable access

Sockets to all pins and outputs are included to enable feeds to other clocks via transistor drivers in my Master Clock system

 

Sure Electronics Digital record and playback board for sounding the quarter chime.

Hour chime is via my Voltmeter Clock and Longcase clock

 

 

Clock case dimensions

Arduino Site

 

 

Arduino Code

Download the code

Code is set for GMT England see Timezone library for details of how to change zone

Version 5.1 Updated 08/02/2014

// X:\My Documents\Arduino\DCF77 test Brett\DCF77testGMTserialLCD LED sec01
// Moved backliht on off to after "prevdisplay" to it is checked once per sec
// Resets Miss count at 06:10:01 not 23:59:59
// Mod to cycle length
// Version number added on flash screen
// Misscount Tot has leading zero and max count of 99 added
// ***** ALL Serial commands commented out ******************
// Blinkpin 13 for DCF77 pulse monitor on LED 13 commented out
// DCF77 Pulse Master Clock with Chime Brett Oliver 2013
// Note DCF77 time correction will cause pulses to miss if seconds are corrected when they are
// due to pulse. If variable prevDisplay1=1 seconds have stepped on correctly if prevDisplay1=2 seconds
// will have missed 1 second. Example if prevDisplay1 = 2 @ 22:59:59 then 23:00:00 will be missed out and
// any pulses or chimes triggered at this time will be missed. Code below has been corrected for "quartz"
// motor pulse, 30sec pulse and qtr chime only. If pulses or other chimes are critical for other slaves these
// must have code added to take account of DCF77 time correction.
// Note the variable prevDisplay1 will show a value corresponding to the DCF77 correction eg prevDisplay1=3 
// will indicate a 2 second correction. This is quite rare unless DCF77 reception is missing for long periods.
// Added LCD 4-Line 20x4 Alphanumeric LCD Module 2-Wire I2C Interface
// from http://4tronix.co.uk/arduino/I2C_LCD_Module.php
#include <Wire.h>
// I2C library from http://www.4tronix.co.uk/arduino/sketches/LiquidCrystal_V1.2.1.zip
#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#include <DCF77.h>       //https://github.com/thijse/Arduino-Libraries/downloads
#include <Time.h>        //http://www.arduino.cc/playground/Code/Time
#include <Timezone.h>    //https://github.com/JChristensen/Timezone

#define DCF_PIN 2	         // Connection pin to DCF 77 device
#define DCF_INTERRUPT 0		 // Interrupt number associated with pin
//read cycle and pulse length
//#define BLINKPIN 13 // can be used to drive LED D10 instead of IC5 4049b 
#define DCF77PIN 2
//read cycle and pulse length


//**********************
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address


//**********************
//United Kingdom (London, Belfast)
TimeChangeRule rBST = {
  "BST", Last, Sun, Mar, 1, 60};        //British Summer Time
TimeChangeRule rGMT = {
  "GMT", Last, Sun, Oct, 2, 0};         //Standard Time
Timezone UK(rBST, rGMT);
// read cycle and pulse length
int flankUp = 0;
int flankDown = 0;
int PreviousflankUp;
int cycle = 0;
int length = 0;
int lcdTot = 0;
bool Up = false;
// read cycle and pulse length
int misscount = 0;
int hourmiss = 00; // hour last extra pulse variable
int minutemiss = 00; // minute last extra pulse variable
int secondmiss = 00; // second last extra pulse variable
int hoursync = 00; // hour last sync variable
int minutesync = 00; // minute last sync variable
int secondsync = 00; // second last sync variable
int ledStateOdd = HIGH;             // ledState used to set the 1 second LED initial state
int ledStateEven = HIGH;              // ledState used to set the 2nd 1 second LED initial state
int quartzmotor1 = HIGH;              // ledState used to set the quartz motor pin A2 initial state
int quartzmotor2 = LOW;              //  ledState used to set the quartz motor pin A3 initial state

int led = 7; // min pulse
int led30 = 8; // 30 sec pulse
int led05 = 11; // 05 sec pulse
int led10 = 10; // 10 sec pulse
int led15 = 3; // 15 sec pulse
int led20 = 9; // 20 sec pulse
int led01 = 12; // 1 sec pulse
int ledh = 6; // 1 hour pulse
int ledd = 5; // 1 day pulse
int ledQchime = 4; // qtr hour chime pulse
int trigQchime = A0; // qtr hour chime trig pulse
int ledchime =A1;  //  hour chime pulse
int quartz01 =A2;  //  Quartz clock motor pulse 01
int quartz02 =A3;  //  Quartz clock motor pulse 02
time_t prevDisplay = 0;          // when the digital clock was displayed
time_t prevDisplay1 = 0;
time_t time;
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT);

void setup() {
  //read cycle and pulse length
  pinMode(DCF77PIN, INPUT);
 // pinMode(BLINKPIN, OUTPUT);
  //read cycle and pulse length
  // initialize the digital pin as an output.
  lcd.begin(20,4);   // initialize the lcd for 20 chars 4 lines, turn on backlight
  pinMode(led, OUTPUT);
  pinMode(led30, OUTPUT);
  pinMode(led05, OUTPUT);
  pinMode(led10, OUTPUT);
  pinMode(led15, OUTPUT);
  pinMode(led20, OUTPUT);
  pinMode(led01, OUTPUT);
  pinMode(ledh, OUTPUT);
  pinMode(ledd, OUTPUT);
  pinMode(ledQchime, OUTPUT);
  pinMode(trigQchime, OUTPUT);
  pinMode(ledchime, OUTPUT);
  pinMode(quartz01, OUTPUT);
  pinMode(quartz02, OUTPUT);

  Serial.begin(9600); 
  DCF.Start();
  setSyncInterval(30);
  setSyncProvider(getDCFTime);
  // It is also possible to directly use DCF.getTime, but this function gives a bit of feedback
  //setSyncProvider(DCF.getTime);
  digitalWrite(ledQchime, HIGH);
  digitalWrite(trigQchime, HIGH); //Stops chime continualy sounding until DCF77 sync
  //Serial.print(misstot);
  //Serial.println("Waiting for DCF77 UK local time ... ");
  //Serial.println("It will take at least 2 minutes until a first update can be processed.");
  while(timeStatus()== timeNotSet) { 
    // wait until the time is set by the sync provider     
    //Serial.print(".");

    lcd.backlight(); // backlight on
    lcd.setCursor(0,0); //Start at character 0 on line 0
    lcd.print(" DCF77 Master Clock");
    delay(500);
    lcd.setCursor(0,2);
    lcd.print(" Waiting DCF77 Sync "); //Print 20 characters on 3rd line
    delay(200);
    lcd.setCursor(0,1);
    lcd.print("    Brett Oliver    "); //Print 20 characters on 2nd line
    //################# VERSION NUKMBER ######################################################################################
    delay(500);
    lcd.setCursor(0,3);
    lcd.print(" Ver. 51 08/02/2014"); // Print text on 4th Line
       
   //#########################################################################################################################



    delay(500);
    //lcd.setCursor(0,3);
    //lcd.print("Time Status ");
    // lcd.print(timeStatus());
    delay(500);
    lcd.setCursor(0,2);
    lcd.print("                    "); //Print 20 characters on 3rd line
    delay(500);
    lcd.setCursor(0,1);
    lcd.print("    Brett Oliver    "); //Print 20 characters on 2nd line
    delay(500);
    lcd.setCursor(0,3);
    lcd.print("                    "); //Print 20 characters on 4th line

    //******************************* 

    delay(300);

  }
}

void loop()
{  

  //read cycle and pulse length and display on bottom line of LCD
  //as Pulse Length and Cycle
  int sensorValue = digitalRead(DCF77PIN);
  if (sensorValue) {
    if (!Up) {
      flankUp=millis();
      Up = true;
      //digitalWrite(BLINKPIN, HIGH); // can be used to drive LED D10 instead of IC5 4049b
    }
  } 
  else {
    if (Up) {
      flankDown=millis();
      cycle = (flankUp-PreviousflankUp); // cycle length around 1000mSeconds
      lcd.setCursor(0,3);
      lcd.print("Lgth ");
      length = (flankDown - flankUp); // Pulse length 100m Seconds "0" 200m Seconds "1"
      PreviousflankUp = flankUp;
      Up = false;
      //digitalWrite(BLINKPIN, LOW); // can be used to drive LED D10 instead of IC5 4049b

    }              
  } 
  // add leading zero if below 1000 and add EOF indicator
  if (cycle > 1899 && cycle < 2200)
  {
    lcd.setCursor(9,3);
    lcd.print("Cycle ");
    lcd.setCursor(15,3);     
    lcd.print("EOF "); 
  }
  else if (cycle > 999 && cycle < 1900)
  {
    lcd.setCursor(9,3);
    lcd.print("Cycle ");
    lcd.setCursor(15,3);     
    lcd.print(cycle);
  }
  
  else if (cycle > 99 && cycle < 1000)
  {
    lcd.setCursor(9,3);
    lcd.print("Cycle ");
    lcd.setCursor(15,3);
    lcd.print("0");
    lcd.setCursor(16,3);
    lcd.print(cycle);
  }
  
   else if (cycle < 99 && cycle >9)
  {
    lcd.setCursor(9,3);
    lcd.print("Cycle ");
    lcd.setCursor(15,3);
    lcd.print("00");
    lcd.setCursor(17,3);
    lcd.print(cycle);
  }
  
   else if (cycle < 10 && cycle >0)
  {
    lcd.setCursor(9,3);
    lcd.print("Cycle ");
    lcd.setCursor(15,3);
    lcd.print("000");
    lcd.setCursor(18,3);
    lcd.print(cycle);
  }
     else if (cycle > 2199)
  {
    lcd.setCursor(9,3);
    lcd.print("Cycle ");
    lcd.setCursor(15,3);
    lcd.print("XXXX");
   
  }
  // add leading zero if Pulse length if below 99 and greater than 9
  //or add leadng zeroes if pulse below below 10 if over 999 then XXX is printed
  if (length > 99 && length <1000)
  {
    lcd.setCursor(0,3);
    lcd.print("Lgth ");
    lcd.setCursor(5,3);     
    lcd.print(length);
  }
  else if (length < 100 && length > 9 )
  {
    lcd.setCursor(0,3);
    lcd.print("Lgth ");
    lcd.setCursor(5,3);
    lcd.print("0");
    lcd.setCursor(6,3);
    lcd.print(length);

  }
  else if (length < 10 && length > 0)
  {
    lcd.setCursor(0,3);
    lcd.print("Lgth ");
    lcd.setCursor(5,3);
    lcd.print("00");
    lcd.setCursor(7,3);
    lcd.print(length);
  }
  else if (length == 0)
  {
    lcd.setCursor(0,3);
    lcd.print("Lgth ");
    lcd.setCursor(5,3);
    lcd.print("000");
  }
  else if (length > 999)
  {
    lcd.setCursor(0,3);
    lcd.print("Lgth ");
    lcd.setCursor(5,3);
    lcd.print("XXX");
  }

  //end of read cycle and pulse length
  
 

  //***************************
  if( now() != prevDisplay) //update the display only if the time has changed
  {
    prevDisplay1 = now()-prevDisplay; // should =1 if not then extra pulse is required
    prevDisplay = now();
    digitalClockDisplay();
   // Serial.print(" ");
   // Serial.print(prevDisplay1);
   // Serial.print(" ");


  }
}

void digitalClockDisplay(){
   //*************************** LCD backlight and display off after midnight and on from 06:00 hrs

  if (hour() >= 00 && hour() < 06) 

  {
    lcd.noBacklight(); // backlight off
    lcd.noDisplay(); //display off
  }
  else

      lcd.backlight(); // backlight on
  lcd.display(); //display on
  {
  }

  // Quartz clock driver
  // toggle Quartz drive A2 & A3 evey second
  if (quartzmotor1 == LOW)
  { 
    quartzmotor1 = HIGH;
  }
  else
    quartzmotor1 = LOW;
  {
    digitalWrite(quartz01, quartzmotor1); // set the quartz motor drive A2 pin
  }
  if (quartzmotor2 == HIGH)
  { 
    quartzmotor2 = LOW;
  }
  else
    quartzmotor2 = HIGH;
  {
    digitalWrite(quartz02, quartzmotor2); // set the quartz motor drive A3 pin     

  }

  //add extra quartz pulse

  if (prevDisplay1 > 1) // if >1 pulse has been missed so extra quartz pulse is added here
  {

    delay(100);

    if (quartzmotor1 == LOW)
    { 
      quartzmotor1 = HIGH;
    }
    else
      quartzmotor1 = LOW;
    {
      digitalWrite(quartz01, quartzmotor1); // set the quartz motor drive A2 pin
    }
    if (quartzmotor2 == HIGH)
    { 
      quartzmotor2 = LOW;
    }
    else
      quartzmotor2 = HIGH;
    {
      digitalWrite(quartz02, quartzmotor2); // set the quartz motor drive A3 pin     

    }
  }


  // end of add extra quartz pulse

  //#############################
  if (hour()== 6 && minute() == 10 && second() == 01) // resets miss second counter to 0 at 6:10:01
  {
    misscount = 0;
  }

  if (prevDisplay1 > 1) //records time of miss second
  {
    misscount = misscount + 1; //increment Miss count total
    hourmiss = hour();
    minutemiss = minute();
    secondmiss = second();

  }
  // Enable below to analize missed pulses on serial monitor
  //Serial.print(" ");
  //Serial.print("MC");
  //Serial.print(misscount);
  //############################# 
  
 
  // Quarter Chime

  if ((minute() == 15 || minute() == 30 || minute() == 45) && second() == 0)
  {
    digitalWrite(ledQchime, LOW);
  }

  else if ((minute() == 15 || minute() == 30 || minute() == 45) && second() == 59 && prevDisplay1 ==2)
  {
    digitalWrite(ledQchime, LOW);
  }

  else if
    (minute() == 59 && second() == 57) 
  {
    digitalWrite(ledQchime, LOW);
  }

  else if (minute() == 59 && second() == 56 && prevDisplay1 ==2 )
  {
    digitalWrite(ledQchime, LOW);
  }
  else
    digitalWrite(ledQchime, HIGH);





  if ((minute() == 15 || minute() == 30 || minute() == 45) && second() == 0)
  {
    digitalWrite(trigQchime, LOW);
  }

  else if ((minute() == 15 || minute() == 30 || minute() == 45) && second() == 59 && prevDisplay1 ==2)
  {
    digitalWrite(trigQchime, LOW);
  }

  else if
    (minute() == 59 && second() == 57) 
  {
    digitalWrite(trigQchime, LOW);
  }

  else if (minute() == 59 && second() == 56 && prevDisplay1 ==2 )
  {
    digitalWrite(trigQchime, LOW);
  }
  else
    digitalWrite(trigQchime, HIGH);

  //End of Quarter Chime


  // hour Chime
  if (minute() == 0 && (hour() == 1 || hour() == 13) && second() == 0 )
  {
    digitalWrite(ledchime, HIGH);
  }
  else
    if (minute() == 0 && (hour() == 2 || hour() == 14) && (second() == 0 || second() ==2 ))
    {
      digitalWrite(ledchime, HIGH); 
    } 
    else
      if (minute() == 0 && (hour() == 3 || hour() == 15) && (second() == 0 || second() ==2 || second() ==4 ))
      {
        digitalWrite(ledchime, HIGH); 
      } 
      else
        if (minute() == 0 && (hour() == 4 || hour() == 16) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 ))
        {
          digitalWrite(ledchime, HIGH); 
        } 
        else
          if (minute() == 0 && (hour() == 5 || hour() == 17) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 ))
          {
            digitalWrite(ledchime, HIGH);  
          }
          else
            if (minute() == 0 && (hour() == 6 || hour() == 18) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 || second() ==10 ))
            {
              digitalWrite(ledchime, HIGH);
            }
            else
              if (minute() == 0 && (hour() == 7 || hour() == 19) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 || second() ==10 || second() ==12 ))
              {
                digitalWrite(ledchime, HIGH);
              }  
              else
                if (minute() == 0 && (hour() == 8 || hour() == 20) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 || second() ==10 || second() ==12 || second() ==14))
                {
                  digitalWrite(ledchime, HIGH); 
                } 
                else
                  if (minute() == 0 && (hour() == 9 || hour() == 21) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 || second() ==10 || second() ==12 || second() ==14 || second() ==16))
                  {
                    digitalWrite(ledchime, HIGH);
                  }  
                  else
                    if (minute() == 0 && (hour() == 10 || hour() == 22) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 || second() ==10 || second() ==12 || second() ==14 || second() ==16 || second() ==18))
                    {
                      digitalWrite(ledchime, HIGH); 
                    } 
                    else
                      if (minute() == 0 && (hour() == 11 || hour() == 23) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 || second() ==10 || second() ==12 || second() ==14 || second() ==16 || second() ==18 || second() ==20))
                      {
                        digitalWrite(ledchime, HIGH); 
                      } 
                      else
                        if (minute() == 0 && (hour() == 12 || hour() == 0) && (second() == 0 || second() ==2 || second() ==4 || second() ==6 || second() ==8 || second() ==10 || second() ==12 || second() ==14 || second() ==16 || second() ==18 || second() ==20 || second() ==22))
                        {
                          digitalWrite(ledchime, HIGH); 
                        } 
                        else      
                          digitalWrite(ledchime, LOW);
  // end of Hour Chime
  digitalWrite(led01, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(25);
  digitalWrite(led01, LOW);   // turn the LED off (LOW is the voltage level) 

  // digital clock display of the time
  //Serial.println("");
  //Serial.print(hour()); add leading 0 on hour and prob :

  lcd.setCursor(0,0); // set LCD to row 1 pos 1
  //************
 // printDigitsH(hour());
 // printDigits(minute());
 // printDigits(second());
  //Serial.print(" ");
  //Serial.print(day());
  //Serial.print(" ");
  //Serial.print(month());
  //Serial.print(" ");
  //Serial.print(year());
  //Serial.print("      "); // adds space before following


  //~~~~~~~~~~~~~~~~~~
  // printP01(second()); // prints every second
  printPTen(second()); // prints secs ie 0 every 60 secs
  printP30(second()); //  prints 0 or 30  on 0 or 30 secs
  printP05(second()); //  prints every 5 secs
  printP10(second()); //  prints every 10 secs
  printP15(second()); //  prints every 15 secs
  printP20(second()); //  prints every 20 secs
  printPhour(minute()); // print every hour eg when ever mins at 00
  printPday(hour()); // print when hour is 0 eg every 24 hour

   // Serial.println();
  printLCDH(hour()); //adds leadng zero if hour is less than 10
  printLCD(minute()); //adds leadng zero and colon if minute is less than 10
  printLCD(second()); //adds leadng zero and colon if seond is less than 10
  lcd.print(" ");
  printLCDH(day()); // adds leadng zero if day is less than 10
  lcd.print("/");
  printLCDH(month()); // adds leadng zero if month is less than 10
  lcd.print("/");
  lcd.print(year());

  // display last sync time
  lcd.setCursor(0,1);
  lcd.print("Sync ");

  // show last sync time on LCD
  printLCDH(hoursync);
  lcd.print(":");
  printLCDH(minutesync);
  lcd.print(":");
  printLCDH(secondsync);
  lcd.print(" Sta ");
  lcd.print(timeStatus());

  lcd.setCursor(0,2);
  lcd.print("Miss ");
  printLCDH(hourmiss);
  lcd.print(":");
  printLCDH(minutemiss);
  lcd.print(":");
  printLCDH(secondmiss);
  lcd.print(" Tot ");
 // lcd.print(misscount);
  //**********************
   // add leading zero if Misscount Tot below 10 and XX if over 99

  if (misscount > 99)
  {
    lcd.setCursor(18,2);
    lcd.print("XX");
    
  }
  else if (misscount > 9 && misscount < 100)
  {
    lcd.setCursor(18,2);
    lcd.print(misscount);
  
  }
  else if (misscount < 9)
  {
    lcd.setCursor(18,2);
    lcd.print("0");
    lcd.setCursor(19,2);
    lcd.print(misscount);

  }
  
  
  //*********************

//}

//void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0 on mins and secs
  //Serial.print(":");
 // if(digits < 10)
    //Serial.print('0');
  //Serial.print(digits);

}


void printLCD(int LCDdigits){
  // utility function for digital clock display: prints preceding colon and leading 0 on mins and secs
  lcd.print(":");
  if(LCDdigits < 10)
    lcd.print('0');
  lcd.print(LCDdigits); 

}
void printLCDH(int LCDdigitH){
  // utility function for digital clock display: prints leading 0 on hours
  //Serial.print(":");  colon not needed for hours
  if(LCDdigitH < 10)  
    lcd.print("0"); // Print hour on first line
  lcd.print(LCDdigitH);

//}
//void printDigitsH(int digitH){
  // utility function for digital clock display: prints leading 0 on hours
//  if(digitH < 10)
   // Serial.print('0');
 // Serial.print(digitH);

}

void printPTen(int PTen){ // light LED every min on 00

  if(PTen == 00)
  {
   // Serial.print(PTen);
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)

  }
  else if(PTen != 00)

    digitalWrite(led, LOW);   // turn the LED off (LOW is the voltage level)

}


void printP30(int P30){ // light LED every 30 seconds

  if(P30 == 00 || P30 == 30)
  {
   // Serial.print(P30);
    digitalWrite(led30, HIGH);   // turn the LED on (HIGH is the voltage level)

  }
  else if(P30 != 00 || P30 !=30)

    digitalWrite(led30, LOW);   // turn the LED off (LOW is the voltage level)

  else if(P30 == 59 || P30 == 29 && prevDisplay1==2)// makes sure clock pulses 30 sec pulse if DCF77 time corrects @ 59 or 29 sec

  {

    //Serial.print(P30);
    digitalWrite(led30, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
  else if(P30 != 59 || P30 !=29 && prevDisplay1==2) //// makes sure clock pulses turn off 30 sec pulse if DCF77 time corrects @ 59 or 29 sec

    digitalWrite(led30, LOW);   // turn the LED off (LOW is the voltage level)




}
void printP05(int P05){ // light LED 10 every 5 seconds

  if(P05 == 00 || P05 == 05 || P05 == 10 || P05 == 15 || P05 == 20 || P05 == 25 || P05 == 30 || P05 == 35 || P05 == 40 || P05 == 45 || P05 == 50 || P05 == 55)
  {
    //Serial.print(P05);
    digitalWrite(led05, HIGH);   // turn the LED on (HIGH is the voltage level)

  }
  else if(P05 != 00 || P05 !=05 || P05 !=10 || P05 !=15 || P05 !=20 || P05 !=25 || P05 !=30 || P05 !=35 || P05 !=40 || P05 !=45 || P05 !=50 || P05 !=55)

    digitalWrite(led05, LOW);   // turn the LED off (LOW is the voltage level)


}

void printP10(int P10){ // light LED 09 every 10 seconds

  if(P10 == 00 || P10 == 10 || P10 == 20 || P10 == 30 || P10 == 40 || P10 == 50)
  {
    //Serial.print(P10);
    digitalWrite(led10, HIGH);   // turn the LED on (HIGH is the voltage level)
     }
  else if(P10 != 00 || P10 !=10 || P10 !=20 || P10 !=30 || P10 !=40 || P10 !=50)

    digitalWrite(led10, LOW);   // turn the LED off (LOW is the voltage level)

}

void printP15(int P15){ // light LED 03 every 15 seconds

  if(P15 == 00 || P15 == 15 || P15 == 30 || P15 == 45)
  {
   // Serial.print(P15);
    digitalWrite(led15, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
  else if(P15 != 00 || P15 !=15 || P15 !=30 || P15 !=45)

    digitalWrite(led15, LOW);   // turn the LED off (LOW is the voltage level)

}

void printP20(int P20){ // light LED 08 every 20 seconds

  if(P20 == 00 || P20 == 20 || P20 == 40)
  {
   // Serial.print(P20);
    digitalWrite(led20, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
  else if(P20 != 00 || P20 !=20 || P20 !=40)

    digitalWrite(led20, LOW);   // turn the LED off (LOW is the voltage level)
}


void printPhour(int Phour){ // light LED every hour on 00

  if(Phour == 00 && second() == 00)
  {
   // Serial.print(Phour);
    digitalWrite(ledh, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
  else if(second() != 00) // turn off hour pulse when secs are not 00

      digitalWrite(ledh, LOW);   // turn the LED off (LOW is the voltage level)

}
void printPday(int Pday){ // light LED every day on 00

  if(Pday == 00 && second() == 00)
  {
    //Serial.print(Pday);
    digitalWrite(ledd, HIGH);   // turn the LED on (HIGH is the voltage level)
  }
  else if(second() != 00) //turn off day pulse when secs are not 00

      digitalWrite(ledd, LOW);   // turn the LED off (LOW is the voltage level)


}



unsigned long getDCFTime()
{ 
  time_t DCFtime = DCF.getUTCTime(); // Get  UTC time

    if (DCFtime!=0) 
  {
    time_t LocalTime = UK.toLocal(DCFtime); // Convert to UK time
   // Serial.print("Syncronized  ");
    // when sycn'd show this time as time synch'd
    hoursync = hour();
    minutesync = minute();
    secondsync = second();


    return LocalTime;

  }
  return 0;
}