Ajith Kumar B
Published © GPL3+

Multi-functional Clock System with Two Pico-2040 Based Units

"Ultimate Pico2040 Digital Clock featuring Big Display, Scrolling Messages, Chimes, Voice Time Announcement, MP3 Player and More!"

IntermediateFull instructions provided6 hours2,405

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×2
DS1307 RTC
×2
SEVEN SEGMENT DISPLAY 2 .3 INCH
×4
SEVEN SEGMENT DISPLAY 1 INCH
×2
MAX 7219 4 IN 1 LED MATRIX DISPLAY
×4
CD 4504 IC
×1
ULN 2803 IC
×1
BD 139 TRANSISTER
×6
Linear Regulator (7805)
Linear Regulator (7805)
×2
3.3 V REGULATOR MODULE
×2
TSOP-1838 Infrared Sensor
×1
MICRO SD CARD READER MODULE
×1
DF Player Mini MP3 player module
×1
DHT 11 TEMERATURE AND HUMIDITY SENSOR MODULE
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
PAM 8403
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

CLOCK1

CIRCUIT DIAGRAM OF FIRST CLOCK

CLOCK2

CIRCUIT DIAGRAM OF SECOND CLOCK

I2C CONNECTION

LINKING OF CLOCKS WITH I2C

DIFFERENT COMPONETS

Code

CODE FOR CLOCK-1

Arduino
/* *************************************************************
CODE FOR CLOCK -1
UPDATED ON 01 june 23
 
****************************************************************
*/
#include "RTClib.h"
#include<Wire.h>
#include <IRremote.hpp>
#define RECEIVER_PIN 9
RTC_DS1307 RTC;
IRrecv receiver(RECEIVER_PIN);
int digit1 = 16;
int digit2 = 13;
int digit3 = 11;
int digit4 = 12;
int digit6 = 17;
int digit5 = 18;
int segA = 7;
int segB = 8;
int segC = 2;
int segD = 5;
int segE = 21;
int segF = 6;
int segG = 3;
int Dot = 10;
int Mode;
int aset;
int dtt2;
int setmode = 0;
int dispoff_flag = 1;
int keyx;
int count = 0;
int keysum;
int keysum1;
int keyvalid;
int set_mode = 0;
int time_set  = 0 ;
int alm_set;
int charshow1;
int charshow2;
int char1;
int char2                                                     ;
int char3;
int char4;
int char5;
int char6;
int Hrset;
int oldHrset;
int Ulset;
int oldUlset;
int timp2;
int typeset  = 0;
int tempC =0;
int Alm_P_off;
int pc=0;
int kn=0;
int enterkeypress=0;
int retnkey=0;
int date_set;
int Snset;
int oldSnset;
int old_Alm_P_off;
unsigned long key_value = 0;
bool datesetflag;
bool set_start =0;
bool power_on=1;
String receive_string;
void ShowNumber(int );
void displaychar(int , int);
void Light_HR_MIN(int);
void displaysecond(int );
void IRR(int  , int);
void big_char(int , int ,int , int );
void sentdata2pico(String);
void recivdatapico(void);
void DT_SET( int ,  int );


//====================================================================================================
void setup() {
  Serial.begin(9600);
  Serial1.begin( 9600);
  Wire1.setSDA(14);
  Wire1.setSCL(15);
  Wire.setSDA(0);
  Wire.setSCL(1);
  RTC.begin(&Wire1) ; 
  Wire1.begin();
  Wire.begin();
  RTC.begin(&Wire1);
  DateTime now = RTC.now();
 //RTC.adjust(DateTime(__DATE__, __TIME__));// for setting clock   remove 
  //after setting clock again put // on the line and upload once more
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(Dot, OUTPUT);
  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  pinMode(digit5, OUTPUT);
  pinMode(digit6, OUTPUT);
  digitalWrite(Dot, LOW); 
  digitalWrite(5, LOW); 
// ..................WELCOME DISPLAY-------------------------------------

for (int p =3 ; p > 0  ; p--) {
     for (int i =80 ; i > 0  ; i--) {
     
      big_char(10,19,11,1) ;
      displaychar(33,33) ;
  }
      ShowNumber(10);
      delay(300);
 }
 IrReceiver.begin(9);  // enable the receiver
//--------auto syncronising on power on---------------------------------------------------------------


}
//========================================END OF SETUP================================================

