stevie135s
Published © GPL3+

Westminster Chiming Clock

A Big Ben chiming clock using an Arduino Nano, a DS1302 RTC, a DFplayer Mini showing the time on a Nokia 5110 lcd with nightly cuckoo sounds

IntermediateFull instructions provided809
Westminster Chiming Clock

Things used in this project

Hardware components

Nokia 5110 LCD
×1
DFPlayer - A Mini MP3 Player
DFRobot DFPlayer - A Mini MP3 Player
×1
DS1302 RTC
×1
Arduino Nano
×1
Speaker: 3W, 4 ohms
Speaker: 3W, 4 ohms
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Chiming Clock Scheme

Circuit diagram

Westminster Chimes and Cuckoo sounds

Chimes 0001 - 0012
Cuckoo 0013 - 0024

Code

Chiming Analogue Clock

Arduino
Alternate code for analogue clock face
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <Ds1302.h>
#include <Adafruit_PCD8544.h>  // include adafruit PCD8544 (Nokia 5110) library

Adafruit_PCD8544 display = Adafruit_PCD8544(7,8,9,10,11); // CLK, DIN, D/C, CS, RST
SoftwareSerial mySoftwareSerial (3,2); // DFPlayer Mini RX Pin3 -> TX .. TX Pin2 -> RX
DFRobotDFPlayerMini myDFPlayer;

Ds1302 rtc(6,4,5);



static const unsigned char PROGMEM Big_Ben_3[] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFE, 0xD1, 0x0F, 0xFF, 0xFE, 0x7F, 0xF9, 0x05, 0x41,
0xFF, 0xFE, 0x63, 0xF0, 0x83, 0x42, 0x2F, 0xC6, 0x63, 0xDA, 0x05, 0x50, 0xBB, 0xC6, 0x6F, 0x8A,
0x51, 0x14, 0x25, 0xF6, 0x7F, 0x2D, 0x3F, 0xF9, 0x6A, 0xFE, 0x7E, 0x05, 0x83, 0x82, 0x50, 0x7E,
0x7C, 0x97, 0x07, 0x80, 0xA4, 0x3E, 0x7C, 0x2F, 0x83, 0x80, 0xE9, 0x5E, 0x78, 0x13, 0x87, 0x81,
0x10, 0x2E, 0x74, 0xA1, 0xC0, 0x02, 0x08, 0x1E, 0x73, 0x41, 0x80, 0x02, 0x05, 0x16, 0x7C, 0x81,
0x00, 0x00, 0x02, 0x6E, 0x47, 0x80, 0x00, 0x00, 0x02, 0xC2, 0x51, 0x80, 0x00, 0x00, 0x07, 0x16,
0x46, 0x60, 0x00, 0x00, 0x0F, 0x46, 0x22, 0x30, 0x00, 0x00, 0x18, 0x88, 0x08, 0x00, 0x00, 0x00,
0x00, 0xA0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x60, 0x04, 0x00,
0x00, 0x00, 0x00, 0x40, 0x74, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x27, 0xC0, 0x00, 0x00, 0x07, 0xC0,
0xFF, 0x40, 0x00, 0x00, 0x07, 0xFE, 0x27, 0xC0, 0x00, 0x00, 0x07, 0xC0, 0x74, 0x00, 0x00, 0x00,
0x00, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x54, 0x00, 0x00, 0x00, 0x00, 0x60, 0x04, 0x20,
0x00, 0x00, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x00, 0x10, 0xA0, 0x23, 0xF0, 0x00, 0x00, 0x1C, 0x88,
0x47, 0xF8, 0x00, 0x00, 0x1F, 0x42, 0x53, 0xF0, 0x00, 0x00, 0x1F, 0x12, 0x47, 0xE0, 0x00, 0x00,
0x07, 0xC6, 0x7C, 0x81, 0x00, 0x00, 0x02, 0x66, 0x73, 0x43, 0x80, 0x02, 0x05, 0x9E, 0x74, 0xA3,
0xC0, 0x03, 0x08, 0x4E, 0x78, 0x17, 0x83, 0x83, 0x10, 0x1E, 0x7C, 0x2F, 0x83, 0x81, 0xE9, 0x3E,
0x7C, 0x97, 0x03, 0x81, 0xA4, 0x7E, 0x7E, 0x15, 0x83, 0x82, 0xD0, 0xFE, 0x7F, 0xAD, 0x3F, 0xFD,
0x49, 0xFE, 0x63, 0xC8, 0x51, 0x14, 0x23, 0xC6, 0x63, 0xF2, 0x05, 0x50, 0xAF, 0xC6, 0x6B, 0xF8,
0x87, 0x42, 0x1F, 0xD6, 0x7F, 0xFE, 0x05, 0x50, 0xFF, 0xFE, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00
};

  static uint8_t last_second = 0;
  static uint8_t last_minute = 0;
  int hour2;

