Westminster chime part of code

I have already made a 7 segment display clock using Arduino uno, but now I want to add hourly chime on it that I found in Arduino forum, but now I cannot decide which part of this code for hourly chime... can author of this code or anybody guide me?

https://forum.arduino.cc/t/ds3231-calendar-clock-with-hourly-chime/979069

Maybe this comment gives a clue

// play the Westminster Chimes

i have used "// play the Westminster chimes" code and put it in my code but fail to compile....

/*
 4 digit 7 segment display: http://www.sparkfun.com/products/9483
 Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf
  */
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf
// Code modified by BMIAK Basnayaka
// http://www.setnfix.com

int digit1 = 12; 
int digit2 = 11;
int digit3 = 10; 
int digit4 = 9;
const byte SPEAKER_PIN = 7;
//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = 0; //Display pin 0
int segB = 1; //Display pin 1
int segC = 2; //Display pin 2
int segD = 3; //Display pin 3
int segE = 4; //Display pin 4
int segF = 5; //Display pin 5
int segG = 6; //Display pin 6
int segDP =13; // Display pin 13



#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
// add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm



byte SW0 = A0;
byte SW1 = A2;
byte SW2 = A1;
byte SWT = A3;
int Adhr=0;
int Admnt=0;
int D = 0;
int Z =0;

// use for hexa in zecimal conversion
long zh, uh, ore;
long zm, um, miniti;

void setup() {
  
 //Serial.begin(57600);
  Wire.begin();
  RTC.begin();
 // RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
// if you need set clock... just remove // from line above this

// part code for flashing LED
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
// Wire.write(0x00); // turns the SQW pin off
 Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz
// Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz

Wire.endTransmission();
  
  
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(SPEAKER_PIN, OUTPUT);


//Serial.begin(9600);

pinMode(SW0, INPUT);  // N.O. push button switch
pinMode(SW1, INPUT);  // N.O. push button switch
pinMode(SW2, INPUT);  // N.O. push button switch
pinMode(SWT, INPUT);  // N.O. push button switch

digitalWrite(SW0, HIGH); // pull-ups on
digitalWrite(SW1, HIGH);
digitalWrite(SW2, HIGH);
digitalWrite(segDP, LOW);


}


void loop() {

  DateTime now = RTC.now();
  long HR = now.hour()*1000;
  long timp = (HR*10)+now.minute()*100+now.second();
  Adhr = now.hour();
  Admnt=now.minute();



int DIM = 0;
if (timp >=250000)
timp=timp-240000;
//------------------------------------------------------
//12/24 hours shitching 
//------------------------------------------------------
if (timp < 130000){
digitalWrite(segDP, LOW);}


if (digitalRead(SWT)==0){delay(300);
 if (D == 0) {
 D =1;delay(200);}
 
else{
D =0;}
}




if (D == 0){  
if (timp>=130000){
timp=timp-120000;
digitalWrite(segDP, HIGH);}
}

if (timp>=130000){ 
digitalWrite(segDP, LOW);
}

if ((D==1)& (timp <130000))
digitalWrite(segDP, LOW);





//------------------------------------------------------


  



//int timp = (now.minute(), DEC);
//   displayNumber(12); // this is number to diplay


     
    for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber01(timp); 
     else displayNumber02(timp); 
   } 

   for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber03(timp); 
     else displayNumber04(timp); 
   } 

   for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber05(timp); 
     else displayNumber06(timp); 
   } 


  

if (digitalRead(SW0)==0){delay(100);Z=1;  set_time(); }// hold the switch to set time
}



if (halfSec != old_halfSec) { // do this only once every half-second
        // see if it is time for the clock to strike
        if (mi == 0) {  // strike on the hour, i.e. when minutes are 0
          if (halfSec < 26) {
            // play the Westminster Chimes
            switch (halfSec) {
              case 0:  tone(SPEAKER_PIN, 330, 420); break;
              case 1:  tone(SPEAKER_PIN, 415, 420); break;
              case 2:  tone(SPEAKER_PIN, 370, 420); break;
              case 3:  tone(SPEAKER_PIN, 247, 735); break;
              case 6:  tone(SPEAKER_PIN, 330, 420); break;
              case 7:  tone(SPEAKER_PIN, 370, 420); break;
              case 8:  tone(SPEAKER_PIN, 415, 420); break;
              case 9:  tone(SPEAKER_PIN, 330, 735); break;
              case 12: tone(SPEAKER_PIN, 415, 420); break;
              case 13: tone(SPEAKER_PIN, 330, 420); break;
              case 14: tone(SPEAKER_PIN, 370, 420); break;
              case 15: tone(SPEAKER_PIN, 247, 735); break;
              case 18: tone(SPEAKER_PIN, 247, 420); break;
              case 19: tone(SPEAKER_PIN, 370, 420); break;
              case 20: tone(SPEAKER_PIN, 415, 420); break;
              case 21: tone(SPEAKER_PIN, 330, 735); break;
              default: break;
            }
          }
          else if ((halfSec < (26 + 3 * hhTwelve)) && ((halfSec % 3) == 2)) {
            // bong the hours
            tone(SPEAKER_PIN, 415, 750);
          }
        }
     



void set_time()   {
  byte minutes1 = 0;
  byte hours1 = 0;
  byte minutes = 0;
  byte hours = 0;
  hours=Adhr;
  minutes=Admnt;


    if ((hours & 0x0f) > 9) hours =  hours + 6;
      if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
        //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
        if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      if (minutes > 0x59) minutes = 0;
      
while (!(Z==0)){ // set time switch must be released to exit


 


    
   int TST = digitalRead(SW2);
    while (TST==0) // set hours
    { 
     hours++;          
     
   // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 
    
   
   
      
      if ((hours & 0x0f) > 9) hours =  hours + 6;
            if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
        //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
        if (hours <= 9) 
    delay(1);
    
      for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }
    
    TST = digitalRead(SW2);
    }

   while (!(digitalRead(SW1))) // set minutes
    { 
     minutes++;  
   // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 
    
     for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }

      if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      if (minutes > 0x59) minutes = 0;
      if (minutes >= 9) 
    delay(1);    
    }

    Wire.beginTransmission(0x68); // activate DS1307
    Wire.write(0); // where to begin
    Wire.write(0x00);          //seconds
    Wire.write(minutes);          //minutes
    Wire.write(0x80 | hours);    //hours (24hr time)
    Wire.write(0x06);  // Day 01-07
    Wire.write(0x01);  // Date 0-31
    Wire.write(0x05);  // month 0-12
    Wire.write(0x09);  // Year 00-99
    Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7. 
    Wire.endTransmission();
  
    // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 

 
    
    for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }
delay(100); 
//Serial.print(digitalRead(SW0));
if (digitalRead(SW0)==0) Z = 0;
 delay(300);   
  }
//Serial.print(SW2);
}


      


