Arduino Word Clock RTC

Hi,
I'm new to coding and may be overlooking something Simple. I have written the below code and I'm at 51% Dynamic memory usage and I'm only up to the second hour of a 24 hour time program. I have seen many other ways of doing a word clock however, I'm getting the LED Strip lights to animate a particular way once in the sub programs Labelled "Time_" I'm hoping its a simple oversight that I'm missing. I apologize in advance if I don't quite understand coding terms etc., I'm just determined to get the job done without much of a clue.. :blush:





#include <Wire.h>
#include "RTClib.h"
DS1307 rtc;

void setup () {
  Wire.begin();
  rtc.begin();

  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("Arews Time Clock");
  Serial.println("-------------------");
  
}

void loop () {
DateTime now = rtc.now();   
{
Check_Time();
wait (3000);
}

}

void Check_Time (){
DateTime now = rtc.now(); 
///////////////  Midnight //////////////////////
///////////////  Midnight //////////////////////
///////////////  Midnight //////////////////////

if(now.hour() == 00 && now.minute() == 1){
Time_0000();}

  else if(now.hour() == 00 && now.minute() == 5){
  Time_0005();}
  
  else if(now.hour() == 00 && now.minute() == 10){
  Time_0010();}
  
  else if(now.hour() == 00 && now.minute() == 15){
  Time_0015();}
  
  else if(now.hour() == 00 && now.minute() == 20){
  Time_0020();}
  
  else if(now.hour() == 00 && now.minute() == 25){
  Time_0025();}
  
  else if(now.hour() == 00 && now.minute() == 30){
  Time_0030();}
  
  else if(now.hour() == 00 && now.minute() == 35){
  Time_0035();}
  
  else if(now.hour() == 00 && now.minute() == 40){
  Time_0040();}
  
  else if(now.hour() == 00 && now.minute() == 45){
  Time_0045();}
  
  else if(now.hour() == 00 && now.minute() == 50){
  Time_0050();}
  
  else if(now.hour() == 00 && now.minute() == 55){
  Time_0055();}

/////////////  One O Clock ///////////////////////
/////////////  One O Clock ///////////////////////
/////////////  One O Clock ///////////////////////

  else if(now.hour() == 01 && now.minute() == 00){
  Time_0100();}

  else if(now.hour() == 01 && now.minute() == 5){
  Time_0105();}
  
  else if(now.hour() == 01 && now.minute() == 10){
  Time_0110();}
  
  else if(now.hour() == 01 && now.minute() == 15){
  Time_0115();}
  
  else if(now.hour() == 01 && now.minute() == 20){
  Time_0120();}
  
  else if(now.hour() == 01 && now.minute() == 25){
  Time_0125();}
  
  else if(now.hour() == 01 && now.minute() == 30){
  Time_0130();}
  
  else if(now.hour() == 01 && now.minute() == 35){
  Time_0135();}
  
  else if(now.hour() == 01 && now.minute() == 40){
  Time_0140();}
  
  else if(now.hour() == 01 && now.minute() == 45){
  Time_0145();}
  
  else if(now.hour() == 01 && now.minute() == 50){
  Time_0150();}
  
  else if(now.hour() == 01 && now.minute() == 55){
  Time_0155();}
}
  