void setup()
{
  display.begin(); // initialise the Nokia display 
  display.clearDisplay();   // clears the screen and buffer      
  display.setContrast(50);

  mySoftwareSerial.begin(9600);
  myDFPlayer.begin(mySoftwareSerial);
  myDFPlayer.volume(15);
  rtc.init(); // Initialise the Real Time Clock

}

void loop()
{
  
    Ds1302::DateTime now; //Get the current time
    rtc.getDateTime(&now);
    if(last_second != now.second) {
      if ((now.minute == 59) && (now.second == 40)) {
        hour2 = now.hour +1;
        chime();
      }
      last_second = now.second;
    }
    if (last_minute != now.minute) {
      last_minute = now.minute;
      
  float x1, y1, x2, y2, x3, y3, x4, y4,v1 ,v2 ,v3 ,v4 ,w1 ,w2 ,w3 ,w4, Am,Ah;            
  Am = (now.minute * 6);
  Ah = (now.hour * 30) + (now.minute * 0.5);

  x1=25*sin(Am*0.0175); // Co-ords For Minute Hand
  y1=25*-cos(Am*0.0175);
  x2=3*sin(Am*0.0175);
  y2=3*-cos(Am*0.0175);
  x3=10*sin((Am+8)*0.0175);
  y3=10*-cos((Am+8)*0.0175);
  x4=10*sin((Am-8)*0.0175);
  y4=10*-cos((Am-8)*0.0175);

  v1=20*sin(Ah*0.0175); // Co-ords For Hour Hand
  w1=20*-cos(Ah*0.0175);
  v2=3*sin(Ah*0.0175);
  w2=3*-cos(Ah*0.0175);
  v3=8*sin((Ah+14)*0.0175);
  w3=8*-cos((Ah+14)*0.0175);
  v4=8*sin((Ah-14)*0.0175);
  w4=8*-cos((Ah-14)*0.0175);
  
  display.drawBitmap(18,0,Big_Ben_3,48,48,BLACK); // Display Clock Face Bitmap
  display.drawCircle(42,24,2,BLACK); // Draw Centre Circle
  
  display.drawLine(x1+42, y1+24, x3+42, y3+24,BLACK); // Draw Minutes
  display.drawLine(x3+42, y3+24, x2+42, y2+24,BLACK);
  display.drawLine(x2+42, y2+24, x4+42, y4+24,BLACK);
  display.drawLine(x4+42, y4+24, x1+42, y1+24,BLACK);
  

  display.drawLine(v1+42, w1+24, v3+42, w3+24,BLACK); // Draw Hours
  display.drawLine(v3+42, w3+24, v2+42, w2+24,BLACK);
  display.drawLine(v2+42, w2+24, v4+42, w4+24,BLACK);
  display.drawLine(v4+42, w4+24, v1+42, w1+24,BLACK);

  display.display();

  
  display.drawLine(x1+42, y1+24, x3+42, y3+24,WHITE); // Erase Minutes
  display.drawLine(x3+42, y3+24, x2+42, y2+24,WHITE);
  display.drawLine(x2+42, y2+24, x4+42, y4+24,WHITE);
  display.drawLine(x4+42, y4+24, x1+42, y1+24,WHITE);

  display.drawLine(v1+42, w1+24, v3+42, w3+24,WHITE); // Erase Hours
  display.drawLine(v3+42, w3+24, v2+42, w2+24,WHITE);
  display.drawLine(v2+42, w2+24, v4+42, w4+24,WHITE);
  display.drawLine(v4+42, w4+24, v1+42, w1+24,WHITE);

  
  //delay(800);
    }

}