void displayNumber01(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
   
      
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 


     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber02(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     lightNumber(10); 
     
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
     
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber03(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
    
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber04(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     lightNumber(10); 
     
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
    
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber05(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
   
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber06(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     //digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
    
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
   
}
} 
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

//Common Anode *************************
#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW


  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  // all segment are ON
  case 10:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  
  }
// End of the coding, BUDHUSARANAI, Best of luck.
  
}

Thanks for using code tags!

Please post your code again, but click "Tools->auto format" before. Do this every time before you post code on the forum. Auto format does not change how your code works, or fix your code, but it makes it easier to read and to spot errors in the code.

Also please post the error messages you see when you compile the code. Click the link above the error window to copy the complete set of messages, then paste them between code tags in your post (but in separate code tags from the code!).

Incomplete code. Missing: mi, min, hhTwelve, halfSec, old_halfSec, close brace before void set_time()...

The sketch in the link (your post #1) DOES have mi, hhTwelve, old_halfSec, and it compiles.

message shows when I tried to compile is : 'displayNumber01' was not declared in this scope

i add this things before void setup but same problem occurred, error message shows :'displayNumber01' was not declared in this scope
my updated code is here

/*
 4 digit 7 segment display: http://www.sparkfun.com/products/9483
 Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf
  */
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf
// Code modified by BMIAK Basnayaka
// http://www.setnfix.com

int digit1 = 12; 
int digit2 = 11;
int digit3 = 10; 
int digit4 = 9;
const byte SPEAKER_PIN = 8;

//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = 0; //Display pin 0
int segB = 1; //Display pin 1
int segC = 2; //Display pin 2
int segD = 3; //Display pin 3
int segE = 4; //Display pin 4
int segF = 5; //Display pin 5
int segG = 6; //Display pin 6
int segDP =13; // Display pin 13


#include "Wire.h"

#include "RTClib.h"
RTC_DS1307 RTC;

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
// add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm

byte yy=0, mo=1, dd=0, wd=6;
byte hh=0, mi=0, ss=0;
byte hhTwelve = 12;
byte wn=52;

// other helpful variables
bool gotTheTime = false;
byte old_ss = 99, halfSec = 198, old_halfSec = 198;
unsigned long microsNow = 0UL;
unsigned long microsAtLastSecond = 0UL;
bool dstOn = false, old_dstOn = false;


byte SW0 = A0;
byte SW1 = A2;
byte SW2 = A1;
byte SWT = A3;
int Adhr=0;
int Admnt=0;
int D = 0;
int Z =0;

// use for hexa in zecimal conversion
long zh, uh, ore;
long zm, um, miniti;

void setup() {
  
 //Serial.begin(57600);
  
  
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(SPEAKER_PIN, OUTPUT);


//Serial.begin(9600);

pinMode(SW0, INPUT);  // N.O. push button switch
pinMode(SW1, INPUT);  // N.O. push button switch
pinMode(SW2, INPUT);  // N.O. push button switch
pinMode(SWT, INPUT);  // N.O. push button switch

digitalWrite(SW0, HIGH); // pull-ups on
digitalWrite(SW1, HIGH);
digitalWrite(SW2, HIGH);
digitalWrite(segDP, LOW);


}


void loop() {
Wire.begin();
   Wire.beginTransmission(0x68); // 0x68 is DS3231 device address
  Wire.write((byte)0); // start at register 0
  Wire.endTransmission();
  Wire.requestFrom(0x68, 7); // request seven bytes
 
  gotTheTime = false;
  while(Wire.available())
  {
  gotTheTime = true;
  }
  microsNow = micros();
 // try to figure out which half-second we are in
  // (this is important to making the striking work properly)
  if (ss != old_ss) microsAtLastSecond = microsNow;
  halfSec = ss * 2;
  if ((microsNow - microsAtLastSecond) >= 500000UL) halfSec++;


 if (gotTheTime) {
    // only if we have successfully read the time
    // do we then attempt to indicate the time
    
    if (halfSec != old_halfSec) { // do this only once every half-second
      // see if it is time for the clock to strike
      if (mi == 0) {  // strike on the hour, i.e. when minutes are 0
        if (halfSec < 26) {
          // play the Westminster Chimes
          switch (halfSec) {
            case 0:  tone(SPEAKER_PIN, 330, 420); break;
            case 1:  tone(SPEAKER_PIN, 415, 420); break;
            case 2:  tone(SPEAKER_PIN, 370, 420); break;
            case 3:  tone(SPEAKER_PIN, 247, 735); break;
            case 6:  tone(SPEAKER_PIN, 330, 420); break;
            case 7:  tone(SPEAKER_PIN, 370, 420); break;
            case 8:  tone(SPEAKER_PIN, 415, 420); break;
            case 9:  tone(SPEAKER_PIN, 330, 735); break;
            case 12: tone(SPEAKER_PIN, 415, 420); break;
            case 13: tone(SPEAKER_PIN, 330, 420); break;
            case 14: tone(SPEAKER_PIN, 370, 420); break;
            case 15: tone(SPEAKER_PIN, 247, 735); break;
            case 18: tone(SPEAKER_PIN, 247, 420); break;
            case 19: tone(SPEAKER_PIN, 370, 420); break;
            case 20: tone(SPEAKER_PIN, 415, 420); break;
            case 21: tone(SPEAKER_PIN, 330, 735); break;
            default: break;
          }
        }
        else if ((halfSec < (26 + 3 * hhTwelve)) && ((halfSec % 3) == 2)) {
          // bong the hours
          tone(SPEAKER_PIN, 415, 750);
        }
      }
    }
     if ((ss != old_ss) || (dstOn != old_dstOn)) { // only once every second
      // update the display to show the current date and time
  
  DateTime now = RTC.now();
  long HR = now.hour()*1000;
  long timp = (HR*10)+now.minute()*100+now.second();
  Adhr = now.hour();
  Admnt=now.minute();



int DIM = 0;
if (timp >=250000)
timp=timp-240000;
//------------------------------------------------------
//12/24 hours shitching 
//------------------------------------------------------
if (timp < 130000){
digitalWrite(segDP, LOW);}


if (digitalRead(SWT)==0){delay(300);
 if (D == 0) {
 D =1;delay(200);}
 
else{
D =0;}
}




if (D == 0){  
if (timp>=130000){
timp=timp-120000;
digitalWrite(segDP, HIGH);}
}

if (timp>=130000){ 
digitalWrite(segDP, LOW);
}

if ((D==1)& (timp <130000))
digitalWrite(segDP, LOW);





//------------------------------------------------------


  



//int timp = (now.minute(), DEC);
//   displayNumber(12); // this is number to diplay


     
    for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber01(timp); 
     else displayNumber02(timp); 
   } 

   for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber03(timp); 
     else displayNumber04(timp); 
   } 

   for(int i = 100 ; i >0  ; i--) {
     if (timp >= 100000) displayNumber05(timp); 
     else displayNumber06(timp); 
   } 


  

if (digitalRead(SW0)==0){delay(100);Z=1;  set_time(); }// hold the switch to set time
}

void set_time()   {
  byte minutes1 = 0;
  byte hours1 = 0;
  byte minutes = 0;
  byte hours = 0;
  hours=Adhr;
  minutes=Admnt;


    if ((hours & 0x0f) > 9) hours =  hours + 6;
      if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
        //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
        if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      if (minutes > 0x59) minutes = 0;
      
while (!(Z==0)){ // set time switch must be released to exit


 


    
   int TST = digitalRead(SW2);
    while (TST==0) // set hours
    { 
     hours++;          
     
   // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 
    
   
   
      
      if ((hours & 0x0f) > 9) hours =  hours + 6;
            if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
        //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
        if (hours <= 9) 
    delay(1);
    
      for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }
    
    TST = digitalRead(SW2);
    }

   while (!(digitalRead(SW1))) // set minutes
    { 
     minutes++;  
   // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 
    
     for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }

      if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      if (minutes > 0x59) minutes = 0;
      if (minutes >= 9) 
    delay(1);    
    }

    Wire.beginTransmission(0x68); // activate DS1307
    Wire.write(0); // where to begin
    Wire.write(0x00);          //seconds
    Wire.write(minutes);          //minutes
    Wire.write(0x80 | hours);    //hours (24hr time)
    Wire.write(0x06);  // Day 01-07
    Wire.write(0x01);  // Date 0-31
    Wire.write(0x05);  // month 0-12
    Wire.write(0x09);  // Year 00-99
    Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7. 
    Wire.endTransmission();
  
    // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh; 
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um; 

 
    
    for(int i = 400 ; i >0  ; i--) {
     displayNumber01(ore*10000+miniti*100); 
     }
delay(100); 
//Serial.print(digitalRead(SW0));
if (digitalRead(SW0)==0) Z = 0;
 delay(300);   
  }
//Serial.print(SW2);
}



void displayNumber01(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
   
      
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 


     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber02(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     lightNumber(10); 
     
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      //digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
     
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber03(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
    
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber04(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     lightNumber(10); 
     
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
    
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber05(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
   
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
} 

void displayNumber06(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for(int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     //digitalWrite(digit1, DIGIT_ON);
     
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      
      break;
    
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
   
}
} 
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

//Common Anode *************************
#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW


  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  // all segment are ON
  case 10:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  
  }
// End of the coding, BUDHUSARANAI, Best of luck.
  
}

You have not done as I asked. I cannot help you. Good luck.

ok i got how to auto format, here is the code with auto format

/*
  4 digit 7 segment display: http://www.sparkfun.com/products/9483
  Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf
*/
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf
// Code modified by BMIAK Basnayaka
// http://www.setnfix.com

int digit1 = 12;
int digit2 = 11;
int digit3 = 10;
int digit4 = 9;
const byte SPEAKER_PIN = 8;

//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = 0; //Display pin 0
int segB = 1; //Display pin 1
int segC = 2; //Display pin 2
int segD = 3; //Display pin 3
int segE = 4; //Display pin 4
int segF = 5; //Display pin 5
int segG = 6; //Display pin 6
int segDP = 13; // Display pin 13


#include "Wire.h"

#include "RTClib.h"
RTC_DS1307 RTC;

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
// add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm

byte yy = 0, mo = 1, dd = 0, wd = 6;
byte hh = 0, mi = 0, ss = 0;
byte hhTwelve = 12;
byte wn = 52;

// other helpful variables
bool gotTheTime = false;
byte old_ss = 99, halfSec = 198, old_halfSec = 198;
unsigned long microsNow = 0UL;
unsigned long microsAtLastSecond = 0UL;
bool dstOn = false, old_dstOn = false;


byte SW0 = A0;
byte SW1 = A2;
byte SW2 = A1;
byte SWT = A3;
int Adhr = 0;
int Admnt = 0;
int D = 0;
int Z = 0;

// use for hexa in zecimal conversion
long zh, uh, ore;
long zm, um, miniti;

void setup() {

  //Serial.begin(57600);


  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(SPEAKER_PIN, OUTPUT);


  //Serial.begin(9600);

  pinMode(SW0, INPUT);  // N.O. push button switch
  pinMode(SW1, INPUT);  // N.O. push button switch
  pinMode(SW2, INPUT);  // N.O. push button switch
  pinMode(SWT, INPUT);  // N.O. push button switch

  digitalWrite(SW0, HIGH); // pull-ups on
  digitalWrite(SW1, HIGH);
  digitalWrite(SW2, HIGH);
  digitalWrite(segDP, LOW);


}


void loop() {
  Wire.begin();
  Wire.beginTransmission(0x68); // 0x68 is DS3231 device address
  Wire.write((byte)0); // start at register 0
  Wire.endTransmission();
  Wire.requestFrom(0x68, 7); // request seven bytes

  gotTheTime = false;
  while (Wire.available())
  {
    gotTheTime = true;
  }
  microsNow = micros();
  // try to figure out which half-second we are in
  // (this is important to making the striking work properly)
  if (ss != old_ss) microsAtLastSecond = microsNow;
  halfSec = ss * 2;
  if ((microsNow - microsAtLastSecond) >= 500000UL) halfSec++;


  if (gotTheTime) {
    // only if we have successfully read the time
    // do we then attempt to indicate the time

    if (halfSec != old_halfSec) { // do this only once every half-second
      // see if it is time for the clock to strike
      if (mi == 0) {  // strike on the hour, i.e. when minutes are 0
        if (halfSec < 26) {
          // play the Westminster Chimes
          switch (halfSec) {
            case 0:  tone(SPEAKER_PIN, 330, 420); break;
            case 1:  tone(SPEAKER_PIN, 415, 420); break;
            case 2:  tone(SPEAKER_PIN, 370, 420); break;
            case 3:  tone(SPEAKER_PIN, 247, 735); break;
            case 6:  tone(SPEAKER_PIN, 330, 420); break;
            case 7:  tone(SPEAKER_PIN, 370, 420); break;
            case 8:  tone(SPEAKER_PIN, 415, 420); break;
            case 9:  tone(SPEAKER_PIN, 330, 735); break;
            case 12: tone(SPEAKER_PIN, 415, 420); break;
            case 13: tone(SPEAKER_PIN, 330, 420); break;
            case 14: tone(SPEAKER_PIN, 370, 420); break;
            case 15: tone(SPEAKER_PIN, 247, 735); break;
            case 18: tone(SPEAKER_PIN, 247, 420); break;
            case 19: tone(SPEAKER_PIN, 370, 420); break;
            case 20: tone(SPEAKER_PIN, 415, 420); break;
            case 21: tone(SPEAKER_PIN, 330, 735); break;
            default: break;
          }
        }
        else if ((halfSec < (26 + 3 * hhTwelve)) && ((halfSec % 3) == 2)) {
          // bong the hours
          tone(SPEAKER_PIN, 415, 750);
        }
      }
    }
    if ((ss != old_ss) || (dstOn != old_dstOn)) { // only once every second
      // update the display to show the current date and time

      DateTime now = RTC.now();
      long HR = now.hour() * 1000;
      long timp = (HR * 10) + now.minute() * 100 + now.second();
      Adhr = now.hour();
      Admnt = now.minute();



      int DIM = 0;
      if (timp >= 250000)
        timp = timp - 240000;
      //------------------------------------------------------
      //12/24 hours shitching
      //------------------------------------------------------
      if (timp < 130000) {
        digitalWrite(segDP, LOW);
      }


      if (digitalRead(SWT) == 0) {
        delay(300);
        if (D == 0) {
          D = 1; delay(200);
        }

        else {
          D = 0;
        }
      }




      if (D == 0) {
        if (timp >= 130000) {
          timp = timp - 120000;
          digitalWrite(segDP, HIGH);
        }
      }

      if (timp >= 130000) {
        digitalWrite(segDP, LOW);
      }

      if ((D == 1) & (timp < 130000))
        digitalWrite(segDP, LOW);





      //------------------------------------------------------






      //int timp = (now.minute(), DEC);
      //   displayNumber(12); // this is number to diplay



      for (int i = 100 ; i > 0  ; i--) {
        if (timp >= 100000) displayNumber01(timp);
        else displayNumber02(timp);
      }

      for (int i = 100 ; i > 0  ; i--) {
        if (timp >= 100000) displayNumber03(timp);
        else displayNumber04(timp);
      }

      for (int i = 100 ; i > 0  ; i--) {
        if (timp >= 100000) displayNumber05(timp);
        else displayNumber06(timp);
      }




      if (digitalRead(SW0) == 0) {
        delay(100);  // hold the switch to set time
        Z = 1;
        set_time();
      }
    }

    void set_time()   {
      byte minutes1 = 0;
      byte hours1 = 0;
      byte minutes = 0;
      byte hours = 0;
      hours = Adhr;
      minutes = Admnt;


      if ((hours & 0x0f) > 9) hours =  hours + 6;
      if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
      //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
      if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      if (minutes > 0x59) minutes = 0;

      while (!(Z == 0)) { // set time switch must be released to exit






        int TST = digitalRead(SW2);
        while (TST == 0) // set hours
        {
          hours++;

          // converting hexa in zecimal:
          zh = hours / 16;
          uh = hours - 16 * zh ;
          ore = 10 * zh + uh;
          zm = minutes / 16;
          um = minutes - 16 * zm ;
          miniti = 10 * zm + um;




          if ((hours & 0x0f) > 9) hours =  hours + 6;
          if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
          //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
          if (hours <= 9)
            delay(1);

          for (int i = 400 ; i > 0  ; i--) {
            displayNumber01(ore * 10000 + miniti * 100);
          }

          TST = digitalRead(SW2);
        }

        while (!(digitalRead(SW1))) // set minutes
        {
          minutes++;
          // converting hexa in zecimal:
          zh = hours / 16;
          uh = hours - 16 * zh ;
          ore = 10 * zh + uh;
          zm = minutes / 16;
          um = minutes - 16 * zm ;
          miniti = 10 * zm + um;

          for (int i = 400 ; i > 0  ; i--) {
            displayNumber01(ore * 10000 + miniti * 100);
          }

          if ((minutes & 0x0f) > 9) minutes = minutes + 6;
          if (minutes > 0x59) minutes = 0;
          if (minutes >= 9)
            delay(1);
        }

        Wire.beginTransmission(0x68); // activate DS1307
        Wire.write(0); // where to begin
        Wire.write(0x00);          //seconds
        Wire.write(minutes);          //minutes
        Wire.write(0x80 | hours);    //hours (24hr time)
        Wire.write(0x06);  // Day 01-07
        Wire.write(0x01);  // Date 0-31
        Wire.write(0x05);  // month 0-12
        Wire.write(0x09);  // Year 00-99
        Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7.
        Wire.endTransmission();

        // converting hexa in zecimal:
        zh = hours / 16;
        uh = hours - 16 * zh ;
        ore = 10 * zh + uh;
        zm = minutes / 16;
        um = minutes - 16 * zm ;
        miniti = 10 * zm + um;



        for (int i = 400 ; i > 0  ; i--) {
          displayNumber01(ore * 10000 + miniti * 100);
        }
        delay(100);
        //Serial.print(digitalRead(SW0));
        if (digitalRead(SW0) == 0) Z = 0;
        delay(300);
      }
      //Serial.print(SW2);
    }



    void displayNumber01(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

      for (int digit = 6 ; digit > 0 ; digit--) {

        //Turn on a digit for a short amount of time
        switch (digit) {
          case 1:
            digitalWrite(digit1, DIGIT_ON);

            break;
          case 2:
            digitalWrite(digit2, DIGIT_ON);
            //digitalWrite(segDP, LOW);
            break;
          case 3:
            digitalWrite(digit3, DIGIT_ON);

            break;
          case 4:
            digitalWrite(digit4, DIGIT_ON);

            break;


        }
        lightNumber(toDisplay % 10);
        toDisplay /= 10;
        delayMicroseconds(DISPLAY_BRIGHTNESS);


        //Turn off all segments
        lightNumber(10);

        //Turn off all digits
        digitalWrite(digit1, DIGIT_OFF);
        digitalWrite(digit2, DIGIT_OFF);
        digitalWrite(digit3, DIGIT_OFF);
        digitalWrite(digit4, DIGIT_OFF);

      }
    }

    void displayNumber02(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

      for (int digit = 6 ; digit > 0 ; digit--) {

        //Turn on a digit for a short amount of time
        switch (digit) {
          case 1:
            lightNumber(10);

            break;
          case 2:
            digitalWrite(digit2, DIGIT_ON);
            //digitalWrite(segDP, LOW);
            break;
          case 3:
            digitalWrite(digit3, DIGIT_ON);

            break;
          case 4:
            digitalWrite(digit4, DIGIT_ON);

            break;

        }
        lightNumber(toDisplay % 10);
        toDisplay /= 10;
        delayMicroseconds(DISPLAY_BRIGHTNESS);

        //Turn off all segments
        lightNumber(10);

        //Turn off all digits
        digitalWrite(digit1, DIGIT_OFF);
        digitalWrite(digit2, DIGIT_OFF);
        digitalWrite(digit3, DIGIT_OFF);
        digitalWrite(digit4, DIGIT_OFF);

      }
    }

    void displayNumber03(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

      for (int digit = 6 ; digit > 0 ; digit--) {

        //Turn on a digit for a short amount of time
        switch (digit) {
          case 1:
            digitalWrite(digit1, DIGIT_ON);

            break;
          case 2:
            digitalWrite(digit2, DIGIT_ON);

            break;
          case 3:
            digitalWrite(digit3, DIGIT_ON);

            break;
          case 4:
            digitalWrite(digit4, DIGIT_ON);

            break;

        }
        lightNumber(toDisplay % 10);
        toDisplay /= 10;
        delayMicroseconds(DISPLAY_BRIGHTNESS);

        //Turn off all segments
        lightNumber(10);

        //Turn off all digits
        digitalWrite(digit1, DIGIT_OFF);
        digitalWrite(digit2, DIGIT_OFF);
        digitalWrite(digit3, DIGIT_OFF);
        digitalWrite(digit4, DIGIT_OFF);

      }
    }

    void displayNumber04(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

      for (int digit = 6 ; digit > 0 ; digit--) {

        //Turn on a digit for a short amount of time
        switch (digit) {
          case 1:
            lightNumber(10);

            break;
          case 2:
            digitalWrite(digit2, DIGIT_ON);

            break;
          case 3:
            digitalWrite(digit3, DIGIT_ON);

            break;
          case 4:
            digitalWrite(digit4, DIGIT_ON);

            break;

        }
        lightNumber(toDisplay % 10);
        toDisplay /= 10;
        delayMicroseconds(DISPLAY_BRIGHTNESS);

        //Turn off all segments
        lightNumber(10);

        //Turn off all digits
        digitalWrite(digit1, DIGIT_OFF);
        digitalWrite(digit2, DIGIT_OFF);
        digitalWrite(digit3, DIGIT_OFF);
        digitalWrite(digit4, DIGIT_OFF);

      }
    }

    void displayNumber05(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

      for (int digit = 6 ; digit > 0 ; digit--) {

        //Turn on a digit for a short amount of time
        switch (digit) {
          case 1:
            digitalWrite(digit1, DIGIT_ON);

            break;
          case 2:
            digitalWrite(digit2, DIGIT_ON);

            break;
          case 3:
            digitalWrite(digit3, DIGIT_ON);

            break;
          case 4:
            digitalWrite(digit4, DIGIT_ON);

            break;

        }
        lightNumber(toDisplay % 10);
        toDisplay /= 10;
        delayMicroseconds(DISPLAY_BRIGHTNESS);

        //Turn off all segments
        lightNumber(10);

        //Turn off all digits
        digitalWrite(digit1, DIGIT_OFF);
        digitalWrite(digit2, DIGIT_OFF);
        digitalWrite(digit3, DIGIT_OFF);
        digitalWrite(digit4, DIGIT_OFF);

      }
    }

    void displayNumber06(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

      for (int digit = 6 ; digit > 0 ; digit--) {

        //Turn on a digit for a short amount of time
        switch (digit) {
          case 1:
            //digitalWrite(digit1, DIGIT_ON);

            break;
          case 2:
            digitalWrite(digit2, DIGIT_ON);

            break;
          case 3:
            digitalWrite(digit3, DIGIT_ON);

            break;
          case 4:
            digitalWrite(digit4, DIGIT_ON);

            break;

        }
        lightNumber(toDisplay % 10);
        toDisplay /= 10;
        delayMicroseconds(DISPLAY_BRIGHTNESS);

        //Turn off all segments
        lightNumber(10);

        //Turn off all digits
        digitalWrite(digit1, DIGIT_OFF);
        digitalWrite(digit2, DIGIT_OFF);
        digitalWrite(digit3, DIGIT_OFF);
        digitalWrite(digit4, DIGIT_OFF);

      }
    }
    //Given a number, turns on those segments
    //If number == 10, then turn off number
    void lightNumber(int numberToDisplay) {

      //Common Anode *************************
#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW


      switch (numberToDisplay) {

        case 0:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_ON);
          digitalWrite(segE, SEGMENT_ON);
          digitalWrite(segF, SEGMENT_ON);
          digitalWrite(segG, SEGMENT_OFF);
          break;

        case 1:
          digitalWrite(segA, SEGMENT_OFF);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_OFF);
          digitalWrite(segE, SEGMENT_OFF);
          digitalWrite(segF, SEGMENT_OFF);
          digitalWrite(segG, SEGMENT_OFF);
          break;

        case 2:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_OFF);
          digitalWrite(segD, SEGMENT_ON);
          digitalWrite(segE, SEGMENT_ON);
          digitalWrite(segF, SEGMENT_OFF);
          digitalWrite(segG, SEGMENT_ON);
          break;

        case 3:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_ON);
          digitalWrite(segE, SEGMENT_OFF);
          digitalWrite(segF, SEGMENT_OFF);
          digitalWrite(segG, SEGMENT_ON);
          break;

        case 4:
          digitalWrite(segA, SEGMENT_OFF);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_OFF);
          digitalWrite(segE, SEGMENT_OFF);
          digitalWrite(segF, SEGMENT_ON);
          digitalWrite(segG, SEGMENT_ON);
          break;

        case 5:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_OFF);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_ON);
          digitalWrite(segE, SEGMENT_OFF);
          digitalWrite(segF, SEGMENT_ON);
          digitalWrite(segG, SEGMENT_ON);
          break;

        case 6:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_OFF);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_ON);
          digitalWrite(segE, SEGMENT_ON);
          digitalWrite(segF, SEGMENT_ON);
          digitalWrite(segG, SEGMENT_ON);
          break;

        case 7:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_OFF);
          digitalWrite(segE, SEGMENT_OFF);
          digitalWrite(segF, SEGMENT_OFF);
          digitalWrite(segG, SEGMENT_OFF);
          break;

        case 8:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_ON);
          digitalWrite(segE, SEGMENT_ON);
          digitalWrite(segF, SEGMENT_ON);
          digitalWrite(segG, SEGMENT_ON);
          break;

        case 9:
          digitalWrite(segA, SEGMENT_ON);
          digitalWrite(segB, SEGMENT_ON);
          digitalWrite(segC, SEGMENT_ON);
          digitalWrite(segD, SEGMENT_ON);
          digitalWrite(segE, SEGMENT_OFF);
          digitalWrite(segF, SEGMENT_ON);
          digitalWrite(segG, SEGMENT_ON);
          break;

        // all segment are ON
        case 10:
          digitalWrite(segA, SEGMENT_OFF);
          digitalWrite(segB, SEGMENT_OFF);
          digitalWrite(segC, SEGMENT_OFF);
          digitalWrite(segD, SEGMENT_OFF);
          digitalWrite(segE, SEGMENT_OFF);
          digitalWrite(segF, SEGMENT_OFF);
          digitalWrite(segG, SEGMENT_OFF);
          break;

      }
      // End of the coding, BUDHUSARANAI, Best of luck.

    }

