Question about PJRC's TimeAlarms Library

I'm trying to understand whether this code is 'blocking' or not. I understand that one can adjust

    Alarm.delay(1000); // wait one second between clock display

to

    Alarm.delay(0);

and that apparently makes the code less blocking, but I could do with a bit of help understanding what is and isn't happening when the delay is a second instead of '0'. Things seem to be working just fine whether I have the delay at 1000 or 0. There doesn't seem to be a difference.

Secondly, I can find this out by experimenting, but is there anything stopping me from doing this:

Alarm.alarmRepeat(15,19,55, Pips);
Alarm.alarmRepeat(16,19,55, Pips);
Alarm.alarmRepeat(17,19,55, Pips);

as in multiple alarms for the same callback? Presumably this is OK, oder?

thanks!

A link to the library would be beneficial.

and that apparently makes the code less blocking, but I could do with a bit of help understanding what is and isn't happening when the delay is a second instead of '0'. Things seem to be working just fine whether I have the delay at 1000 or 0. There doesn't seem to be a difference.

As we just see one line of code I can simply tell you what that does.

The first waits for one second and will call the alarm callback functions if an alarm occurs during that one second.

The second doesn't wait but simply checks if an alarm should be issued at that exact moment or is already overdue. If no alarm is already waiting it immediately returns.

Secondly, I can find this out by experimenting, but is there anything stopping me from doing this:

Alarm.alarmRepeat(15,19,55, Pips);
Alarm.alarmRepeat(16,19,55, Pips);
Alarm.alarmRepeat(17,19,55, Pips);

as in multiple alarms for the same callback? Presumably this is OK, oder?

Yes.

but I could do with a bit of help understanding what is and isn’t happening when the delay is a second instead of ‘0’.

Checking the library source code is a good habit to develop.

void TimeAlarmsClass::delay(unsigned long ms)
    {
      unsigned long start = millis();
      while( millis() - start  <= ms)
        serviceAlarms();
    }
void TimeAlarmsClass::serviceAlarms()
    {
      if(! isServicing)
      {
        isServicing = true;
        for( servicedAlarmId = 0; servicedAlarmId < dtNBR_ALARMS; servicedAlarmId++)
        {
          if( Alarm[servicedAlarmId].Mode.isEnabled && (now() >= Alarm[servicedAlarmId].nextTrigger)  )
          {
            OnTick_t TickHandler = Alarm[servicedAlarmId].onTickHandler;
            if(Alarm[servicedAlarmId].Mode.isOneShot)
               free(servicedAlarmId);  // free the ID if mode is OnShot 
            else   
               Alarm[servicedAlarmId].updateNextTrigger();
            if( TickHandler != NULL) {        
              (*TickHandler)();     // call the handler  
            }
          }
        }
        isServicing = false;
      }
    }

The one second delay should block for one second hanging out in the while loop and checking the alarms. The delay(0) should block for the time it takes to check all the alarm timers.

cattledog:
The delay(0) should block for the time it takes to check all the alarm timers.

Will block for up to 2 milliseconds while checking all the alarm timers. The author chose "delay not to be less than".

Hmmm...

so why would you ever NOT want the Alarm.delay to be 0? Sorry just trying to wrap my head around it.

I am in a slightly odd situation whereby if I have just one 'alarm' scheduled my code works but if I have a long list like

  Alarm.alarmRepeat(7,59,55, PipsAlarm);
  Alarm.alarmRepeat(8,59,55, PipsAlarm);
  Alarm.alarmRepeat(9,59,55, PipsAlarm);
  Alarm.alarmRepeat(10,59,55, PipsAlarm);
  Alarm.alarmRepeat(11,59,55, PipsAlarm);
  Alarm.alarmRepeat(12,59,55, PipsAlarm);
  Alarm.alarmRepeat(13,59,55, PipsAlarm);
  Alarm.alarmRepeat(14,59,55, PipsAlarm);
  Alarm.alarmRepeat(15,59,55, PipsAlarm);
  Alarm.alarmRepeat(16,59,55, PipsAlarm);
  Alarm.alarmRepeat(17,59,55, PipsAlarm);
  Alarm.alarmRepeat(18,00,00, BigBenAlarm);
  Alarm.alarmRepeat(18,59,55, PipsAlarm);
  Alarm.alarmRepeat(19,59,55, PipsAlarm);
  Alarm.alarmRepeat(20,59,55, PipsAlarm);
  Alarm.alarmRepeat(21,59,55, PipsAlarm);
  Alarm.alarmRepeat(22,00,00, BigBenAlarm);
  Alarm.alarmRepeat(22,59,55, PipsAlarm);

then the alarms don't work.

I can post my complete sketch if it would be thought to be helpful, otherwise I'll keep trying to figure it out. I'm wondering if with a Alarm.delay of '0' the sketch doesn't have time to check all the alarms?

Lots for me to think about.

I am in a slightly odd situation whereby if I have just one ‘alarm’ scheduled my code works but if I have a long list then the alarms don’t work.

There is a default limit of six alarms. Take a look at the TimeAlarms.h file and change this line to meet your needs. It is very close to the top of the file(line 10 in my editor).

#define dtNBR_ALARMS 6   // max is 255

I’m wondering if with a alarm.delay of ‘0’ the sketch doesn’t have time to check all the alarms?

No. alarm.delay(0) calls the function serviceAlarms() which checks them all, but it is limited by the number of alarms in the #define

 for( servicedAlarmId = 0; servicedAlarmId < dtNBR_ALARMS; servicedAlarmId++)