Go Down

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

johncc


is not necessary disable the timer ? is automatically disabled ?

Right!  Thats what the "Once" means in triggerOnce() and timerOnce() and alarmOnce().
Another way to say it is "Once it happens, That One is gone".
Quote


You would only need to disable a timer if you need to cancel it, like
Now it's 9:15.  I set the Alarm for 11:30 with alarmOnce().
Now it's 9:45.  I change my mind and I don't want that Alarm.  I disable() it.
Now it's 11:30.  The alarm doesn't go off because its disabled().

I think you have found the library folder-- have you read the file readme.txt, and loaded and run the example sketch(s)?  If not you really need to do it.  The documentation is quite good.  Among other things it is important to learn the difference in how the TimeAlarms library means the words "Timer" and "Alarm".

Regards,
John

gnusso

So, I've tried then for you is not necessary disable the timer ? is automatically disabled ?

thanks
gnux

UKHeliBob

Actually there is some stuff in the code that is not necessary left over from my experiments.
Try this version
Code: [Select]
#include <Time.h>
#include <TimeAlarms.h>

int timerID;
bool timerActive = false;

void setup()
{
  Serial.begin(9600);
  setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
}

void  loop(){ 
  if (!timerActive)
  {
    Alarm.timerOnce(10, OnceOnly);  //set timer if not already active
    timerActive = true;
  }
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void OnceOnly(){
  Serial.println("This timer only triggers once and is then disabled");
}

void digitalClockDisplay()
{
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

gnusso

Sounds Good ! This was exactly that was in my mind ...

so tomorrow i will do more the test and i will implement array :-)

I'll let you know :-)

thanks :-)
have nice evening :-)

UKHeliBob

Try this
Code: [Select]
#include <Time.h>
#include <TimeAlarms.h>

int timerID;
bool timerActive = false;

void setup()
{
  Serial.begin(9600);
  setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
}

void  loop(){ 
  if (!timerActive)
  {
    timerID = Alarm.timerOnce(10, OnceOnly);  //set timer if not already active
    timerActive = true;
  }
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void OnceOnly(){
  Serial.println("This timer only triggers once and is then disabled");
  Alarm.disable(timerID);
}

void digitalClockDisplay()
{
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println();
}

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


Currently only valid for one alarm but it would be a good candidate for the use of an array of alarm statuses and IDs
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