///////////////////  Midnight ////////////////////

        void Time_0000() {
        Serial.print("The Time is Twelve O Clock");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0005() {
        Serial.print("The Time is Five Past Twelve");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0010() {
        Serial.print("The Time is Ten Past Twelve");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0015() {
        Serial.print("The Time is Quarter Past Twelve");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0020() {
        Serial.print("The Time is Twenty Past Twelve");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0025() {
        Serial.print("The Time is Twenty Five Past Twelve");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0030() {
        Serial.print("The Time is Half Past Twelve");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0035() {
        Serial.print("The Time is Twenty Five to One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0040() {
        Serial.print("The Time is Quarter to One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0045() {
        Serial.print("The Time is Quarter to One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0050() {
        Serial.print("The Time is Ten to One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0055() {
        Serial.print("The Time is Five to One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

//////////////////  One O Clock //////////////////
        
        void Time_0100() {
        Serial.print("The Time is One O Clock");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0105() {
        Serial.print("The Time is Five Past One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0110() {
        Serial.print("The Time is Ten Past One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0115() {
        Serial.print("The Time is Quarter Past One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0120() {
        Serial.print("The Time is Twenty Past One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0125() {
        Serial.print("The Time is Twenty Five Past One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0130() {
        Serial.print("The Time is Half Past One");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0135() {
        Serial.print("The Time is Twenty Five to Two");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0140() {
        Serial.print("The Time is Quarter to Two");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0145() {
        Serial.print("The Time is Quarter to Two");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

        void Time_0150() {
        Serial.print("The Time is Ten to Two");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}
        
        void Time_0155() {
        Serial.print("The Time is Five to Two");
        Serial.println();
        // Insert LED Code Here

        // Insert LED Code Here
        delay(3000);}

Oh, my. I don't want to hurt your feelings, but the common term for that kind of code is "pedestrian". You really need to factor out the endless repetition using math, loop control structures, and sometimes arrays.

The problem with "determination" is that the processor has much more of it than you do. :slight_smile: You will soon run out of memory unless you back off and rethink the approach.

Just as a trivial example, look at the number of times you print, "The Time is"... if it's part of a generic time print routine, you only code it once.

Also I believe there is no state change detection in your code, as it tests the time repetitively, every time through loop(), and then prints the time. Since loop() executes thousands of times a second, you will get thousands of prints. You need to implement state change detection.

On some displays, that will cause flickering even though the same data is being written on each pass. You really only should update the display whenever the information changes.

Thanks aarg,
No feelings were hurt, I'm not sure exactly how to trigger the 5m interval of time to get the sub program in a way using the RTC without checking the time every block of code.
I originally had the "Check_Time()" code just under the loop but moved it to its own void to try to save memory but that didn't help.
As far as the "Serial.Print" Commands these were for me to debug on the serial monitor prior to hooking up all the LED Strips, these can be removed.

you said
Also I believe there is no state change detection in your code, as it tests the time repetitively, every time through loop(), and then prints the time. Since loop() executes thousands of times a second
i guess i could make it look for a state change or just put in a time delay at the bottom so it delays before the loop starts again, would this work?

@arew, the RTC doesn't really care if you keep polling it for the time, so you can do that and only respond (for example) when the minute changes. For that, you save the old minute and compare it like:

current_minute = now.minute();
if (current_minute != previous_minute)
{
display_time();  //update display
previous_minute = current_minute;
}

Most of the time, the current and previous minute are the same, so no display code is executed.

After a while, you might end up finessing it with details like polling the RTC only every 100ms or so. But that is optional.

Or you could react every 5 minutes:

current_minute = now.minute();
if (current_minute != previous_minute and (current_minute % 5) == 0)
{
display_time();  //update display
previous_minute = current_minute;
}

@arew, your topic has been moved to a more suitable location on the forum. I'm not sure why you think that this relates to Avrdude, stk500, Bootloader issues ( which basically is about upload problems which you don't seem to have :wink: ).

Can you please edit your opening post, select all code and click the </> button to apply code tags. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Using arrays and math to reduce the number of unique strings and reduce duplication.

const char *HourNames[25] =
{
  "Midnight", "One AM", "Two AM", "Three AM", 
  "Four AM", "Five AM", "Six AM", "Seven AM", 
  "Eight AM", "Nine AM", "Ten AM", "Eleven AM", 
  "Noon", "One PM", "Two PM", "Three PM", 
  "Four PM", "Five PM", "Six PM", "Seven PM", 
  "Eight PM", "Nine PM", "Ten PM", "Eleven PM", 
  "Midnight" // for 11:35, 11:40, 11:45, 11:50, and 11:55 PM
};

const char *MinuteRange[12] =
{
  "", "Five Past", "Ten Past", "Quarter Past", 
  "Twenty Past", "Twenty Five Past", "Half Past", "Twenty Five to", 
  "Twenty to", "Quarter to", "Ten to", "Five to"
};

void ShowTime(int hour, int minute)
{
  int minuteRange = minute / 5;
  Serial.print("The Time is ");
  Serial.print(MinuteRange[minuteRange]);
  if (minuteRange > 0)
    Serial.print(' ');
  Serial.print(HourNames[hour + (minuteRange > 6)]);
  Serial.println('.');
}