and the error message is

C:\Users\SUBHRO\AppData\Local\Temp\arduino_modified_sketch_679888\sketch_feb07a.ino: In function 'void loop()':

sketch_feb07a:223:49: error: 'displayNumber01' was not declared in this scope

         if (timp >= 100000) displayNumber01(timp);

                                                 ^

sketch_feb07a:224:34: error: 'displayNumber02' was not declared in this scope

         else displayNumber02(timp);

                                  ^

sketch_feb07a:228:49: error: 'displayNumber03' was not declared in this scope

         if (timp >= 100000) displayNumber03(timp);

                                                 ^

sketch_feb07a:229:34: error: 'displayNumber04' was not declared in this scope

         else displayNumber04(timp);

                                  ^

sketch_feb07a:233:49: error: 'displayNumber05' was not declared in this scope

         if (timp >= 100000) displayNumber05(timp);

                                                 ^

sketch_feb07a:234:34: error: 'displayNumber06' was not declared in this scope

         else displayNumber06(timp);

                                  ^

sketch_feb07a:243:18: error: 'set_time' was not declared in this scope

         set_time();

                  ^

sketch_feb07a:247:23: error: a function-definition is not allowed here before '{' token

     void set_time()   {

                       ^

sketch_feb07a:744:5: error: expected '}' at end of input

     }

     ^

