TimeAlarms.h too many Alarms?

I have a project for a Break and Lunch bell using the Photon, once the time hits it triggers a relay shield for the bell to work. I have the first six alarms that work but after that the bell stops working. I’ve read the posts and GitHub pages regarding this port and the original Arduino library and managed to change the

#define dtNBR_ALARMS 6

From 6 to 255. I have a test line of code so i can see if its working and still nothing.
Hopefully someone can please look over my code and tell me what I’m doing wrong
Thanks in advance.
Not sure if I could post this here but I couldn’t post in Troubleshooting for some reason.

// This #include statement was automatically added by the Particle IDE.
#include "TimeAlarms.h" //This TimeAlarms.h file has been edited to accomodate for more alarms 

/*
 * This program will send a signal to the Photon Relay Shield so the bell can ring for the
 * breaks and lunch. 
 * This program will be updated until its working flawlessly.
 * This device will also sync time with the cloud once every 24 hours
 * 
 *
 */



// This #include statement was automatically added by the Particle IDE.
//#include <TimeAlarms.h>

// This #include statement was automatically added by the Particle IDE.
#include <NCD1Relay.h>
NCD1Relay relayController;

#define ONE_DAY_MILLIS (24 * 60 * 60 * 1000)
unsigned long lastSync = millis();

void setAddress(int a0, int a1, int a2);

void setup()
{
      // Update clock
  while (Particle.syncTimePending());  // Wait here for sync to finish
  Time.zone(-8);  // Pacific time zone
    Serial.begin(115200);
    relayController.setAddress(1, 1, 1);  //Relay Shield address for bell output
  
  
  // These are the bell times during the week
  Alarm.alarmRepeat(7,29,56, Break1);  // 7:30am every day
  Alarm.alarmRepeat(7,40,00,Break1End);  // 7:40am every day 
  Alarm.alarmRepeat(8,59,56, Break2);  // 9:00am every day
  Alarm.alarmRepeat(9,10,00,Break2End);  // 9:10am every day 
  Alarm.alarmRepeat(10,59,56, Lunch1);  // 11:00am every day
  Alarm.alarmRepeat(11,30,00,Lunch1End);  // 11:30am every day 
  Alarm.alarmRepeat(13,29,56, Break3);  // 1:30pm every day
  Alarm.alarmRepeat(13,40,00,Break3End);  // 1:40pm every day 
  Alarm.alarmRepeat(15,59,56, Break4);  // 4:00pm every day
  Alarm.alarmRepeat(16,10,00,Break4End);  // 4:10pm every day 
  Alarm.alarmRepeat(18,59,56, Lunch2);  // 7:00pm every day
  Alarm.alarmRepeat(19,30,00,Lunch2End);  // 7:30pm every day 
  Alarm.alarmRepeat(21,59,56, Break5);  // 10:00pm every day
  Alarm.alarmRepeat(22,10,00,Break5End);  // 10:10pm every day 


  //Theses are the bell alarms for Saturday Production
  
  
  Alarm.alarmRepeat(dowSaturday,7,29,56,SatBreak1);  // 7:30am every Saturday 
  Alarm.alarmRepeat(dowSaturday,7,40,00,SatBreak1End);  // 7:40am every Saturday
  Alarm.alarmRepeat(dowSaturday,8,59,56,SatBreak2);  // 9:00am every Saturday
  Alarm.alarmRepeat(dowSaturday,9,10,00,SatBreak2End);  // 9:10am every Saturday
  Alarm.alarmRepeat(dowSaturday,10,59,56,SatLunch);  // 11:00am every Saturday
  Alarm.alarmRepeat(dowSaturday,11,30,00,SatLunchEnd);  // 11:30am every Saturday
  Alarm.alarmRepeat(dowSaturday,13,29,56,SatBreak3);  // 1:30pm every Saturday
  Alarm.alarmRepeat(dowSaturday,13,40,00,SatBreak3End);  // 1:40pm every Saturday
 
 
  Alarm.alarmRepeat(dowSunday,19,33,00,SunTest);  //This was for testing because it was on a Sunday 
  
  //Alarm.timerRepeat(15, Repeats);            // timer for every 15 seconds    
  //Alarm.timerOnce(10, OnceOnly);             // called once after 10 seconds 
}