void loop() { // ==========================VOID LOOP==================================================
DateTime now = RTC.now();
if (power_on==1){
 delay (2000); 
recivdatapico();
oldHrset=Hrset;
oldSnset=Snset;
old_Alm_P_off=Alm_P_off;
power_on =0 ;
}

//====================================DISPLAY OFF FUNCTION.===========================================
  if ( dispoff_flag == 0) {
    digitalWrite(digit1, LOW);
    digitalWrite(digit2, LOW);
    digitalWrite(digit3, LOW);
    digitalWrite(digit4, LOW);
    digitalWrite(digit5, LOW);
    digitalWrite(digit6, LOW);
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    digitalWrite(Dot, LOW);

  }
else{

//=================================TEMPERATURE DISPLAY ===========================================

 if (Mode == 4)
 {
 for (int i = 8 ; i > 0  ; i--) {
      Light_HR_MIN(tempC);
      displaychar(16 , 15) ;
   }
}
 else{}
 
 //---------------------------------------ALARM PERMANET OFF------------------------------------------   
   
if (Mode ==8){
if(set_start == 0){
 sentdata2pico("a") ;
}
     set_start=1;
     if (Alm_P_off == 0) char4=17;
     else   char4=18;
     for (int i = 8 ; i > 0  ; i--) {
     big_char(11,12,0,char4) ;
     ShowNumber(10);
 }
}
else{}
 if (Mode ==8 &&  enterkeypress ==1)  {
  Mode =0;  
  enterkeypress =0; 
  set_start=0;
  old_Alm_P_off=Alm_P_off;
  pc=0;
  String ap;
  ap = "N"+String(Alm_P_off);
  sentdata2pico(ap);
  delay(100);
 }
 else{}   
 
//--------------------------------------HOUR CHIME SETTING -------------------------------------------   
       
if (Mode ==9){
if(set_start == 0){
  sentdata2pico("h") ;
}
set_start=1;

     if (Hrset == 1){
      char1=16;
      char2=19;
      char3=26;
      char4=26;
      char5=0;
      char6=18;
        }
 if (Hrset == 2){
       char1=26;
       char2=26;
       char3=27;
       char4=12;
       char5=0;
       char6=18;
      
        }
  if (Hrset == 3){
       char1=29;
       char2=30;
       char3=13;
       char4=28;
       char5=0;
       char6=18;
        }
  if (Hrset == 4){
       char1=16;
       char2=19;
       char3=26;
       char4=26;
       char5=18;
       char6=13;
        }
 if (Hrset == 5){
      char1=26;
      char2=26;
      char3=27;
      char4=12;
      char5=18;
      char6=13;
       }
if (Hrset == 6){
      char1=29;
      char2=30;
      char3=13;
      char4=28;
      char5=18;
      char6=13;
       }
if (Hrset == 7){
      char1=29;
      char2=30;
      char3=13;
      char4=28;
      char5=0;
      char6=17;
       }
     for (int i = 8 ; i > 0  ; i--) {
     big_char(char1,char2,char3,char4) ;
     ShowNumber(10);
     displaychar(char6,char5);
 }
}
else{}
 if (Mode ==9 &&  enterkeypress ==1)  {
 Mode=0;
 enterkeypress =0; 
 oldHrset=Hrset;  
set_start=0;
String hp = "R"+String(Hrset);

sentdata2pico(hp);
delay(100);



kn=0;
 
 }
 else{}   
//--------------------VOLUME SETTING-----------------------------------------------------------------
 if (Mode ==12){
if(set_start == 0){
 sentdata2pico("s") ;
}
set_start=1;

     if (Snset>= 33  || Snset== 0)  Snset=0;    
     else{}   
     for (int i = 8 ; i > 0  ; i--) {
     big_char(14,18,24,26) ;
     ShowNumber(10);
     displaysecond(Snset);
 }
}
  else{}
 if (Mode ==12 &&  enterkeypress ==1)  {
   Mode=0;
   enterkeypress =0; 
   oldSnset=Snset;
   set_start=0;
String hq = "S"+String(Snset);
sentdata2pico(hq);
kn=0;
 }
 else{}   

//------- sound volume end---------------------------------------------------------------------------

//=================================REAL TIME DISPLAY=================================================

    if (Mode == 0) {
      DateTime now = RTC.now();
      int tim = (now.hour());
      if (tim >  12) {
        tim = tim - 12;
      }
      else;
      if (tim ==  0) {
        tim = 12;
      }
      else;
      int timp = (tim * 100 + now.minute());
      int timp1 = now.second();
      timp2 = (now.hour() + now.minute());
// For Digits display
      for (int i = 2
                   ; i > 0  ; i--) {
      Light_HR_MIN(timp);
      displaysecond(timp1);
      }
    }
    else {}
}

// ---------------end of sync tine every hour---------------------------------------------------------
//-----------------------------------------------------------------------------------------------------
  //===============================CHECKING REMOTE PESSING============================================

  if  (IrReceiver.decode()) {
//Serial.println("KEY RESULT");
//Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);

//=================================TEMPERATURE  DISPLAY KEY  PRESSED==================================
    if (IrReceiver.decodedIRData.decodedRawData == 0xEC13FF00 ) { 
  Mode = 4;
recivdatapico();
delay(200);
//timesync("t");
     }
    else{
      receiver.resume();
  }

//==================date display key pressed=========================================================

 if (IrReceiver.decodedIRData.decodedRawData == 0xEA15FF00 ) {
datesetflag=0;
if(set_start == 0){
 //Serial.println("printing d"); 
 sentdata2pico("d") ;
}
set_start=1;
 DateTime now = RTC.now();
  int hj  =  (now.day()*100)+now.month();
     for (int i = 2 ; i > 0  ; i--) {
        Light_HR_MIN(hj);
       displaysecond(now.year()%100);
  }
     Mode =15; 
     sentdata2pico("U");
     typeset = 3;
     setmode = 1;
  int ya=now.day();
  int yb=now.month();
  int yc= now.year();       
  int datest = ((ya*10000)+(yb* 100) + (yc%100));
  receiver.resume();
  DT_SET (datest , 3);
  if (datesetflag ==1){
  receiver.resume();
  int hr=now.hour();
  int mnn = now.minute();
  int scs =  now.second();     
  int mnt = (date_set/100)%100;
  int dy  = date_set/ 10000; 
  int  yr = 2000+(date_set%100);
      
RTC.adjust(DateTime(yr,mnt,dy, hr, mnn, scs));
//---- date set for sending to other board---------------------------------------------------------
String hr1= String (hr);
if(hr/10 ==0) hr1=("0"+hr1);
if(hr ==0) hr1=("00");
String mn1= String(mnn);
if(mnn/10 ==0) mn1=("0"+mn1);
if(mnn ==0) mn1=("00");
String mnt1=String(mnt);
if(mnt/10 ==0) mnt1=("0"+mnt1);
if(mnt ==0) mnt1=("00");
String dy1=String(dy);
if(dy/10 ==0) dy1=("0"+dy1);
String yr1=String(yr);
 int scc =  now.second();   
String scc1=String(scc);
if(scc/10 ==0) scc1=("0"+scc1);
if(scc ==0) scc1=("00");

String tk = "T"+yr1+mnt1+dy1+hr1+mn1+scc1 ;
sentdata2pico("Z");
sentdata2pico(tk);
//sentdata2pico("Z");
delay(100);

datesetflag=0;
Mode = 0;
 set_start=0;
  }
else{
 receiver.resume(); 
  }
 }
//=============================================RETURN KEY PRESSED=====================================
 if (IrReceiver.decodedIRData.decodedRawData == 0xEB14FF00  ) {

          typeset = 0;
          Mode = 0;
          enterkeypress ==0;
          Alm_P_off =old_Alm_P_off;
          Hrset=oldHrset;
          Snset=oldSnset;
          kn=0;
          pc=0; 
          set_start=0;
          retnkey == 1;           
 }
 //=================================ENTER KEY PRESSED=================================================
 if (IrReceiver.decodedIRData.decodedRawData == 0xF00FFF00  ) enterkeypress=1;
 else  enterkeypress=0;
  
 //=========================ALRM PERMANENT OFF  key pressed===========================================
  
        if (IrReceiver.decodedIRData.decodedRawData == 0xF906FF00) { 
      Mode=8;
        Alm_P_off =  abs(Alm_P_off - 1);
        if(pc==0) Alm_P_off = old_Alm_P_off ;  
        else{} 
        pc= pc+1;
        delay(500);
        }
        else{}

 //=========================HOUR CHIME mode KEY PRESSED=============================================
    
       if (IrReceiver.decodedIRData.decodedRawData == 0xF10EFF00 ) { 
       Mode=9;  
       kn=kn+1;
       Hrset = Hrset+1;
       if(Hrset>=8)Hrset=1;
       else{}
       if (kn ==1)
      {Hrset=oldHrset;
       }
       }   
       else{}
 
//==========================ALARM SET KEY PRESSED=====================================================
      if (IrReceiver.decodedIRData.decodedRawData == 0xF807FF00  ) {  
   
      if(set_start == 0){
   //   Serial.println("printing n"); 
      sentdata2pico("n") ;
}
      set_start=1;
      typeset = 1;
      setmode = 0;
     Mode = 1;
      keysum1 = alm_set;
      int oldalm=alm_set;
      receiver.resume();
      IRR( keysum1 , 1);
      alm_set = keysum1;
      if (retnkey == 1){
      alm_set=oldalm;
      retnkey == 0;
}
else{
      String al;
      al = "A"+ String(alm_set);
      sentdata2pico(al);
      aset = 6;
      typeset = 0;
    Mode == 0;
      }    
      }   

// ==============TIME SET KEY PRESSED============================================================
          
      if (IrReceiver.decodedIRData.decodedRawData == 0xED12FF00 ) {
      if(set_start == 0){
      sentdata2pico("t"); 
       delay(100);
}
       set_start=1;
       typeset = 2;
       setmode = 1;
       Mode = 1;
      DateTime now = RTC.now();
      dtt2 = now.hour() * 100 + now.minute();
      int Y1=now.year();
      int M1 = now.month();
      int D1 =now.day();
      receiver.resume();
      IRR( dtt2 , 2);
//---------------------
if (retnkey ==1){
      Mode = 0;
      enterkeypress ==0;
      retnkey == 0;   
}
 if (enterkeypress ==1){
      receiver.resume();
      int newtime = keysum1;
      int h1 = newtime / 100;
      int m1 = newtime % 100;
      //int s1=now.second();
      set_start=0;
  
//========================
      String hh1= String (h1);
      if(h1/10 ==0) hh1=("0"+hh1);
      if(h1 ==0) hh1=("00");
      String mm1= String (m1);
      if(m1/10 ==0) mm1=("0"+mm1);
      if(m1 ==0) mm1=("00");
      String YY1= String(Y1);
      String MM1= String(M1);
      if(M1/10 ==0) MM1=("0"+MM1);
      if(M1 ==0) MM1=("00");
      String DD1= String(D1);
      if(D1/10 ==0) DD1=("0"+DD1);
      if(D1 ==0) DD1=("00");   
      int s1 =  now.second();   
      String ss1=String(s1);
      if(s1/10 ==0) ss1=("0"+ss1);
      if(s1 ==0) ss1=("00");
      String tr3 = "T"+ YY1+MM1+DD1+hh1+mm1+ss1;
      RTC.adjust(DateTime(Y1,M1,D1, h1, m1, s1));
      set_start=0;
      enterkeypress=0;
    // sentdata2pico("Z");
      sentdata2pico(tr3);
   //   sentdata2pico("Z");
      delay(100);
  }
      else{}
  }

//=======================ALARM OFF KEY PRESSED===================================================
         
      if (IrReceiver.decodedIRData.decodedRawData == 0xE916FF00  ) {
        sentdata2pico("O");
  }
      else {
      receiver.resume();
      }

//====================Sound set KEY PRESSED======================================================= 

    if (IrReceiver.decodedIRData.decodedRawData == 0xF609FF00 ) {  
      delay(100);
     Mode=12;  
      kn=kn+1;
      Snset = Snset+3;
      if(Snset>=33)Snset=0;
      else{}
    if (kn ==1)
      {Snset=oldSnset;
}
      else{}
 }
   
 //============DISPLAY ON/ OFF) KEY PRESSED=====================================================

 if (IrReceiver.decodedIRData.decodedRawData == 0xF30CFF00 ) { 
      dispoff_flag =  abs(dispoff_flag - 1);
      String di;
      di = "V"+String(dispoff_flag);
       sentdata2pico("Z0");
      sentdata2pico(di);
      delay(100);
   }
  else {
      receiver.resume();
      }
    }
}
//================================END OD REMOTE KEY PRESS CHECK===================================
 