sketch_feb07a:744:5: error: expected '}' at end of input

exit status 1
'displayNumber01' was not declared in this scope

Now that you have formatted the code, it is pretty easy to see...
Void displayNumber01 should be at the very left. Instead it is one tab to the right.
So you miss one } somewhere in loop().
Add a } at the end of loop and see what happens...
Hit ctrl-t again to see if void is now fully to the left.

@subhrodeep - your missing close brace "}" is before set_time()... not setup()... and after you fix that you will find that you have many missing definitions (see post #5). The code that you copy/pasted from (your link in your post #1) is complete, and compiles. Take a look at it, and try again.

after adding '}' the code compile successfully but the chime part and clock not working...
it is clear that the only chime part of this code cannot extracted till now...

Okay. Can you show your working code and any errors/output displayed in your Serial Monitor? Also, can you describe "chime part and clock not working"? I understand you do not hear something and see something, but is something "bad" or "none" or "other"... post (here) what you see.

(sry late edit ... and your circuit drawing...) The following is from the Gallery... from the Author:

Here is how I have my hardware hooked up:

The external RTC (e.g. DS3231) is connected to the Arduino thus:

RTC SDA goes to A4 of Arduino
RTC SDA goes through a 5100-ohm resistor to +5V
RTC SCL goes to A5 of Arduino
RTC SCL goes through a 5100-ohm resistor to +5V
RTC VCC goes to +5V
RTC GND goes to ground

The LCD display to Arduino is connected to the Arduino thus:

LCD VSS goes to ground
LCD VDD goes to +5V
LCD V0 goes through a 9000-ohm resistor to +5V
LCD V0 goes through a 1000-ohm resistor to ground
    These numbers (9000 and 1000) were what worked for me. Feel free to try different numbers, but I read that they need to add up to 10000 ohms.
LCD RW goes to ground
LCD LED+ (or A) goes through a 220-ohm resistor to +5V
LCD LED- (or K) goes to ground
LCD RS goes to Arduino pin 7
LCD EN (or E) goes to Arduino pin 6
LCD D4 goes to Arduino pin 5
LCD D5 goes to Arduino pin 4
LCD D6 goes to Arduino pin 3
LCD D7 goes to Arduino pin 2
    For LCD pins RS, EN, D4, D5, D6, and D7, you can (I believe) choose any six free Arduino pins. Just make sure to specify which six pins in the code.

The buzzer is connected thus:

Buzzer (-) to ground
Buzzer (+) to Arduino pin 9 through a 150-ohm resistor

The Daylight Saving Time switch, (once I get a hardware switch) will be connected thus:

one contact of DST switch to ground
the other contact of DST switch to Arduino pin 8

Note: If you don't have, for example, a 9000-ohm resistor, just use two (or more) resistors that add up to the resistance you need. Just be sure to connect them in series, so that the math works right. (If you connect them in parallel, then the math won't work, and you'll end up with much less resistance than you were aiming for.)

And, the author's re-written code:

#include "Wire.h"
#include <LiquidCrystal.h>

// Make sure your pin numbers match these!
//                RS  EN  D4  D5  D6  D7
LiquidCrystal lcd( 7,  6,  5,  4,  3,  2);
const byte DST_SWITCH_PIN = 8;
const byte SPEAKER_PIN = 9;
const byte PLUS_BUTTON_PIN = 11;
const byte SET_BUTTON_PIN = 12;

// some useful constants (names of modes)
const byte SET_YEAR   = 6;
const byte SET_MONTH  = 5;
const byte SET_DATE   = 4;
const byte SET_HOUR   = 3;
const byte SET_MINUTE = 2;
const byte SET_SECOND = 1;
const byte KEEP_TIME  = 0;

// another useful constant
const byte MINIMUM_YEAR = 22; // because I am writing this in 2022

// variables for the current date and time
byte yy=0, mo=1, dd=0, wd=6;
byte hh=0, mi=0, ss=0;
byte hhTwelve = 12;
byte wn=52;

// other helpful variables
bool gotTheTime = false;
bool timeIsGarbage = false;
byte old_ss = 99, halfSec = 198, old_halfSec = 198;
unsigned long microsNow = 0UL;
unsigned long microsAtLastSecond = 0UL;
bool dstOn = false, old_dstOn = false;
bool plusPressed = false, old_plusPressed = false;
bool setPressed = false, old_setPressed = false;
byte clockMode = KEEP_TIME;

// a buffer for text to be displayed
char buf[20] = "";

void setup() {
  pinMode(DST_SWITCH_PIN, INPUT_PULLUP);
  pinMode(SPEAKER_PIN, OUTPUT);
  pinMode(PLUS_BUTTON_PIN, INPUT_PULLUP);
  pinMode(SET_BUTTON_PIN, INPUT_PULLUP);
  
  Wire.begin();
  lcd.begin(16, 2);
  
  // BEGINNING of code for setting the date and time
  
  // If you wish to set the date and time,
  // uncomment the following:
  
  /*
  // code to precisely set the external real-time clock
  Wire.beginTransmission(0x68); // address DS3231
  Wire.write(0x00); // select register
  // NOTE: before you run this code, you *must*
  // change the following numbers to the correct time!
  // (plus a few seconds to allow for compilation, etc.)
  Wire.write(numberToBcd( 0)); // seconds
  Wire.write(numberToBcd(21)); // minutes
  Wire.write(numberToBcd( 1)); // hours (use 24-hour format)
  Wire.write(numberToBcd( 6)); // day of week (I use Mon=1 .. Sun=7)
  Wire.write(numberToBcd( 9)); // day of month
  Wire.write(numberToBcd( 4)); // month
  Wire.write(numberToBcd(22)); // year (use only two digits)
  Wire.endTransmission();
  */
  
  // END of code for setting the date and time

  /*
  // define special characters for single cell numerals 10 through 12
  byte singleCellTen[]    = { 18, 21, 21, 21, 21, 21, 18,  0 };
  byte singleCellEleven[] = {  9, 27,  9,  9,  9,  9,  9,  0 };
  byte singleCellTwelve[] = { 22, 21, 17, 18, 20, 20, 23,  0 };
  lcd.createChar(10, singleCellTen);
  lcd.createChar(11, singleCellEleven);
  lcd.createChar(12, singleCellTwelve);
  */
  
  // play a short tone (for testing the speaker)
  tone(SPEAKER_PIN, 1000, 500);
  
  // display a demo pattern (for testing the display)
  lcd.setCursor(0, 0); // go to beginning of top line
  lcd.print(F("  Display test  "));
  lcd.setCursor(0, 1); // go to beginning of bottom line
  lcd.print(F("0123456789 (^_^)"));

  for (int i = 5; i >= 1; i--) { // countdown from 5 to 1
    lcd.setCursor(0, 0); // go to beginning of top line
    lcd.print((char)('0' + i)); // print the digit
    lcd.setCursor(15, 0); // go to end of top line
    lcd.print((char)('0' + i)); // print the digit again
    delay(998);
  }
}

void loop() {
  if (clockMode == KEEP_TIME) {
    // normal timekeeping mode
    
    // first, we (try to) read the time from the RTC
    // send request to receive data starting at register 0
    Wire.beginTransmission(0x68); // 0x68 is DS3231 device address
    Wire.write((byte)0); // start at register 0
    Wire.endTransmission();
    Wire.requestFrom(0x68, 7); // request seven bytes
   
    gotTheTime = false;
    while(Wire.available())
    { 
      ss = bcdToNumber(Wire.read()); // get seconds
      mi = bcdToNumber(Wire.read()); // get minutes
      hh = bcdToNumber(Wire.read()); // get hours
      Wire.read(); // discard the day of the week (we will calculate it ourself)
      dd = bcdToNumber(Wire.read()); // get day of month
      mo = bcdToNumber(Wire.read()); // get month
      yy = bcdToNumber(Wire.read()); // get year
      gotTheTime = true;
    }

    microsNow = micros();
    
    // detect garbage dates and times
    if ((yy < MINIMUM_YEAR) || (yy > 99)) timeIsGarbage = true;
    if ((mo < 1) || (mo > 12)) timeIsGarbage = true;
    if ((dd < 1) || (dd > daysInMonth(yy,mo))) timeIsGarbage = true;
    if (hh > 23) timeIsGarbage = true;
    if (mi > 59) timeIsGarbage = true;
    if (ss > 59) timeIsGarbage = true;
    
    // read the Daylight Saving Time on/off switch
    // NOTE: because we are using INPUT_PULLUP, LOW means on, and HIGH means off
    dstOn = (digitalRead(DST_SWITCH_PIN) == LOW);
    
    // adjust for Daylight Saving Time if applicable
    if (dstOn) {
      hh++;
      if (hh >= 24) {
        hh -= 24;
        dd++;
        if (dd > daysInMonth(yy, mo)) {
          dd = 1;
          mo++;
          if (mo > 12) {
            mo = 1;
            yy++;
          }
        }
      }
    }
    
    // try to figure out which half-second we are in
    // (this is important to making the striking work properly)
    if (ss != old_ss) microsAtLastSecond = microsNow;
    halfSec = ss * 2;
    if ((microsNow - microsAtLastSecond) >= 500000UL) halfSec++;
    
    // calculate day of the week
    wd = ymdToWeekday(yy, mo, dd);

    // calculate week number  
    wn = ymdToWeekNumber(yy, mo, dd);
    
    // convert hour to 12-hour format
    hhTwelve = hh;
    if (hhTwelve > 12) {
      hhTwelve -= 12;
    }
    if (hhTwelve == 0) {
      hhTwelve = 12;
    }
    
    if (gotTheTime && (!timeIsGarbage)) {
      // only if we have successfully read the time
      // (and it is not a garbage time)
      // do we then attempt to indicate the time
      
      if (halfSec != old_halfSec) { // do this only once every half-second
        // see if it is time for the clock to strike
        if (mi == 0) {  // strike on the hour, i.e. when minutes are 0
          if (halfSec < 26) {
            // play the Westminster Chimes
            switch (halfSec) {
              case 0:  tone(SPEAKER_PIN, 330, 420); break;
              case 1:  tone(SPEAKER_PIN, 415, 420); break;
              case 2:  tone(SPEAKER_PIN, 370, 420); break;
              case 3:  tone(SPEAKER_PIN, 247, 735); break;
              case 6:  tone(SPEAKER_PIN, 330, 420); break;
              case 7:  tone(SPEAKER_PIN, 370, 420); break;
              case 8:  tone(SPEAKER_PIN, 415, 420); break;
              case 9:  tone(SPEAKER_PIN, 330, 735); break;
              case 12: tone(SPEAKER_PIN, 415, 420); break;
              case 13: tone(SPEAKER_PIN, 330, 420); break;
              case 14: tone(SPEAKER_PIN, 370, 420); break;
              case 15: tone(SPEAKER_PIN, 247, 735); break;
              case 18: tone(SPEAKER_PIN, 247, 420); break;
              case 19: tone(SPEAKER_PIN, 370, 420); break;
              case 20: tone(SPEAKER_PIN, 415, 420); break;
              case 21: tone(SPEAKER_PIN, 330, 735); break;
              default: break;
            }
          }
          else if ((halfSec < (26 + 3 * hhTwelve)) && ((halfSec % 3) == 2)) {
            // bong the hours
            tone(SPEAKER_PIN, 415, 750);
          }
        }
      }
      
      if ((ss != old_ss) || (dstOn != old_dstOn)) { // only once every second
        // update the display to show the current date and time
        
        // build a string of text containing the weekday and the full date
        // (Hint: this code makes more sense if you read it vertically)
        buf[0]  = "BMTWTFSS"[wd];
        buf[1]  = "aouehrau"[wd];
        buf[2]  = "dneduitn"[wd];
        buf[3]  = ' ';
        buf[4]  = ' ';
        buf[5]  = ' ';
        buf[6]  = '0' + (mo/10);
        buf[7]  = '0' + (mo%10);
        buf[8]  = '/';
        buf[9]  = '0' + (dd/10);
        buf[10] = '0' + (dd%10);
        buf[11] = '/';
        buf[12] = '2';
        buf[13] = '0';
        buf[14] = '0' + (yy/10);
        buf[15] = '0' + (yy%10);
        buf[16] = 0;
        // suppress leading zero for month (character at position 6)
        if (buf[6] == '0') buf[6] = ' ';
        // display the weekday and full date on the top line
        lcd.setCursor(0, 0); // move to beginning of top line 
        lcd.print(buf); // print the text to the display
        
        // build a string of text containing the week number and the time
        buf[0]  = 'W';
        buf[1]  = 'k';
        buf[2]  = '0' + (wn/10);
        buf[3]  = '0' + (wn%10);
        buf[4]  = ' ';
        buf[5]  = ' ';
        buf[6]  = '0' + (hhTwelve/10);
        buf[7]  = '0' + (hhTwelve%10);
        buf[8]  = ':';
        buf[9]  = '0' + (mi/10);
        buf[10] = '0' + (mi%10);
        buf[11] = ':';
        buf[12] = '0' + (ss/10);
        buf[13] = '0' + (ss%10);
        buf[14] = ((hh<12) ? 'a' : 'p');
        buf[15] = 'm';
        buf[16] = 0;
        // suppress leading zero for hour (character at position 6)
        if (buf[6] == '0') buf[6] = ' ';
        // display the week number and the time on the bottom line
        lcd.setCursor(0, 1); // move to beginning of bottom line
        lcd.print(buf); // print the text to the display
      }  
    }
    
    else if (gotTheTime) {
      // if we have read a garbage time from the RTC,
      // then we will end up in here
      
      // we request that the time be set
      lcd.setCursor(0, 0); // go to beginning of top line
      lcd.print(F(" Please set the "));
      lcd.setCursor(0, 1); // go to beginning of bottom line
      lcd.print(F(" date and time. "));     
    }
    
    else {
      // if we have *completely* failed to read *anything* from the RTC,
      // then we will end up inside this "else"
      
      // indicate failure to read the time
      lcd.setCursor(0, 0); // go to beginning of top line
      lcd.print(F("Error:          "));
      lcd.setCursor(0, 1); // go to beginning of bottom line
      lcd.print(F("Can\'t read time "));
      
      while(1) {
        // do nothing, forever
      }
    }
    
    while (micros() - microsNow < 10000UL) {
      // do nothing for about 1/100 of a second
    }
    
    // remember these for the next time through loop()
    old_ss = ss;
    old_halfSec = halfSec;
    old_dstOn = dstOn;
  }
  
  else {
    // time setting mode
    
    microsNow = micros();
    
    // show the screen for setting the time
    // first, assemble the string to be displayed
    switch (clockMode) {
      case SET_YEAR:
        //                  01234567890123456
        strcpy_P(buf, PSTR(" Set year: 20XX "));
        buf[13] = '0' + (yy/10);
        buf[14] = '0' + (yy%10);
        break;
      case SET_MONTH:
        //                  01234567890123456
        strcpy_P(buf, PSTR(" Set month:  XX "));
        buf[13] = '0' + (mo/10);
        buf[14] = '0' + (mo%10);
        break;
      case SET_DATE:
        //                  01234567890123456
        strcpy_P(buf, PSTR(" Set date:   XX "));
        buf[13] = '0' + (dd/10);
        buf[14] = '0' + (dd%10);
        break;
      case SET_HOUR:
        //                  01234567890123456
        strcpy_P(buf, PSTR(" Set hour: XXXm "));
        // Should I take care of this conversion here or elsewhere?
        // I'll take care of it here, just to be safe.
        hhTwelve = hh % 12;
        if (hhTwelve == 0) hhTwelve = 12;
        buf[11] = '0' + (hhTwelve/10);
        buf[12] = '0' + (hhTwelve%10);
        buf[13] = ((hh < 12) ? 'a' : 'p');
        break;
      case SET_MINUTE:
        //                  01234567890123456
        strcpy_P(buf, PSTR(" Set minute: XX "));
        buf[13] = '0' + (mi/10);
        buf[14] = '0' + (mi%10);
        break;
      case SET_SECOND:
        //                  01234567890123456
        strcpy_P(buf, PSTR(" Set second: XX "));
        buf[13] = '0' + (ss/10);
        buf[14] = '0' + (ss%10);
        break;
      default:
        //                  01234567890123456
        strcpy_P(buf, PSTR(" Mode error!    "));
    }
    lcd.setCursor(0, 0); // move to beginning of top line 
    lcd.print(buf); // print the text to the display
    lcd.setCursor(0, 1); // go to beginning of bottom line
    lcd.print(F("                ")); // print a full row of blanks
    
    while (micros() - microsNow < 20000UL) {
      // do nothing for about 1/50 of a second
    }
  }
  
  // check the buttons
  // NOTE: because we are using INPUT_PULLUP, LOW means the button is pressed
  plusPressed = (digitalRead(PLUS_BUTTON_PIN) == LOW);
  setPressed = (digitalRead(SET_BUTTON_PIN) == LOW);

  if (plusPressed && !(old_plusPressed)) {
    // the "plus" button was just pressed
    switch (clockMode) {
      case SET_YEAR:
        yy = (yy + 1) % 100;
        if (yy < MINIMUM_YEAR) yy = MINIMUM_YEAR;
        break;
      case SET_MONTH:
        mo = (mo % 12) + 1;
        break;
      case SET_DATE:
        dd = (dd % daysInMonth(yy, mo)) + 1;
        break;
      case SET_HOUR:
        hh = (hh + 1) % 24;
        break;
      case SET_MINUTE:
        mi = (mi + 1) % 60;
        break;
      case SET_SECOND:
        ss = (ss + 5) % 60;
        ss -= (ss % 5);
        break;
      default:
        // do nothing
        ;
    }
  }
  
  if (setPressed && !(old_setPressed)) {
    // the "set" button was just pressed
    
    // change to the new mode
    if (clockMode == KEEP_TIME) {
      clockMode = SET_YEAR;
    }
    else {
      clockMode--;
    }
    
    // act according to the new mode
    switch (clockMode) {
      case SET_YEAR:
        if (yy < MINIMUM_YEAR) yy = MINIMUM_YEAR;
        if (yy > 99) yy = 99;
        break;
      case SET_MONTH:
        if (mo < 1) mo = 1;
        if (mo > 12) mo = 12;
        break;
      case SET_DATE:
        if (dd < 1) dd = 1;
        if (dd > daysInMonth(yy, mo)) dd = daysInMonth(yy, mo);
        break;
      case SET_HOUR:
        if (hh > 23) hh = 23;
        break;
      case SET_MINUTE:
        if (mi > 59) mi = 59;
        break;
      case SET_SECOND:
        if (ss > 59) ss = 59;
        break;
        
      case KEEP_TIME:
        // prepare to enter normal timekeeping mode
      
        // read the Daylight Saving Time on/off switch
        // NOTE: because we are using INPUT_PULLUP, LOW means on, and HIGH means off
        dstOn = (digitalRead(DST_SWITCH_PIN) == LOW);
        
        // because the RTC keeps "standard" (i.e. non-Daylight Saving) time,
        // then, if we are in Daylight Saving Time,
        // we will need to subtract 1 hour before we write to the RTC
        if (dstOn) {
          if (hh == 0) {
            hh = 23;
            dd--;
            if (dd == 0) {
              mo--;
              if (mo == 0) {
                mo = 12;
                yy--;
              }
              dd = daysInMonth(yy, mo);
            }
          }
          else {
            hh--;
          }
        }
        
        // calculate the day of the week (not that we really care, anyway)
        wd = ymdToWeekday(yy, mo, dd);
        
        // indicate that this is a valid time, not a garbage time
        timeIsGarbage = false;
      
        // write the date and time to the RTC
        Wire.beginTransmission(0x68); // address DS3231
        Wire.write(0x00); // select register
        Wire.write(numberToBcd(ss)); // seconds
        Wire.write(numberToBcd(mi)); // minutes
        Wire.write(numberToBcd(hh)); // hours (use 24-hour format)
        Wire.write(numberToBcd(wd)); // day of week (I use Mon=1 .. Sun=7)
        Wire.write(numberToBcd(dd)); // day of month
        Wire.write(numberToBcd(mo)); // month
        Wire.write(numberToBcd(yy)); // year (use only two digits)
        Wire.endTransmission();
        
        // update these variables
        microsNow = micros();
        microsAtLastSecond = microsNow;
        halfSec = ss * 2;
        
        // change these variables to nonsense values
        // this will force a display update next time through loop()
        old_ss = 99;
        old_halfSec = 198;
        
        // maybe I don't need this delay, but I'm putting it in anyway
        delay(50);
        break;
        
      default:
        // should never happen
        lcd.setCursor(0, 0); // move to beginning of top line      
        lcd.print(F("Error: bad mode!")); // display error message
        while (1) {
          // do nothing, forever
        }
    }
  }
  
  old_plusPressed = plusPressed;
  old_setPressed = setPressed;
}

byte bcdToNumber(byte b) {
  // convert BCD (binary-coded decimal) to an ordinary number
  byte tens = (b >> 4) & 0xF;
  byte ones = b & 0xF;
  return (byte)((tens * 10) + ones);
}

byte numberToBcd(byte n) {
  // convert a number to binary-coded decimal
  byte tens = (n/10);
  byte ones = (n%10);
  return (byte)((tens << 4) + ones);
}

byte daysInMonth(byte y, byte m) {
  // get the number of days in the given month
  // y is for the year (0 to 99 for years 2000 through 2099)
  // m is for the month (1 to 12)
  
  // reject out-of-range input
  if (y > 99) return 0;
  if ((m < 1) || (m > 12)) return 0;
  
  // Fourth, eleventh, ninth, and sixth,
  // thirty days to each we fix. 
  if ((m==4)||(m==11)||(m==9)||(m==6)) return 30; 
  // Every other, thirty-one,
  // except the second month alone,
  if (m!=2) return 31;
  // which hath twenty-eight, in fine,
  // till leap-year give it twenty-nine.
  if ((y%4)==0) return 29; // leap year
  return 28; // not a leap year 
}

byte ymdToWeekNumber (byte y, byte m, byte d) {
  // get the week number for a given year, month, and day  
  // NOTE: This function uses two-digit years
  // y is a number from 0 (for year 2000) to 99 (for year 2099)
  // This function will not work for years outside of this range!
  
  // reject out-of-range dates
  if (y > 99) return 0;
  if ((m < 1)||(m > 12)) return 0;
  if ((d < 1)||(d > 31)) return 0;
  // special case first two days of January 2000
  if ((y == 0) && (m == 1) && (d <= 2)) return 52;
  // (It is useful to know that Jan. 1, 2000 was a Saturday)
  // compute adjustment for dates within the year
  //     If Jan. 1 falls on: Mo Tu We Th Fr Sa Su
  // then the adjustment is:  6  7  8  9  3  4  5
  byte adj = ((y + 1 + ((y+3)/4)) % 7) + 3;
  // compute day of the year (in range 1-366)
  int doy = d;
  if (m > 1) doy += 31;
  if (m > 2) {
    if ((y%4)==0) doy += 29;
    else doy += 28;
  }
  if (m > 3) doy += 31;
  if (m > 4) doy += 30;
  if (m > 5) doy += 31;
  if (m > 6) doy += 30;
  if (m > 7) doy += 31;
  if (m > 8) doy += 31;
  if (m > 9) doy += 30;
  if (m > 10) doy += 31;
  if (m > 11) doy += 30;
  // compute week number
  byte wknum = (adj + doy) / 7;
  // check for boundary conditions
  if (wknum < 1) {
    // last week of the previous year
    // go to previous year and re-compute adjustment
    y--;
    adj = ((y + 1 + ((y+3)/4)) % 7) + 3;
    // check to see whether that year had 52 or 53 weeks
    // all years beginning on Thursday have 53 weeks
    if (adj==9) return 53;
    // leap years beginning on Wednesday have 53 weeks
    if ((adj==8) && ((y%4)==0)) return 53;
    // other years have 52 weeks
    return 52;
  }
  if (wknum > 52) {
    // check to see whether week 53 exists in this year
    // all years beginning on Thursday have 53 weeks
    if (adj==9) return 53;
    // leap years beginning on Wednesday have 53 weeks
    if ((adj==8) && ((y%4)==0)) return 53;
    // other years have 52 weeks
    return 1;
  }
  return wknum;
}

byte ymdToWeekday(byte y, byte m, byte d) {
  // get the day of the week for a given year, month, and day  
  // NOTE: This function uses two-digit years
  // y is a number from 0 (for year 2000) to 99 (for year 2099)
  // This function will not work for years outside of this range!
  if (y > 99) return 0;
  if (d < 1) return 0;
  byte l = (((y%4)==0) ? 1 : 0);
  byte n = y + (y/4);
  switch (m) {
    case 1:  if (d > 31) return 0;  n+=(1-l); break;
    case 2: if (d>(28+l)) return 0; n+=(4-l); break;
    case 3:  if (d > 31) return 0;  n+= 4;    break;
    case 4:  if (d > 30) return 0;  break;
    case 5:  if (d > 31) return 0;  n+= 2; break;
    case 6:  if (d > 30) return 0;  n+= 5; break;
    case 7:  if (d > 31) return 0;  break;
    case 8:  if (d > 31) return 0;  n+= 3; break;
    case 9:  if (d > 30) return 0;  n+= 6; break;
    case 10: if (d > 31) return 0;  n+= 1; break;
    case 11: if (d > 30) return 0;  n+= 4; break;
    case 12: if (d > 31) return 0;  n+= 6; break;
    default: return 0;
  }
  n += d;
  n = ((n + 4) % 7) + 1;
  return n;  // 1 for Mon, 2 for Tue, ..., 7 for Sun
}

My DS1307 RTC connection is same as author, and I have made this code for 7 Segment led display clock . now this time clock is working properly but hourly chime not... probably I cannot read time from DS1307 which is very necessary for chiming part if this code... this is my code please check it ..

/*
  4 digit 7 segment display: http://www.sparkfun.com/products/9483
  Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf
*/
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf
// Code modified by BMIAK Basnayaka
// http://www.setnfix.com

int digit1 = 12;
int digit2 = 11;
int digit3 = 10;
int digit4 = 9;

//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = 0; //Display pin 0
int segB = 1; //Display pin 1
int segC = 2; //Display pin 2
int segD = 3; //Display pin 3
int segE = 4; //Display pin 4
int segF = 5; //Display pin 5
int segG = 6; //Display pin 6
int segDP = 13; // Display pin 13


int SPEAKER_PIN = 8;

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
// add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm

byte yy = 0, mo = 1, dd = 0, wd = 6;
byte hh = 0, mi = 0, ss = 0;
byte hhTwelve = 12;
byte wn = 52;

// other helpful variables
bool gotTheTime = false;
byte old_ss = 99, halfSec = 198, old_halfSec = 198;
unsigned long microsNow = 0UL;
unsigned long microsAtLastSecond = 0UL;
bool dstOn = false, old_dstOn = false;


byte SW0 = A0;
byte SW1 = A2;
byte SW2 = A1;
byte SWT = A3;
int Adhr = 0;
int Admnt = 0;
int D = 0;
int Z = 0;

// use for hexa in zecimal conversion
long zh, uh, ore;
long zm, um, miniti;

void setup() {

  //Serial.begin(57600);
  Wire.begin();
  RTC.begin();
  // RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // if you need set clock... just remove // from line above this

  // part code for flashing LED
  Wire.beginTransmission(0x68);
  Wire.write(0x07); // move pointer to SQW address
  // Wire.write(0x00); // turns the SQW pin off
  Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz
  // Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz

  Wire.endTransmission();


  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(SPEAKER_PIN, OUTPUT);


  //Serial.begin(9600);

  pinMode(SW0, INPUT);  // N.O. push button switch
  pinMode(SW1, INPUT);  // N.O. push button switch
  pinMode(SW2, INPUT);  // N.O. push button switch
  pinMode(SWT, INPUT);  // N.O. push button switch

  digitalWrite(SW0, HIGH); // pull-ups on
  digitalWrite(SW1, HIGH);
  digitalWrite(SW2, HIGH);
  digitalWrite(segDP, LOW);


}


void loop() {
  gotTheTime  = RTC.now;
  {
    // normal timekeeping mode
    gotTheTime = false;
    while (Wire.available())
    {
      gotTheTime = true;
    }

    microsNow = micros();

    // detect garbage dates and times

  }
  // try to figure out which half-second we are in
  // (this is important to making the striking work properly)
  if (ss != old_ss) microsAtLastSecond = microsNow;
  halfSec = ss * 2;
  if ((microsNow - microsAtLastSecond) >= 500000UL) halfSec++;

  // calculate day of the week


  // calculate week number




  if (gotTheTime ) {
    // only if we have successfully read the time
    // (and it is not a garbage time)
    // do we then attempt to indicate the time

    if (halfSec != old_halfSec) { // do this only once every half-second
      // see if it is time for the clock to strike
      if (mi == 0) {  // strike on the hour, i.e. when minutes are 0
        if (halfSec < 26) {
          // play the Westminster Chimes
          switch (halfSec) {
            case 0:  tone(SPEAKER_PIN, 330, 420); break;
            case 1:  tone(SPEAKER_PIN, 415, 420); break;
            case 2:  tone(SPEAKER_PIN, 370, 420); break;
            case 3:  tone(SPEAKER_PIN, 247, 735); break;
            case 6:  tone(SPEAKER_PIN, 330, 420); break;
            case 7:  tone(SPEAKER_PIN, 370, 420); break;
            case 8:  tone(SPEAKER_PIN, 415, 420); break;
            case 9:  tone(SPEAKER_PIN, 330, 735); break;
            case 12: tone(SPEAKER_PIN, 415, 420); break;
            case 13: tone(SPEAKER_PIN, 330, 420); break;
            case 14: tone(SPEAKER_PIN, 370, 420); break;
            case 15: tone(SPEAKER_PIN, 247, 735); break;
            case 18: tone(SPEAKER_PIN, 247, 420); break;
            case 19: tone(SPEAKER_PIN, 370, 420); break;
            case 20: tone(SPEAKER_PIN, 415, 420); break;
            case 21: tone(SPEAKER_PIN, 330, 735); break;
            default: break;
          }
        }
        else if ((halfSec < (26 + 3 * hhTwelve)) && ((halfSec % 3) == 2)) {
          // bong the hours
          tone(SPEAKER_PIN, 415, 750);
        }
      }
    }
  }

  DateTime now = RTC.now();
  long HR = now.hour() * 1000;
  long timp = (HR * 10) + now.minute() * 100 + now.second();
  Adhr = now.hour();
  Admnt = now.minute();



  int DIM = 0;
  if (timp >= 250000)
    timp = timp - 240000;
  //------------------------------------------------------
  //12/24 hours shitching
  //------------------------------------------------------
  if (timp < 130000) {
    digitalWrite(segDP, LOW);
  }


  if (digitalRead(SWT) == 0) {
    delay(300);
    if (D == 0) {
      D = 1; delay(200);
    }

    else {
      D = 0;
    }
  }




  if (D == 0) {
    if (timp >= 130000) {
      timp = timp - 120000;
      digitalWrite(segDP, HIGH);
    }
  }

  if (timp >= 130000) {
    digitalWrite(segDP, LOW);
  }

  if ((D == 1) & (timp < 130000))
    digitalWrite(segDP, LOW);





  //------------------------------------------------------






  //int timp = (now.minute(), DEC);
  //   displayNumber(12); // this is number to diplay



  for (int i = 100 ; i > 0  ; i--) {
    if (timp >= 100000) displayNumber01(timp);
    else displayNumber02(timp);
  }

  for (int i = 100 ; i > 0  ; i--) {
    if (timp >= 100000) displayNumber03(timp);
    else displayNumber04(timp);
  }

  for (int i = 100 ; i > 0  ; i--) {
    if (timp >= 100000) displayNumber05(timp);
    else displayNumber06(timp);
  }




  if (digitalRead(SW0) == 0) {
    delay(100);  // hold the switch to set time
    Z = 1;
    set_time();
  }
}

void set_time()   {
  byte minutes1 = 0;
  byte hours1 = 0;
  byte minutes = 0;
  byte hours = 0;
  hours = Adhr;
  minutes = Admnt;


  if ((hours & 0x0f) > 9) hours =  hours + 6;
  if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
  //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
  if ((minutes & 0x0f) > 9) minutes = minutes + 6;
  if (minutes > 0x59) minutes = 0;

  while (!(Z == 0)) { // set time switch must be released to exit






    int TST = digitalRead(SW2);
    while (TST == 0) // set hours
    {
      hours++;

      // converting hexa in zecimal:
      zh = hours / 16;
      uh = hours - 16 * zh ;
      ore = 10 * zh + uh;
      zm = minutes / 16;
      um = minutes - 16 * zm ;
      miniti = 10 * zm + um;




      if ((hours & 0x0f) > 9) hours =  hours + 6;
      if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 12:00 (With PM LED on) or 24:00
      //if (hours > 0x24) hours = 1; // Mid night 12.00 will show as 0:00
      if (hours <= 9)
        delay(1);

      for (int i = 400 ; i > 0  ; i--) {
        displayNumber01(ore * 10000 + miniti * 100);
      }

      TST = digitalRead(SW2);
    }

    while (!(digitalRead(SW1))) // set minutes
    {
      minutes++;
      // converting hexa in zecimal:
      zh = hours / 16;
      uh = hours - 16 * zh ;
      ore = 10 * zh + uh;
      zm = minutes / 16;
      um = minutes - 16 * zm ;
      miniti = 10 * zm + um;

      for (int i = 400 ; i > 0  ; i--) {
        displayNumber01(ore * 10000 + miniti * 100);
      }

      if ((minutes & 0x0f) > 9) minutes = minutes + 6;
      if (minutes > 0x59) minutes = 0;
      if (minutes >= 9)
        delay(1);
    }

    Wire.beginTransmission(0x68); // activate DS1307
    Wire.write(0); // where to begin
    Wire.write(0x00);          //seconds
    Wire.write(minutes);          //minutes
    Wire.write(0x80 | hours);    //hours (24hr time)
    Wire.write(0x06);  // Day 01-07
    Wire.write(0x01);  // Date 0-31
    Wire.write(0x05);  // month 0-12
    Wire.write(0x09);  // Year 00-99
    Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7.
    Wire.endTransmission();

    // converting hexa in zecimal:
    zh = hours / 16;
    uh = hours - 16 * zh ;
    ore = 10 * zh + uh;
    zm = minutes / 16;
    um = minutes - 16 * zm ;
    miniti = 10 * zm + um;



    for (int i = 400 ; i > 0  ; i--) {
      displayNumber01(ore * 10000 + miniti * 100);
    }
    delay(100);
    //Serial.print(digitalRead(SW0));
    if (digitalRead(SW0) == 0) Z = 0;
    delay(300);
  }
  //Serial.print(SW2);
}



void displayNumber01(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        digitalWrite(digit1, DIGIT_ON);

        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        //digitalWrite(segDP, LOW);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);

        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);

        break;


    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);


    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);

  }
}

