Time Alarm Problem

hello!! :frowning:

can you help me with my problem on this project . I am working with arduino Time Alarm. the number of alarm that i will use, consumed a more than a memory limit of the arduino. I am trying to shorten this code for low memory consumption and I am worrying for the stability of my program.

I am using:

  1. DS1307 RTC Module
  2. SD card module
  3. arduino uno

the triggering time for MWF and TTH is the same but i came up to put it individually. Can you help me for this??

#include <TimeAlarms.h>
#include <Time.h>
#include <SD.h>         
#include <SPI.h> 
#define SD_ChipSelectPin 4  
#include <TMRpcm.h>     
#include <Wire.h>  
#include <DS1307RTC.h> 

TMRpcm tmrpcm;

//unsigned long time = 0;

void setup()  {
  // pinMode (2, OUTPUT); 
   Serial.begin(9600);
    while (!Serial) ; 
    setSyncProvider(RTC.get);  
    if(timeStatus()!= timeSet) 
      Serial.println(F("Unable to sync with the RTC"));
    else
     Serial.println(F("RTC has set the system time"));     

                tmrpcm.speakerPin = 9;
 
                 if (!SD.begin(SD_ChipSelectPin)) {  
                 Serial.println(F("SD fail"));  
                return;  
                  }
             
                  
Alarm.alarmRepeat(dowMonday,8,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,9,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,10,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,11,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,12,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,1,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,2,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,3,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,4,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,5,0,0,WeeklyAlarm);
Alarm.alarmRepeat(dowMonday,6,0,0,WeeklyAlarm);

  Alarm.alarmRepeat(dowTuesday,7,30,0,WeeklyAlarm);   
  Alarm.alarmRepeat(dowTuesday,9,0,0,WeeklyAlarm);    
  Alarm.alarmRepeat(dowTuesday,10,30,0,WeeklyAlarm);
  Alarm.alarmRepeat(dowTuesday,12,0,0,WeeklyAlarm);    
  Alarm.alarmRepeat(dowTuesday,13,0,0,WeeklyAlarm);
  Alarm.alarmRepeat(dowTuesday,14,30,0,WeeklyAlarm);    
  Alarm.alarmRepeat(dowTuesday,15,0,0,WeeklyAlarm);    
  Alarm.alarmRepeat(dowTuesday,16,30,0,WeeklyAlarm);    
  Alarm.alarmRepeat(dowTuesday,17,30,0,WeeklyAlarm);    

          Alarm.alarmRepeat(dowWednesday,8,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,9,0,0,WeeklyAlarm);  
          Alarm.alarmRepeat(dowWednesday,10,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,11,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,12,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,13,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,14,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,15,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,16,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,17,0,0,WeeklyAlarm);   
          Alarm.alarmRepeat(dowWednesday,18,0,0,WeeklyAlarm);   

              Alarm.alarmRepeat(dowThursday,7,30,0,WeeklyAlarm);   
              Alarm.alarmRepeat(dowThursday,9,0,0,WeeklyAlarm);    
              Alarm.alarmRepeat(dowThursday,10,30,0,WeeklyAlarm);
              Alarm.alarmRepeat(dowThursday,12,0,0,WeeklyAlarm);    
              Alarm.alarmRepeat(dowThursday,13,0,0,WeeklyAlarm);
              Alarm.alarmRepeat(dowThursday,14,30,0,WeeklyAlarm);    
              Alarm.alarmRepeat(dowThursday,15,0,0,WeeklyAlarm);    
              Alarm.alarmRepeat(dowThursday,16,30,0,WeeklyAlarm);    
              Alarm.alarmRepeat(dowThursday,17,30,0,WeeklyAlarm);    

                                Alarm.alarmRepeat(dowFriday,8,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,9,0,0,WeeklyAlarm);  
                                Alarm.alarmRepeat(dowFriday,10,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,11,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,12,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,13,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,14,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,15,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,16,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,17,0,0,WeeklyAlarm);   
                                Alarm.alarmRepeat(dowFriday,18,0,0,WeeklyAlarm);   

Alarm.alarmRepeat(7,30,0,seventhirty);
Alarm.alarmRepeat(8,0,0,eight);
Alarm.alarmRepeat(8,30,0,eightthirty);
Alarm.alarmRepeat(9,0,0,nine);
Alarm.alarmRepeat(9,30,0,ninethirty);
Alarm.alarmRepeat(10,0,0,ten);
Alarm.alarmRepeat(10,30,0,tent);
Alarm.alarmRepeat(11,0,0,eleven);
Alarm.alarmRepeat(11,30,0,elevent);
Alarm.alarmRepeat(12,0,0,twelve);
Alarm.alarmRepeat(13,0,0,one);
Alarm.alarmRepeat(13,30,0,onet);
Alarm.alarmRepeat(14,53,0,two);
Alarm.alarmRepeat(14,30,0,twot);
Alarm.alarmRepeat(15,0,0,three);
Alarm.alarmRepeat(15,30,0,threet);
Alarm.alarmRepeat(16,14,0,four);
Alarm.alarmRepeat(16,16,0,fourt);
Alarm.alarmRepeat(16,18,0,five);
Alarm.alarmRepeat(17,30,0,fivet);
Alarm.alarmRepeat(18,0,0,six);
  }

