Go Down

Topic: Project Timer with DS1307 - Array of TimeElements; - Is Possible ? (Read 5 times) previous topic - next topic


Jan 22, 2013, 10:02 pm Last Edit: Jan 22, 2013, 10:08 pm by johncc Reason: 1

 tm.Year = 2011;
 tm.Month = 01;
 tm.Day = 01;
 tm.Hour = 8;
 tm.Minute = 31;
 tm.Second = 00;
 Alarm.timerOnce(makeTime(tm), OnceOnly) ;

... the condition is never verified ...

Maybe the alarm actually triggered-- where were you at 8:31am on 1/1/2011?

Just kidding.  

As UkHeliBob pointed out you should be using Alarm.triggerOnce() instead of timerOnce().  The documentation doesn't seem to describe this.  But you can get really good information about the TimeAlarms library by finding your Arduino/libraries/Timealarms/ directory and looking at readme.txt and TimeAlarms.h.  It is very well documented there as are many/most ARduino libraries:
Code: [Select]

 AlarmID_t triggerOnce(time_t value, OnTick_t onTickHandler);   // trigger once at the given time_t
 AlarmID_t timerOnce(time_t value, OnTick_t onTickHandler);   // trigger once after the given number of seconds

Also I noticed in Time.h that it is expecting a year in the form of "years since 1970", so you should put in some reasonable values like:
Code: [Select]

 static tmElements_t tm; // this is fine static is ok here but not necessary
 tm.Year = 2013 - 1970;  // this would be year 2013
 tm.Month = 01;
 tm.Day = 22;
 tm.Hour = 15;
 tm.Minute = 01;
 tm.Second = 00;
 Alarm.triggerOnce(makeTime(tm), OnceOnly) ;



From the readme :

"Low level functions to convert between system time and individual time elements are provided:                   
  breakTime( time, &tm);  // break time_t into elements stored in tm struct
  makeTime( &tm);  // return time_t  from elements stored in tm struct "

So you can convert both ways.

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Hi Guys,
really thanks I've understood now ...  so thanks for the very great support !!! I've adjust my sketch and now it's working ... so this morning I will try to play well with this  ;) thanks again,

warm regards,


Good Morning,

I've note using the TimerAlarmExample:

Code: [Select]

#include <Time.h>
#include <TimeAlarms.h>

void setup()
  setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
  // create the alarms
  Alarm.alarmRepeat(8,30,0, MorningAlarm);  // 8:30am every day
  Alarm.alarmRepeat(17,45,0,EveningAlarm);  // 5:45pm every day
  Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm);  // 8:30:30 every Saturday

  Alarm.timerRepeat(15, Repeats);            // timer for every 15 seconds   
  Alarm.timerOnce(10, OnceOnly);             // called once after 10 seconds

void  loop(){ 

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

// functions to be called when an alarm triggers:
void MorningAlarm(){
  Serial.println("Alarm: - turn lights off");   

void EveningAlarm(){
  Serial.println("Alarm: - turn lights on");           

void WeeklyAlarm(){
  Serial.println("Alarm: - its Monday Morning");     

void ExplicitAlarm(){
  Serial.println("Alarm: - this triggers only at the given date and time");       

void Repeats(){
  Serial.println("15 second timer");         

void OnceOnly(){
  Serial.println("This timer only triggers once"); 

void digitalClockDisplay()
  // digital clock display of the time

void printDigits(int digits)
  if(digits < 10)

If I didn't put

Code: [Select]


the timer doesn't work ...

My understanding is that the timer should work in background without block the cpu each time for a second ...

is there a way to change it ?



The documentation for TimeAlarms specifically says that you must use Alarm.delay() for it to work otherwise it cannot check for alarms.  There is no reason why you should not use Alarm.delay(1) if you want it not to block for 1 second.  You could also arrange to call Alarm.delay() at less frequent intervals using millis() as your own non blocking timer and only calling it when the delay will not affect your program.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up