void displayNumber02(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        lightNumber(10);

        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);
        //digitalWrite(segDP, LOW);
        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);

        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);

        break;

    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);

  }
}

void displayNumber03(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        digitalWrite(digit1, DIGIT_ON);

        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);

        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);

        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);

        break;

    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);

  }
}

void displayNumber04(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        lightNumber(10);

        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);

        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);

        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);

        break;

    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);

  }
}

void displayNumber05(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        digitalWrite(digit1, DIGIT_ON);

        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);

        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);

        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);

        break;

    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);

  }
}

void displayNumber06(long toDisplay) {
#define DISPLAY_BRIGHTNESS  25

#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW

  for (int digit = 6 ; digit > 0 ; digit--) {

    //Turn on a digit for a short amount of time
    switch (digit) {
      case 1:
        //digitalWrite(digit1, DIGIT_ON);

        break;
      case 2:
        digitalWrite(digit2, DIGIT_ON);

        break;
      case 3:
        digitalWrite(digit3, DIGIT_ON);

        break;
      case 4:
        digitalWrite(digit4, DIGIT_ON);

        break;

    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS);

    //Turn off all segments
    lightNumber(10);

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);

  }
}
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

  //Common Anode *************************
#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW


  switch (numberToDisplay) {

    case 0:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_OFF);
      break;

    case 1:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;

    case 2:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_OFF);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 3:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 4:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 5:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 6:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 7:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;

    case 8:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    case 9:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;

    // all segment are ON
    case 10:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_OFF);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;

  }
  // End of the coding, BUDHUSARANAI, Best of luck.

}

The author re-wrote his code. I pasted the author's code above. Please, check it.

I have used author re- written code which u mention in your post, it works with lcd display very well without any issue, but fails to do with 7 segment led display....

That is good. The topic is "... chime..." Your first post says your 7-segment is working, but if it is not, search for a solution to "7-segment clock," and if you can not find the solution, start a new topic.

Thanks for information:
website: Content marketing company

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.