void  loop(){  
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
  if (millis() - lastSync > ONE_DAY_MILLIS) {
    // Request time synchronization from the Particle Device Cloud
    Particle.syncTime();
    lastSync = millis();
  }
}

// functions to be called when an alarm triggers:
void Break1(){
  Particle.publish("7:30am Break Starts", PUBLIC);
         relayController.toggleRelay();
        delay(2000);
                relayController.toggleRelay();
}

void Break1End(){
  Particle.publish("7:40am Break End", PUBLIC);
        relayController.toggleRelay();
        delay(2000);
                relayController.toggleRelay();
}

void Break2(){
  Particle.publish("9:00am Break Starts", PUBLIC);
        relayController.toggleRelay();
        delay(2000);
                relayController.toggleRelay();
}

void Break2End(){
  Particle.publish("9:10am Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(2000);
                relayController.toggleRelay();
}

void Lunch1(){
  Particle.publish("Morning Lunch Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Lunch1End(){
  Particle.publish("Morning Lunch Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Break3(){
  Particle.publish("1:30pm Break Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Break3End(){
  Particle.publish("1:40am Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Break4(){
  Particle.publish("4:00m Break Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Break4End(){
  Particle.publish("4:10pm Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();    
}

void Lunch2(){
  Particle.publish("7:00 Evening Lunch Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Lunch2End(){
  Particle.publish("7:40pm Evening Lunch Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Break5(){
  Particle.publish("10:00pm Break Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void Break5End(){
  Particle.publish("10:10pm Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}


// These are for the Saturday breaks

void SatBreak1(){
  Particle.publish("7:30am Saturday Break Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SatBreak1End(){
  Particle.publish("7:40am Saturday Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SatBreak2(){
  Particle.publish("9:00am Saturday Break Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SatBreak2End(){
  Particle.publish("9:10am Saturday Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SatLunch(){
  Particle.publish("11:00am Saturday Lunch Starts", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SatLunchEnd(){
  Particle.publish("11:30am Saturday Lunch Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SatBreak3(){
  Particle.publish("1:30pm Saturday Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SatBreak3End(){
  Particle.publish("1:40pm Saturday Break Ends", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}

void SunTest(){
  Particle.publish("This is a test", PUBLIC);
        relayController.toggleRelay();
        delay(3000);
                relayController.toggleRelay();
}



void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(Time.hour());
  printDigits(Time.minute());
  printDigits(Time.second());
  Serial.println(); 
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}



How did you do that?
Have you removed the original library from your project?
If you are using Web IDE, can you post a SHARE THIS REVISION link to your project?

Personally, with that many callbacks that virtually all do the same thing - with the only difference in the displayed test - I'd not use this library that way.

Also there is a Time.format() method that makes your digitalClockDisplay() into a one-liner (Serial.println(Time.format("%T"));)

I had added another tab and copy paste the TimeAlarms code to it so I can edit the line

#define dtNBR_ALARMS 6

Here’s the shareable link, Im not too concerned about the clock display but more about the rela output at those times.

Project

As expected, you still have the cloud library imported. You need to remove that otherwise it will be used instead of your altered version.
You also need to copy the implementation (.cpp) over into your project and while at it I’d extend that library just slightly to pass your alarm string in to the created AlarmClass object to reuse one single callback for all of them.


Try this
https://go.particle.io/shared_apps/5e00bbf6fd7aae000c0773cd
(this link will be valid for a week or so)

1 Like

Well that’s exactly what I was looking for. This is my first project with this type of device and normally I like to keep my code short and clean. Thanks for the help, now if you can direct me to the instructions on how to remove the installed library and use the modified one. I tried to do it when you mentioned it but it didn’t work for me. Now to to test and I will let you know how it works.
Thanks again.

In my sample I've already removed the cloud based library, but when you click on the <> icon the project drawer will open and there you will see this
image

Just hit the image next to the library you want to remove and hit YES, REMOVE IT.

1 Like

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