//==========================END OF MAIN LOOP VOID()================================================


//=============================SUB PROGRAMMES=======================================================


  void IRR( int keysum ,  int typeset ) {
     while (typeset != 0) {
      if (typeset == 1) {
      for (int i = 8 ; i > 0  ; i--) {

          Light_HR_MIN(keysum);
          displaychar(12 , 11) ;
          Light_HR_MIN(keysum);
        }
      }
      else {}

          if (typeset == 2) {
          for (int i = 8 ; i > 0  ; i--) {
          Light_HR_MIN(keysum);
          displaychar(13 , 14) ;
          Light_HR_MIN(keysum);
        }
      }
      else {}

      if  (IrReceiver.decode()) {

        switch (IrReceiver.decodedIRData.decodedRawData) {

          case 0xEB14FF00 ://------------------------------RETURN KEY PRESSED---------------------------
            typeset = 0;
            Mode = 0;
            retnkey=1;
            set_start=0;
            enterkeypress=0;
            break;
 
//-----------------------------------------------------------------------------------------------------

          case 0xF00FFF00 :  //  -----------------------PRESSING ENTER KEY----------------------------------

              if (  keysum / 10 == 0 && keysum >= 60 ) {
              count = 0;
              keysum = 0;
              keyvalid = 0;
              set_start=0;
              enterkeypress=1;
            }
            else {}

            if ( keysum / 100 == 0 && keysum >= 60) {
              count = 0;
              keysum = 0;
              keyvalid = 0;
            }
            else {}
              if ( keysum / 100 == 0 && keysum / 1000 == 0    &&   keysum % 100  >= 60   ) {
              count = 0;
              keysum = 0;
              keyvalid = 0;
            }
            else {}

            if ( keysum / 10000 == 0    &&  keysum % 100  >= 60  ) {
              count = 0;
              keysum = 0;
              keyvalid = 0;
            }
            else { }
            if (keyvalid == 1) {
              typeset = 0;
             Mode = 0;
             retnkey =0;
             enterkeypress=1;
            }
            else {}
            break ;
//-------------------------
          case 0xEE11FF00:  //........KEY 1.........
            keyx = 1;
            keysum = keysum * 10 + keyx;
            count = count + 1;
            break;

 case 0xEE01FF00:  //........KEY 1.........
            keyx = 1;
            keysum = keysum * 10 + keyx;
            count = count + 1;
            break;
       
          case 0xF708FF00:   //........KEY 2.....
            keyx = 2;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break;

case 0xFF10EF:   //........KEY 2.....
            keyx = 2;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break;

          
          case 0xEF10FF00:   //........KEY 3 ....
            keyx = 3;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break;

case 0xFF08F7:   //........KEY 3 ....
            keyx = 3;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break;
            
case 0xFF00FF00:    //........KEY 4.....
            keyx = 4;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;

 case 0xFF00FF:    //........KEY 4.....
            keyx = 4;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
          
          case 0xFE01FF00:   //........KEY 5.....
            keyx = 5;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
 case 0xFF807F:   //........KEY 5.....
            keyx = 5;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
          
 case 0xFD02FF00:     //........KEY 6.....
            keyx = 6;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
            
 case 0xFF40BF:     //........KEY 6.....
            keyx = 6;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
        
case 0xFC03FF00:     //........KEY 7.....
            keyx = 7;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;

case 0xFFC03F:     //........KEY 7.....
            keyx = 7;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
            
case 0xFB04FF00:    //........KEY 8.....
            keyx = 8;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
case 0xFF20DF:    //........KEY 8.....
            keyx = 8;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
   
case 0xFA05FF00:    //........KEY 9.....
            keyx = 9;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;

case 0xFFA05F:    //........KEY 9.....
            keyx = 9;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
        
case 0xF50AFF00:     //........KEY 0.....
            keyx = 0;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;

 case 0xFF50AF:     //........KEY 0.....
            keyx = 0;
            count = count + 1;
            keysum = keysum * 10 + keyx;
            break ;
        }  
  //--------------------------------------------------------------------------------------------------
        if (count >= 5) {
          count = 0;
          keysum = 0;
        }
        else {}

        if (keysum >= 2400) {
          keysum = 0;
          count = 0;
        }
        else {}

        if (keysum <= 0) {
          keysum = 0;
          count = 0;
        }
        else {}

        key_value = IrReceiver.decodedIRData.decodedRawData;
        keyvalid = 1;
        keysum1 = keysum;

        if (typeset == 1) {
          alm_set = keysum;
        }
        else {}
        if (typeset == 2) {
          time_set = keysum;
        }
        else {}
        delay(50);
        receiver.resume();
    }
    }
    }
  //==================================================================================================
  void Light_HR_MIN(int toDisplay) {
    #define BRIGHTNESS  1000
    #define DIGIT_ON  HIGH
    #define DIGIT_OFF  LOW
    int hrr = toDisplay / 100;
    if (Mode == 1)
    { digitalWrite(digit5, LOW);
      digitalWrite(digit6, LOW);
    }
    else {}

    for (int digit = 4 ; digit > 0 ; digit--) {
       switch (digit) {

        case 1:
          if (hrr < 10  && hrr != 0 )
          {
            digitalWrite(digit1, DIGIT_OFF);
          }
          else {
            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;
      }
         ShowNumber(toDisplay % 10);
         toDisplay /= 10;
         delayMicroseconds(BRIGHTNESS);
         ShowNumber(10);
         //Turn off all digits
         digitalWrite(digit1, DIGIT_OFF);
         digitalWrite(digit2, DIGIT_OFF);
         digitalWrite(digit3, DIGIT_OFF);
         digitalWrite(digit4, DIGIT_OFF);
    }
  }

  //==================================================================================================
  void ShowNumber(int numberToDisplay) {

#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;
      case 10: //... FOR ALL DISP OFF
        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;

      case 11:  //------FOR SHOWING A
        digitalWrite(segA, SEGMENT_ON);
        digitalWrite(segB, SEGMENT_ON);
        digitalWrite(segC, SEGMENT_ON);
        digitalWrite(segD, SEGMENT_OFF);
        digitalWrite(segE, SEGMENT_ON);
        digitalWrite(segF, SEGMENT_ON);
...

This file has been truncated, please download it to see its full contents.

CODE FOR CLOCK 2

Arduino
/*CODE FOR CLOCK-2
*/
  #include <SPI.h>
  #include <RP2040_SD.h>
  #include <MD_Parola.h>
  #include <MD_MAX72xx.h>
  #include <Wire.h>
  #include "NewPing.h"
  #include "DHT.h"
  #include <RTClib.h>
  #include "DFRobotDFPlayerMini.h"
  #define DHTPIN 11
  #define DHTTYPE DHT11
  #define MAX_DEVICES 8
  #define CS_PIN 9
  #define DATA_PIN 7
  #define CLK_PIN 6
  #define SOUND_VELOCITY 0.034
  #define TRIGGER_PIN 22
  #define ECHO_PIN 21
  #define MAX_DISTANCE 400 
  #define HARDWARE_TYPE MD_MAX72XX::FC16_HW  
  NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
  RTC_DS1307 rtc;
  DHT dht(DHTPIN, DHTTYPE);
  MD_MAX72XX *pM;
  MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
  DFRobotDFPlayerMini myDFPlayer;
  void sdfilelines(void);
  void sdsingleline(int);
  void disptime(int);
  void anim(void);
  void mp3play(int  , int, int);
  void timespeak(void);
  void mng_evg_song_play(int, int);
  void checkstatus(void);
  void ultrasound(void);
  void sd_datastor(String);
  void line1(void );
  void Temperature(void);
//-----------------------------------------
  int mrg_wish_hr = 4; int mrg_wish_min = 15;
  int mngsong_hr = 6; int mngsong_min = 30;
  int evgsong_hr = 18; int evgsong_min = 3;
//------------------------------------------
  File myFile;
  String displine;
  String sdfile ;
  String lin;
  String lin1;
  String spos;
  String L;
  String data_string;
  String message1 = "Good Morning";
  String message2 = "Good After noon";
  String message3 = "Good Evening";
  String message4 = "Good Night";
  String message;
  char care;
  char R;
  char song;
  long duration;
  bool ch_stat = 0;
  bool hr_onoff;
  bool ul_onoff;
  bool lin_stop = 0;
  float humid;
  float heat;
  float dist_cm;
  int Alm_time = 06;
  int chimeblk=0;
  int alhr ;
  int almn;
  int I = 0 ;
  int lineno;
  int k;
  int totline;
  int mpos;
  int ps[800];
  int dely = 1000;
  int Tempr;
  int randtotline;
  int snd_block_start =22; int snd_block_end =4;
  int rr = 1;
//--variables for handshaking-----
  int Disp_on;
  int snoozon;
  int Almoff  = 0;
  int ALM_time;
  int Hr_status;
  int Alm_Poff;
  int Snd_vol;
  int req_no=1;
//---------------------------------------------------------------------------------
  void setup()
  {
  Wire1.setSDA(14);
  Wire1.setSCL(15);
  Wire.setSDA(12);
  Wire.setSCL(13);
  rtc.begin(&Wire1) ;
  Wire.begin(8);
  Wire1.begin();
  Wire.begin(8);
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);
  Serial1.begin( 9600);
  Serial.begin(9600);
  dht.begin();
  pM = myDisplay.getGraphicObject();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.setTextAlignment(PA_RIGHT);
  myDisplay.setPause(1000);
  myDisplay.setSpeed(100);
  myDisplay.displayClear();
  Serial.begin(9600);

  if (!SD.begin()) {
   }
  myFile = SD.open(sdfile);
  mpos = 0;
  pinMode(10, INPUT);
  Serial1.begin(9600);
  Serial.begin(9600);
  myDFPlayer.begin(Serial1);
  delay(1000);
  if (!myDFPlayer.begin(Serial1)) {
  }
  myDFPlayer.start();
  delay(100);
  sd_datastor("R" ) ;
  alhr = ALM_time / 100;
  almn = ALM_time % 100;
  myDFPlayer.volume(Snd_vol);
  myDFPlayer.playFolder(5, 1);
  delay(100);
  sdfile = "comments.txt";
  sdfilelines();
  randtotline = totline;
  myDisplay.displayText("HAI..", PA_CENTER, 100, 1, PA_BLINDS);
  while (myDisplay.displayAnimate() == false) { } 
  }
//---------------------------------------------------------------------------------
  void loop() {
  Temperature();
  Serial.begin(9600);
  DateTime now = rtc.now();
  int hr = now.hour();
  int mn = now.minute();
  int scc = now.second();
  myDisplay.displayClear();
  myDFPlayer.volume(Snd_vol);
  //---------------------------------------------------------------------------------
  if (hr >= 4 && hr <= 12)message = message1;
  if (hr >= 13 && hr <= 16)message = message2;
  if (hr >= 16 && hr <= 20)message = message3;
  if (hr >= 20 && hr <= 23)message = message4;
  if (hr >= 0 && hr < 4)message = message4;
  checkstatus();

//---------------------------------------morng wish-start----------------------------
  if ( hr == mrg_wish_hr && mn == mrg_wish_min  && scc <= 2) {
  ch_stat = 1;
  myDisplay.displayClear();
  myDFPlayer.volume(Snd_vol);
  myDFPlayer.playFolder(5, 1);
  delay(1000);
  myDisplay.displayText("Hai Sobha Good Morning ...", PA_RIGHT, 100, 1, PA_SCROLL_LEFT);
  while (myDisplay.displayAnimate() == false) {
  }
  ch_stat = 1;
  }
//------------------------------------morng wish  end---------------------------------

//------------------------------------30 min  and hour speak---------------------------
  if (  mn == 30 && scc <= 3 &&   hr_onoff==0 &&  chimeblk==0 ) {
  ch_stat = 1;
  myDisplay.displayClear();
  myDFPlayer.volume(Snd_vol);
  myDFPlayer.playFolder(7, 2);
  delay(1000);
  for (int kh = 1 ; kh <= 2 ; kh++) {
  myDisplay.displayText("HALF HOUR ", PA_CENTER, 100, 1, PA_BLINDS);
  while (myDisplay.displayAnimate() == false) {
  }
  delay(1000);
  }
  timespeak();
  ch_stat = 0;
  myDisplay.displayClear();
  }
  else
  {ch_stat = 0; }
  //---------------------------------------------------------------------------------
  if (  mn == 0 && scc <= 3 &&   hr_onoff==0 &&  chimeblk==0) {
  ch_stat = 1;
  myDisplay.displayClear();
  myDFPlayer.volume(Snd_vol);
  myDFPlayer.playFolder(7, 1);
  delay(1000);
  for (int hh = 1 ; hh <= 6 ; hh++) {
  myDisplay.displayText("DING  DING ", PA_CENTER, 100, 1, PA_BLINDS);
  while (myDisplay.displayAnimate() == false) {
  }
  myDisplay.displayClear();
  delay(1500);
  }
  ch_stat = 0;
  }
  else {
  ch_stat = 0; 
  }

//---------------------------------------------------------------------------------
  if ( hr == alhr && mn == almn  && scc <= 2  && Alm_Poff == 1) {
  ch_stat = 1;
  chimeblk=1;
  myDisplay.displayClear();
  myDFPlayer.volume(30);
  Almoff = 0;
  myDFPlayer.playFolder(3, 1);
  delay(1000);
  myDisplay.displayText("ALARM      ", PA_RIGHT, 100, 1, PA_SCROLL_LEFT);
  while ((myDisplay.displayAnimate() == false)   ||(Almoff == 0) ) {
  checkstatus();
  }
  delay(2000);
  ch_stat = 1;
  chimeblk=0;
  }
//-------------------------30 min and  hour speak end------------------------------
//--------------------------morning  and Evg song----------------------------------
  if ( hr == mngsong_hr && mn == mngsong_min && scc <= 2    ) {
  ch_stat = 1;
  chimeblk=1;
  sdfile = "test.txt";
  myDFPlayer.volume(Snd_vol);
  mng_evg_song_play(3, 1);
  ch_stat = 0;
  chimeblk=0;
  Almoff == 0;
  }
  
  if ( hr == evgsong_hr && mn == evgsong_min && scc <= 2  ) {
  ch_stat = 1;
  chimeblk=1;
  sdfile = "test.txt";
  myDFPlayer.volume(Snd_vol);
  mng_evg_song_play(3, 1);
  ch_stat = 0;
  chimeblk=0;
  Almoff == 0;
  } 
  
//---------------- --- End  of morning  and Evg song--------------------------------

//------------------------------normal time  ---------------------------------------
  checkstatus();
  if (ch_stat == 0) {
  myDisplay.displayClear();
  int msglength = (message.length() + 1);
  char mssg[msglength];
  message.toCharArray(mssg, msglength);
  myDisplay.displayScroll(mssg, PA_RIGHT, PA_SCROLL_LEFT, 80);
  while (myDisplay.displayAnimate() == false) {
  ultrasound();
  checkstatus();
  if (ch_stat == 1)return;
  }
//-------------------Temperature Display-----------------------------------------
  myDisplay.displayClear();
  String tmp = "Temp: " + String(heat) + " 'C" + "                      Humd: " + String(humid) + " %" ;
  int tmp_length = (tmp.length() + 1);
  char tmpr[tmp_length];
  tmp.toCharArray(tmpr, tmp_length);
  myDisplay.displayScroll(tmpr, PA_RIGHT, PA_SCROLL_LEFT, 80);
  while (myDisplay.displayAnimate() == false) {
  ultrasound();
  checkstatus();
  if (ch_stat == 1)return;
  }
//---------------------------------------------------------------------------------
  myDisplay.displayClear();
  disptime(1);
  checkstatus();
  }
  ultrasound();
  }
//-------------------END OF MAIN LOOP----------------------------------------------

//-------------------SUB PROGRAMS--------------------------------------------------
  void anim(void ) {
  Serial.begin(9600);
  int displength = displine.length() - 1;
  char dispa[displength];
  displine.toCharArray(dispa, displength);
  while (myDisplay.displayAnimate()) {
  myDisplay.displayText(dispa, PA_RIGHT, 100, 1, PA_SCROLL_LEFT);
  }
  while (myDisplay.displayAnimate() == false) {
  }
  while (myDisplay.displayAnimate()) {
    myDisplay.displayText("      ", PA_RIGHT, 40, 1, PA_SCROLL_LEFT);
  }
  while (myDisplay.displayAnimate() == false) {
  }

  myDisplay.displayClear();
  return;
}
//---------------------------------------------------------------------------------
  void sdsingleline(int lineno) { // To Read a single line from the opened file on SD card
  myFile = SD.open(sdfile);
  myFile.seek(ps[lineno]);
  L = "";
  while (myFile.available()) {
  R = myFile.read();
  L += R;
  if (   R == '\n') {
  displine = L;
  return;
  }
  }
  }
//---------------------------------------------------------------------------------
  void sdfilelines(void){ // to find the total no of lines in the opened  text file 
  int x = 2;
  char rline;
  int y = 0;
  ps[1] = 0;
  myFile = SD.open(sdfile);
  while (myFile.available()) {
  rline = myFile.read();
  y = y + 1;
  if (rline == '\n') {
  ps[x] = myFile.position() ;
  x = x + 1;
  y = 0;
    }
  }
  totline = x - 1;
  myFile.close();
  return;
  }
//---------------------------------------------------------------------------------
  void disptime(int tipe) {  // to diplay Real time on Parala display
  DateTime now = rtc.now();
  char time_format[] = "     hh:mm:ss AP";
  char date_format[] = "     DDD DD MMM YY";
  char time_format2[]  = " hh:mm   AP";
  if (tipe == 1) {
  String apm;
  int h1=now.hour();
  int m1=now.minute();
  int s1=now.second()+3;
  if(s1>=60){ 
  s1=0; 
  m1=m1+1;  
  }
  if(m1>=60){ 
  m1=0; 
  h1=h1+1;  
  }     

  if(h1 >= 12)apm=":PM";
  else{
   apm= ":AM";  
  }
  if(h1 >= 12)h1=h1-12;    
  if(h1 == 0)h1=12;    
  String hh1= String (h1);
  if(h1/10 ==0) hh1=("0"+hh1);
  if(h1 ==0) hh1=("00");
  String mm1= String (m1);
  if(m1/10 ==0) mm1=("0"+mm1);
  if(m1 ==0) mm1=("00");
  String ss1=String(s1);
  if(s1/10 ==0) ss1=("0"+ss1);
  if(s1 ==0) ss1=("00");
  String tr5 = hh1+":"+mm1+":"+ss1+apm;
  int msgln = (tr5.length() + 1);
  char msg[msgln];
  tr5.toCharArray(msg, msgln);
  myDisplay.displayScroll(msg, PA_LEFT, PA_SCROLL_LEFT, 80);
  while (myDisplay.displayAnimate() == false) {
  ultrasound();
  checkstatus();
  if (ch_stat == 1) return;
    }
  myDisplay.displayClear();
  String up=now.toString(date_format);
  up.toUpperCase();
  int upln = (up.length() + 1);
  char upm[upln];
  up.toCharArray(upm, upln);



  myDisplay.displayScroll(upm, PA_LEFT, PA_SCROLL_LEFT, 80);
  while (myDisplay.displayAnimate() == false) {
  ultrasound();
  checkstatus();
  if (ch_stat == 1) return;
  }
  myDisplay.displayClear();
  ch_stat == 1;
  return;
  }
  if (tipe == 2) {
  myDisplay.print(now.toString(time_format2));
  }
  return;
}
//---------------------------------------------------------------------------------
  void mp3play(int fold , int playfileno , int timedely) {  //  to play Specifif Mp3 file on DF player
  myDFPlayer.playFolder(fold, playfileno);; //now
  delay(1000);
  }
//---------------------------------------------------------------------------------
  void timespeak( void) {   // to play the time on MP3 player
  DateTime now = rtc.now();
  int h = now.hour();
  int m = now.minute();
  int s = now.second();
  if (h >= 12) {
    h = h - 12;
  }
  if (h == 0) {
    h = 12;
  }
  myDFPlayer.playFolder(4, 1); //NOW TIME IS
  delay(1000);
  while (digitalRead(10) == LOW) {
  }
  myDFPlayer.playFolder(1, h); //hour
  delay(dely);
  while (digitalRead(10) == LOW) {
  }
 // myDFPlayer.playFolder(4, 2); //HOURS
  //delay(dely);
 // while (digitalRead(10) == LOW) {
 // }
 // myDFPlayer.playFolder(1, m); //min
  //delay(dely);
  //while (digitalRead(10) == LOW) {
 // }
  myDFPlayer.playFolder(4, 3); //min
  delay(dely);
  while (digitalRead(10) == LOW) {
  }
  return;
}
//---------------------------------------------------------------------------------
  void mng_evg_song_play(int fold , int fle) {   // To play songs on Evening and morning at times specified

  sdfilelines();
  int op = 1;
  for (int line_count = 1 ; line_count <= totline; line_count++) {
  if(Almoff == 1) {
  sdfile = "comments.txt";
  sdfilelines();  
  return;
  }  
  if (op == 1) {
  mp3play(fold, fle, 1000);
  delay(1000);
  }
  op = op + 1;
  sdsingleline(line_count);
  anim();
//  if ((line_count % 4) == 0) {
//  for (int t = 1; t <= 3; t ++) {
//  myDisplay.displayClear();
//  disptime(2);
//  delay(1000);
//  myDisplay.displayClear();
//  delay(500);
//  }
//  }
//  else {}
  }
  sdfile = "comments.txt";
  sdfilelines();  
  return;
  }
//---------------------------------------------------------------------------------
  void checkstatus(void){ // To check the status  of different sub systems 
  DateTime now = rtc.now();
  long int a1 = now.hour() * 3600 + now.minute() * 60 + now.second();
  long int a2 = now.minute() * 60 + now.second();
  long int mwish = mrg_wish_hr * 3600 + mrg_wish_min * 60;
  long int msong = mngsong_hr * 3600 + mngsong_min * 60;
  long int esong = evgsong_hr * 3600 + evgsong_min * 60;
  long int alr = alhr * 3600 + almn * 60;

  if (( a1 >= mwish - 3) && ( a1 <= mwish + 3) ) { // mrng wish
    ch_stat = 1; return; }
    
  if (( a1 >= msong - 3) && ( a1 <= msong + 3) ) { // morng song
    ch_stat = 1; return; }
    
  if (( a1 >= esong - 3) && ( a1 <= esong + 3) ) { // evening song
    ch_stat = 1; return; }
    
  if (( a2 >= 3597) || ( a2 <= 3)) { // full hour chime
    ch_stat = 1; return; }
    
  if ( (a2 >= 1797) && (a2 <= 1803) ) { // half hour chime
    ch_stat = 1; return; }

  if (( a1 >= alr - 3) && ( a1 <= alr + 3) ) { //alarm
    ch_stat = 1; return; }
  ch_stat = 0;

//------------------------------------
  hr_onoff =1;ul_onoff =1;
  if ((Hr_status==7) ){
  hr_onoff =1; 
  ul_onoff =1;
  }
  else {}
  if ((Hr_status==1) ||  (Hr_status==3)  ) hr_onoff =0;
  else {}
  if ((Hr_status==2) ||  (Hr_status==3)  ) ul_onoff =0;
  else {}
  if ((( now.hour()>= snd_block_end)&&(now.hour()<=snd_block_start  ))&& ( (Hr_status==4)|| (Hr_status==6))           )  {
  hr_onoff =0;
  }
  else {}
  if ((( now.hour()>=snd_block_end)&&(now.hour()<=snd_block_start ))&& (    (Hr_status==5)|| (Hr_status==6)       )    )  {
  ul_onoff =0;
  }
  else {}
  return;
  }
//---------------------------------------------------------------------------------
  void ultrasound(void) {  // to check/play ultra sound sensor
  if(ul_onoff==0 &&  chimeblk==0){
  dist_cm=sonar.ping_cm();
  if ((dist_cm >= 2 ) && (dist_cm <= 250 )) {
  ch_stat = 1;
  myDisplay.displayClear();
  int rand_fileno = random(1, randtotline - 1);
  sdsingleline(rand_fileno);
  int displength = displine.length() - 1;
  char dispa[displength];
  displine.toCharArray(dispa, displength);
  myDisplay.displayText(dispa, PA_LEFT, 100, 1, PA_SCROLL_LEFT);
  int dd = 1;
  while (myDisplay.displayAnimate() == false) {
  if (dd == 150){
  mp3play(10, rand_fileno, 1000);
  delay(100);   }
  dd = dd + 1;  }
  ch_stat = 0;
  }
  else{}
  }
  else{};
  return;
  }
//---------------------------------------------------------------------------------
  void receiveEvent(int howMany) {  // for actions to do when an event is received from master clock throuh I2C
  Wire.begin(8);
  String uc = "";
  String yt = "";
  String dt = "";
  String ti;
  String req_type;
  while (0 < Wire.available()) {
  char c = Wire.read();
  uc = uc + c;
  }
  if (uc == "")uc = "Z0";
  req_type = uc.charAt(0);
  uc = uc.substring(1);
  ti =uc.charAt(0);
 //  if (uc == "Z")return;
   
//========================================
  if (req_type == "N" ) {
  //Serial.println  ("ALM PER OFF  ");
  Alm_Poff = ti.toInt();
  sd_datastor("W" ) ;
  }
//=========================================
  if (req_type == "R" ) {
  //Serial.println  (" hour chime set mode");
  Hr_status = ti.toInt();
  sd_datastor("W" ) ;
  }
//==========================================
  if (req_type == "A" ) {
  //Serial.println  (" alarm set time");
  ALM_time =  (uc.substring(0, 4)).toInt();
  alhr = ALM_time / 100;
  almn = ALM_time % 100;
  sd_datastor("W") ;
  }
//==========================================
  if (req_type == "O" ) {
  //Serial.println  (" ALM OFF");
  Almoff = 1;
  myDFPlayer.stop();
  lin1 = "ALM/PLR OFF";
  line1() ;
  }
  if (req_type == "S" ) {
//Serial.println  (" SOUND VOL");
  Snd_vol = (uc.substring(0, 2)).toInt();
  sd_datastor("W") ;
  }
//=========================================
  if (req_type == "V" ) {
  //Serial.println  (" DISPLAY OFF");
  Disp_on = ti.toInt();
  if (Disp_on==0){
  pM->control(MD_MAX72XX::SHUTDOWN,1); }
  else{
  pM->control(MD_MAX72XX::SHUTDOWN,0);
 }}
//==========================================
  if (req_type == "t" ) {
  lin1 = "SET TIME"; line1() ; }
  
  if (req_type == "n" ) {
  lin1 = "SET ALARM"; line1() ;}
  
  if (req_type == "a" ) {
  lin1 = "SET ALM-ON"; line1();}
  
  if (req_type == "d" ) {
  lin1 = "SET DATE";line1() ;  }
  
  if (req_type == "y" ) {
  lin1 = "SYNC TIME";line1() ; }
  
  if (req_type == "s" ) {
  lin1 = "SET VOL"; line1() ;  }
  
  if (req_type == "h" ) {
  lin1 = "SET CHIME";line1() ; }
  
  if (req_type == "T" ) {
  int ss = ((uc.substring(12)).toInt()) +6;
  int mm = (uc.substring(10, 12)).toInt();
  if (ss >= 60 ){
  ss = ss - 60;
  mm = mm + 1;  }
  int hh = (uc.substring(8,10)).toInt();
  int DD = (uc.substring(6, 8)).toInt();
  int MM = (uc.substring(4, 6)).toInt();
  int YY = (uc.substring(0, 4)).toInt();
  DateTime now = rtc.now();
  Wire1.begin();
  rtc.begin(&Wire1) ;
  delay(50);
  rtc.adjust(( DateTime(YY, MM, DD, hh, mm, ss)));
  delay(500);
  lin_stop = 0;
  }
  Wire1.begin();
  rtc.begin(&Wire1) ;
  return;
  }

//---------------------------------------------------------------------------------
  void requestEvent() { // To read  data from SD card and send to Master on power on 
  DateTime now = rtc.now();
  int Y1=now.year();
  int M1 = now.month();
  int D1 =now.day();
  int h1 =now.hour();
  int m1 =now.minute();
  String hh1= String (h1);
  if(h1/10 ==0) hh1=("0"+hh1);
  if(h1 ==0) hh1=("00");
  String mm1= String (m1);
  if(m1/10 ==0) mm1=("0"+mm1);
  if(m1 ==0) mm1=("00");
  String YY1= String(Y1);
  String MM1= String(M1);
  if(M1/10 ==0) MM1=("0"+MM1);
  if(M1 ==0) MM1=("00");
  String DD1= String(D1);
  if(D1/10 ==0) DD1=("0"+DD1);
  if(D1 ==0) DD1=("00");   
  int s1 =  now.second();   
  String ss1=String(s1);
  if(s1/10 ==0) ss1=("0"+ss1);
  if(s1 ==0) ss1=("00");
  String tr3 = YY1+MM1+DD1+hh1+mm1+ss1;
  String a1 = String(ALM_time);
  if ((ALM_time / 1000) <= 0)a1 = "0" + a1;
  String a2 = String(Alm_Poff);
  if (Alm_Poff == 0)a2 = "0";
  String a3 = String(Hr_status);
  if ((Hr_status == 0))a3 = "0";
  String a4 = String(Snd_vol);
  if ((Snd_vol / 10) <= 0)a4 = "0" + a4;
  String t = String(Tempr);
  String a5 = tr3+a1 + a2 + a3 + a4 + t;
  char rs[25];
  a5.toCharArray(rs, 27);
  Wire.begin(8);
  Wire.write(rs, 26);
  delay(100);
  if(req_no==1) lin1 = "SEND DATA";
          else{ lin1 = "TEMPERATURE"; }
  req_no=0;
  line1() ;
  return;
  }
//---------------- STORE DATA ON SD CARD-------------------------------------------
  void sd_datastor(String rw ) {  // For reading and Writing  data on SD card
  String la;
  char ra;
  if (rw == "R") {
  myFile = SD.open("datastor.txt", FILE_READ);
  la = "";
  while (myFile.available()) {
  ra = myFile.read();
  la = la + ra;
  }
  data_string = la;
  ALM_time = (la.substring(0, 4)).toInt();
  Alm_Poff = (la.substring(4, 5)).toInt();
  Hr_status = (la.substring(5, 6)).toInt();
  Snd_vol = (la.substring(6)).toInt();
  myFile.close();
  return;
  }
  if (rw == "W") {
  SD.remove("datastor.txt");
  myFile = SD.open("datastor.txt", FILE_WRITE);
  int d = ALM_time * 10000 + Alm_Poff * 1000 + Hr_status * 100 + Snd_vol;
  String dd = String(d);
  myFile.print(dd);
  myFile.close();
  return;
  }}
//---------------------------------------------------------------------------------
  void line1(void ) {  // for diplaying messages in single line on Parola
  int lin1_length = lin1.length();
  char lin[lin1_length];
  lin1.toCharArray(lin, lin1_length + 1);
  lin_stop = 1;
  for (int kh = 1 ; kh <= 6 ; kh++) {
  myDisplay.setTextAlignment(PA_CENTER);
  myDisplay.print(lin );
  delay (200);
  myDisplay.displayClear();
  delay (200);
  }
  return;
  }
//---------------------------------------------------------------------------------
  void Temperature(void) { // to Read Temperature and humidity from Sensor
  delay(500);
  humid  = dht.readHumidity();
  heat = dht.readTemperature();
  Tempr = int(heat * 100);
  return;
  }

Credits

Ajith Kumar B

Ajith Kumar B

3 projects • 18 followers
Civil engineer.

Comments