void loop()
{
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
  } else {
    Serial.println(F("The time has not been set.  Please run the Time"));
    Serial.println(F("TimeRTCSet example, or DS1307RTC SetTime example."));
    delay(4000);
  }
  delay(1000);
  {
    digitalClockDisplay();
    Alarm.delay(1000);
}}

void digitalClockDisplay(){
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
void WeeklyAlarm(){
  tmrpcm.play("open.wav"); }
  
  void seventhirty(){
      tmrpcm.play("730.wav");     }
  
   void eight(){
       tmrpcm.play("8.wav"); }

          void eightthirty(){
             tmrpcm.play("830.wav"); }

          void nine(){
              tmrpcm.play("9.wav"); }

          void ninethirty(){
             tmrpcm.play("930.wav"); }

          void ten(){
             tmrpcm.play("10.wav"); }

          void tent(){
              tmrpcm.play("1030.wav"); }

          void eleven(){
             tmrpcm.play("11.wav"); }   

          void elevent(){
              tmrpcm.play("1130.wav"); }

          void twelve(){
              tmrpcm.play("speak 12.wav"); }

          void one(){
              tmrpcm.play("1.wav"); }

          void onet(){
              tmrpcm.play("130.wav"); }

          void two(){
               tmrpcm.play("2.wav"); }

          void twot(){
                tmrpcm.play("230.wav"); }

          void three(){
                 tmrpcm.play("3.wav"); }

          void threet(){
                tmrpcm.play("330.wav"); }

          void four(){
              tmrpcm.play("4.wav"); }

          void fourt(){
               tmrpcm.play("430.wav"); }

          void five(){
              tmrpcm.play("5.wav"); }

          void fivet(){
               tmrpcm.play("530.wav"); }

          void six(){
              tmrpcm.play("6.wav"); } :(

thank you and more power!!

It is pointless to use the TimeAlarm library when you have a real time clock.

On every pass through loop(), read the time. It the time corresponds to when something should happen, make that something happen.

Did you read the TimeAlarms readme ? There is a limit to how many alarms you can create unless you make a change a variable declaration in the library .h file. Mind you, whether you can create over 70 alarms even with the change is a moot point. You may need to take a different approach.

thon95:
thank you and more power!!

Like a Mega 2560. :slight_smile:

PaulS:
It is pointless to use the TimeAlarm library when you have a real time clock.

Unless, of course, your coding skills are limited to cut-and-paste.

On every pass through loop(), read the time. It the time corresponds to when something should happen, make that something happen.

But to do that would require coding skills beyond cut-and-paste, and here in Arduino-land, we bend over backwards to remove the need for such skills.

we bend over backwards to remove the need for such skills.

Not all of us. Some of us try to get people to think.