void chime() {
  switch (hour2) {

    case 6:
    myDFPlayer.play(6);
    break;
    case 7:
    myDFPlayer.play(7);
    break;
    case 8:
    myDFPlayer.play(8);
    break;
    case 9:
    myDFPlayer.play(9);
    break;
    case 10:
    myDFPlayer.play(10);
    break;
    case 11:
    myDFPlayer.play(11);
    break;
    case 12:
    myDFPlayer.play(12);
    break;
    case 13:
    myDFPlayer.play(1);
    break;
    case 14:
    myDFPlayer.play(2);
    break;
    case 15:
    myDFPlayer.play(3);
    break;
    case 16:
    myDFPlayer.play(4);
    break;
    case 17:
    myDFPlayer.play(5);
    break;
    case 18:
    myDFPlayer.play(6);
    break;
    case 19:
    myDFPlayer.play(7);
    break;
    case 20:
    myDFPlayer.play(8);
    break;
    case 21:
    myDFPlayer.play(9);
    break;
    case 22:
    myDFPlayer.play(10);
    break;  
  }
}

Digital Display

Arduino
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <Ds1302.h>
#include <Adafruit_PCD8544.h>  // include adafruit PCD8544 (Nokia 5110) library
#include <LowPower.h>

SoftwareSerial mySoftwareSerial(3, 2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

// DS1302 RTC instance
Ds1302 rtc(6,4,5); // 
// Nokia 5110 LCD module connections CLK, DIN, D/C, CS, RST (opposite to the actual pin positions !!)
Adafruit_PCD8544 display = Adafruit_PCD8544(7,8,9,10,11);
const static char* WeekDays[] =
{
    "  Mon  ",
    " Tues  ",
    "  Wed  ",
    " Thurs ",
    "  Fri  ",
    "  Sat  ",
    "  Sun  "
};
 const static char* Months[] =
 {
  "Jan ",
  "Feb ",
  "Mar ",
  "Apr ",
  "May ",
  "Jun ",
  "Jul ",
  "Aug ",
  "Sep ",
  "Oct ",
  "Nov ",
  "Dec "
 };
  static uint8_t last_second = 0; 
  int hour2;
void setup() {
 //     Serial.begin(115200);
      display.begin(); // initialise the Nokia display
      display.clearDisplay();   // clears the screen and buffer      
      display.setContrast(50);
        
      mySoftwareSerial.begin(9600);
      myDFPlayer.begin(mySoftwareSerial);
      myDFPlayer.volume(15);
      rtc.init(); // initialize the RTC

      display.drawRect(0, 0, 84, 30, BLACK);
      display.drawRect(0, 29, 84, 12, BLACK);
  
}


void loop()
{

    // get the current time
    Ds1302::DateTime now;
    rtc.getDateTime(&now);

    if (last_second != now.second)
    {
//      Serial.println(hour2);
      if ((now.minute == 59) && (now.second == 40)) {
       hour2 = now.hour;
       hour2++;
//       Serial.println("Go to chime");
       chime();
     }
        last_second = now.second;

        display.setTextColor(BLACK);
        display.setTextSize(2);
        display.setCursor(6,10);
        if (now.hour <= 9) { //If Hour is single figures, put a 0 in front
        display.print("0");
        }
        display.print(now.hour);
        display.print(":");
     if (now.minute <= 9) {  //If Minute is single figures, put a 0 in front
        display.print("0");
     }
        display.print(now.minute);
  //      display.print(":");
        display.setTextSize(1); 
        if (now.second <= 9) {  //If Seconds is single figures, put a 0 in front
        display.print("0");
     } 
        display.print(now.second);

        
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print(" ");
        display.print(Months[now.month -1]);
        
        display.display();

        
        display.setTextColor(WHITE);
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print(" ");
        display.print(Months[now.month -1]);           
        
                
        
        display.setTextSize(2);
        display.setCursor(6,10);
     if (now.hour <= 9) {
        display.print("0");
    }
       display.print(now.hour);
       display.print(":");
     if (now.minute <= 9) {
       display.print("0");
  }
       display.print(now.minute);
  //     display.print(":");
       display.setTextSize(1);
     if (now.second <= 9) {
       display.print("0");
  } 
      display.print(now.second);
 
// No need to display the screen again
 
    }
  //  delay(100);
  LowPower.powerDown(SLEEP_250MS,ADC_OFF,BOD_OFF);
}

void chime() {
  switch (hour2) {

    case 6:
    myDFPlayer.play(6);
    break;
    case 7:
    myDFPlayer.play(7);
    break;
    case 8:
    myDFPlayer.play(8);
    break;
    case 9:
    myDFPlayer.play(9);
    break;
    case 10:
    myDFPlayer.play(10);
    break;
    case 11:
    myDFPlayer.play(11);
    break;
    case 12:
    myDFPlayer.play(12);
    break;
    case 13:
    myDFPlayer.play(1);
    break;
    case 14:
    myDFPlayer.play(2);
    break;
    case 15:
    myDFPlayer.play(3);
    break;
    case 16:
    myDFPlayer.play(4);
    break;
    case 17:
    myDFPlayer.play(5);
    break;
    case 18:
    myDFPlayer.play(6);
    break;
    case 19:
    myDFPlayer.play(7);
    break;
    case 20:
    myDFPlayer.play(8);
    break;
    case 21:
    myDFPlayer.play(9);
    break;
    case 22:
    myDFPlayer.play(10);
    break;  
  }
}

Analogue Clock face with nightly cuckoo

Arduino
Use arduino IDE to program your Nano
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <Ds1302.h>
#include <Adafruit_PCD8544.h>  // include adafruit PCD8544 (Nokia 5110) library

Adafruit_PCD8544 display = Adafruit_PCD8544(7,8,9,10,11); // CLK, DIN, D/C, CS, RST
SoftwareSerial mySoftwareSerial (3,2); // DFPlayer Mini RX Pin3 -> TX .. TX Pin2 -> RX
DFRobotDFPlayerMini myDFPlayer;

Ds1302 rtc(6,4,5);



static const unsigned char PROGMEM Big_Ben_3[] ={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFE, 0xD1, 0x0F, 0xFF, 0xFE, 0x7F, 0xF9, 0x05, 0x41,
0xFF, 0xFE, 0x63, 0xF0, 0x83, 0x42, 0x2F, 0xC6, 0x63, 0xDA, 0x05, 0x50, 0xBB, 0xC6, 0x6F, 0x8A,
0x51, 0x14, 0x25, 0xF6, 0x7F, 0x2D, 0x3F, 0xF9, 0x6A, 0xFE, 0x7E, 0x05, 0x83, 0x82, 0x50, 0x7E,
0x7C, 0x97, 0x07, 0x80, 0xA4, 0x3E, 0x7C, 0x2F, 0x83, 0x80, 0xE9, 0x5E, 0x78, 0x13, 0x87, 0x81,
0x10, 0x2E, 0x74, 0xA1, 0xC0, 0x02, 0x08, 0x1E, 0x73, 0x41, 0x80, 0x02, 0x05, 0x16, 0x7C, 0x81,
0x00, 0x00, 0x02, 0x6E, 0x47, 0x80, 0x00, 0x00, 0x02, 0xC2, 0x51, 0x80, 0x00, 0x00, 0x07, 0x16,
0x46, 0x60, 0x00, 0x00, 0x0F, 0x46, 0x22, 0x30, 0x00, 0x00, 0x18, 0x88, 0x08, 0x00, 0x00, 0x00,
0x00, 0xA0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x60, 0x04, 0x00,
0x00, 0x00, 0x00, 0x40, 0x74, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x27, 0xC0, 0x00, 0x00, 0x07, 0xC0,
0xFF, 0x40, 0x00, 0x00, 0x07, 0xFE, 0x27, 0xC0, 0x00, 0x00, 0x07, 0xC0, 0x74, 0x00, 0x00, 0x00,
0x00, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x54, 0x00, 0x00, 0x00, 0x00, 0x60, 0x04, 0x20,
0x00, 0x00, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x00, 0x10, 0xA0, 0x23, 0xF0, 0x00, 0x00, 0x1C, 0x88,
0x47, 0xF8, 0x00, 0x00, 0x1F, 0x42, 0x53, 0xF0, 0x00, 0x00, 0x1F, 0x12, 0x47, 0xE0, 0x00, 0x00,
0x07, 0xC6, 0x7C, 0x81, 0x00, 0x00, 0x02, 0x66, 0x73, 0x43, 0x80, 0x02, 0x05, 0x9E, 0x74, 0xA3,
0xC0, 0x03, 0x08, 0x4E, 0x78, 0x17, 0x83, 0x83, 0x10, 0x1E, 0x7C, 0x2F, 0x83, 0x81, 0xE9, 0x3E,
0x7C, 0x97, 0x03, 0x81, 0xA4, 0x7E, 0x7E, 0x15, 0x83, 0x82, 0xD0, 0xFE, 0x7F, 0xAD, 0x3F, 0xFD,
0x49, 0xFE, 0x63, 0xC8, 0x51, 0x14, 0x23, 0xC6, 0x63, 0xF2, 0x05, 0x50, 0xAF, 0xC6, 0x6B, 0xF8,
0x87, 0x42, 0x1F, 0xD6, 0x7F, 0xFE, 0x05, 0x50, 0xFF, 0xFE, 0x00, 0x00, 0x81, 0x01, 0x00, 0x00
};

  static uint8_t last_second = 0;
  static uint8_t last_minute = 0;
  int hour2;

void setup()
{
  display.begin(); // initialise the Nokia display 
  display.clearDisplay();   // clears the screen and buffer      
  display.setContrast(50);

  mySoftwareSerial.begin(9600);
  myDFPlayer.begin(mySoftwareSerial);
  myDFPlayer.volume(15);
  rtc.init(); // Initialise the Real Time Clock

}

void loop()
{
  
    Ds1302::DateTime now; //Get the current time
    rtc.getDateTime(&now);
    if(last_second != now.second) {
      if ((now.minute == 59) && (now.second == 40)) {
        hour2 = now.hour +1;
        chime();
      }
      last_second = now.second;
    }
    if (last_minute != now.minute) {
      last_minute = now.minute;
      
  float x1, y1, x2, y2, x3, y3, x4, y4,v1 ,v2 ,v3 ,v4 ,w1 ,w2 ,w3 ,w4, Am,Ah;            
  Am = (now.minute * 6);
  Ah = (now.hour * 30) + (now.minute * 0.5);

  x1=25*sin(Am*0.0175); // Co-ords For Minute Hand
  y1=25*-cos(Am*0.0175);
  x2=3*sin(Am*0.0175);
  y2=3*-cos(Am*0.0175);
  x3=10*sin((Am+8)*0.0175);
  y3=10*-cos((Am+8)*0.0175);
  x4=10*sin((Am-8)*0.0175);
  y4=10*-cos((Am-8)*0.0175);

  v1=20*sin(Ah*0.0175); // Co-ords For Hour Hand
  w1=20*-cos(Ah*0.0175);
  v2=3*sin(Ah*0.0175);
  w2=3*-cos(Ah*0.0175);
  v3=8*sin((Ah+14)*0.0175);
  w3=8*-cos((Ah+14)*0.0175);
  v4=8*sin((Ah-14)*0.0175);
  w4=8*-cos((Ah-14)*0.0175);
  
  display.drawBitmap(18,0,Big_Ben_3,48,48,BLACK); // Display Clock Face Bitmap
  display.drawCircle(42,24,2,BLACK); // Draw Centre Circle
  
  display.drawLine(x1+42, y1+24, x3+42, y3+24,BLACK); // Draw Minutes
  display.drawLine(x3+42, y3+24, x2+42, y2+24,BLACK);
  display.drawLine(x2+42, y2+24, x4+42, y4+24,BLACK);
  display.drawLine(x4+42, y4+24, x1+42, y1+24,BLACK);
  

  display.drawLine(v1+42, w1+24, v3+42, w3+24,BLACK); // Draw Hours
  display.drawLine(v3+42, w3+24, v2+42, w2+24,BLACK);
  display.drawLine(v2+42, w2+24, v4+42, w4+24,BLACK);
  display.drawLine(v4+42, w4+24, v1+42, w1+24,BLACK);

  display.display();

  
  display.drawLine(x1+42, y1+24, x3+42, y3+24,WHITE); // Erase Minutes
  display.drawLine(x3+42, y3+24, x2+42, y2+24,WHITE);
  display.drawLine(x2+42, y2+24, x4+42, y4+24,WHITE);
  display.drawLine(x4+42, y4+24, x1+42, y1+24,WHITE);

  display.drawLine(v1+42, w1+24, v3+42, w3+24,WHITE); // Erase Hours
  display.drawLine(v3+42, w3+24, v2+42, w2+24,WHITE);
  display.drawLine(v2+42, w2+24, v4+42, w4+24,WHITE);
  display.drawLine(v4+42, w4+24, v1+42, w1+24,WHITE);

  
  //delay(800);
    }

}


void chime() {
  switch (hour2) {

    case 6:
    myDFPlayer.play(6);
    break;
    case 7:
    myDFPlayer.play(7);
    break;
    case 8:
    myDFPlayer.play(8);
    break;
    case 9:
    myDFPlayer.play(9);
    break;
    case 10:
    myDFPlayer.play(10);
    break;
    case 11:
    myDFPlayer.play(11);
    break;
    case 12:
    myDFPlayer.play(12);
    break;
    case 13:
    myDFPlayer.play(1);
    break;
    case 14:
    myDFPlayer.play(2);
    break;
    case 15:
    myDFPlayer.play(3);
    break;
    case 16:
    myDFPlayer.play(4);
    break;
    case 17:
    myDFPlayer.play(5);
    break;
    case 18:
    myDFPlayer.play(6);
    break;
    case 19:
    myDFPlayer.play(7);
    break;
    case 20:
    myDFPlayer.play(8);
    break;
    case 21:
    myDFPlayer.play(9);
    break;
    case 22:
    myDFPlayer.play(22);
    break;
    case 23:
    myDFPlayer.play(23);
    break;
    case 24:
    myDFPlayer.play(24);
    break;
    case 1:
    myDFPlayer.play(13);
    break;
    case 2:
    myDFPlayer.play(14);
    break;
    case 3:
    myDFPlayer.play(15);
    break;     
    case 4:
    myDFPlayer.play(16);
    break;     
    case 5:
    myDFPlayer.play(17);
    break;      
  }
}

Digital Clock face with nightly cuckoo sounds

Arduino
Use this code for digital display with cuckoo sounds. Program using Arduino IDE
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <Ds1302.h>
#include <Adafruit_PCD8544.h>  // include adafruit PCD8544 (Nokia 5110) library
#include <LowPower.h>

SoftwareSerial mySoftwareSerial(3, 2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

// DS1302 RTC instance
Ds1302 rtc(6,4,5); // 
// Nokia 5110 LCD module connections CLK, DIN, D/C, CS, RST (opposite to the actual pin positions !!)
Adafruit_PCD8544 display = Adafruit_PCD8544(7,8,9,10,11);
const static char* WeekDays[] =
{
    "  Mon  ",
    " Tues  ",
    "  Wed  ",
    " Thurs ",
    "  Fri  ",
    "  Sat  ",
    "  Sun  "
};
 const static char* Months[] =
 {
  "Jan ",
  "Feb ",
  "Mar ",
  "Apr ",
  "May ",
  "Jun ",
  "Jul ",
  "Aug ",
  "Sep ",
  "Oct ",
  "Nov ",
  "Dec "
 };
  static uint8_t last_second = 0; 
  int hour2;
void setup() {
 //     Serial.begin(115200);
      display.begin(); // initialise the Nokia display
      display.clearDisplay();   // clears the screen and buffer      
      display.setContrast(50);
        
      mySoftwareSerial.begin(9600);
      myDFPlayer.begin(mySoftwareSerial);
      myDFPlayer.volume(15);
      rtc.init(); // initialize the RTC

      display.drawRect(0, 0, 84, 30, BLACK);
      display.drawRect(0, 29, 84, 12, BLACK);
  
}


void loop()
{

    // get the current time
    Ds1302::DateTime now;
    rtc.getDateTime(&now);

    if (last_second != now.second)
    {
//      Serial.println(hour2);
      if ((now.minute == 59) && (now.second == 40)) {
       hour2 = now.hour;
       hour2++;
//       Serial.println("Go to chime");
       chime();
     }
        last_second = now.second;

        display.setTextColor(BLACK);
        display.setTextSize(2);
        display.setCursor(6,10);
        if (now.hour <= 9) { //If Hour is single figures, put a 0 in front
        display.print("0");
        }
        display.print(now.hour);
        display.print(":");
     if (now.minute <= 9) {  //If Minute is single figures, put a 0 in front
        display.print("0");
     }
        display.print(now.minute);
  //      display.print(":");
        display.setTextSize(1); 
        if (now.second <= 9) {  //If Seconds is single figures, put a 0 in front
        display.print("0");
     } 
        display.print(now.second);

        
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print(" ");
        display.print(Months[now.month -1]);
        
        display.display();

        
        display.setTextColor(WHITE);
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print(" ");
        display.print(Months[now.month -1]);           
        
                
        
        display.setTextSize(2);
        display.setCursor(6,10);
     if (now.hour <= 9) {
        display.print("0");
    }
       display.print(now.hour);
       display.print(":");
     if (now.minute <= 9) {
       display.print("0");
  }
       display.print(now.minute);
  //     display.print(":");
       display.setTextSize(1);
     if (now.second <= 9) {
       display.print("0");
  } 
      display.print(now.second);
 
// No need to display the screen again
 
    }
  //  delay(100);
  LowPower.powerDown(SLEEP_250MS,ADC_OFF,BOD_OFF);
}

// Chime Routine 6am - 9pm = Westminster Chime
//               10pm - 5am = Cuckoo

void chime() {
  switch (hour2) {

    case 6:
    myDFPlayer.play(6);
    break;
    case 7:
    myDFPlayer.play(7);
    break;
    case 8:
    myDFPlayer.play(8);
    break;
    case 9:
    myDFPlayer.play(9);
    break;
    case 10:
    myDFPlayer.play(10);
    break;
    case 11:
    myDFPlayer.play(11);
    break;
    case 12:
    myDFPlayer.play(12);
    break;
    case 13:
    myDFPlayer.play(1);
    break;
    case 14:
    myDFPlayer.play(2);
    break;
    case 15:
    myDFPlayer.play(3);
    break;
    case 16:
    myDFPlayer.play(4);
    break;
    case 17:
    myDFPlayer.play(5);
    break;
    case 18:
    myDFPlayer.play(6);
    break;
    case 19:
    myDFPlayer.play(7);
    break;
    case 20:
    myDFPlayer.play(8);
    break;
    case 21:
    myDFPlayer.play(9);
    break;
    case 22:
    myDFPlayer.play(22);
    break;
    case 23:
    myDFPlayer.play(23);
    break;
    case 24:
    myDFPlayer.play(24);
    break;
    case 1:
    myDFPlayer.play(13);
    break;
    case 2:
    myDFPlayer.play(14);
    break;
    case 3:
    myDFPlayer.play(15);
    break;     
    case 4:
    myDFPlayer.play(16);
    break;     
    case 5:
    myDFPlayer.play(17);
    break;    
  }
}

Credits

stevie135s

stevie135s

25 projects • 11 followers

Comments