Project Timer with DS1307 - Array of TimeElements; - Is Possible ?

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

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

I'll let you know :slight_smile:

thanks :slight_smile:
have nice evening :slight_smile:

Actually there is some stuff in the code that is not necessary left over from my experiments.
Try this version

#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);
}

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

thanks
gnux

gnusso:
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".

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

As John says above, yes it is automatically disabled when it is triggered. The reason why timeOnce() keeps triggering if you set it in loop() without checking if is needed is that each time loop() runs it sets up a new copy of the alarm which then triggers.

As has been pointed out, you may need to cancel an alarm before it is triggered, but don't get tangled with that right now. That was the reason why I originally had the alarm ID in my simple sketch as it will be needed in order to cancel the alarm.

As a next step I suggest that you put timerActive flag in an array to allow you to test multiple alarms without the need (yet) to set them up from a menu. Once that is working you can consider getting user input to set up the alarm date and times instead of hard coding them.

A question for you. Will the same function be called when each alarm is triggered or will each alarm trigger its own function or a mixture of both ?

Thanks for the questions ... so my focus is that :

for example:

  • Alarm.TriggerOnce(maketime(tm0start),FunctionStartTimer0);

  • Alarm.TriggerOnce(maketime(tm0stop),FunctionStopTimer0);

this will be called "TIMER0"

then will be another:

  • Alarm.TriggerOnce(maketime(tm1start),FunctionStartTimer1);

  • Alarm.TriggerOnce(maketime(tm1stop),FunctionStopTimer1);

this will be called "TIMER1" , etc etc ...

so i'd like to use "Alarm.TriggerOnce()" because I want to specific at date time ....

So I think that is necessary put "Alarm.Disable(IdTimer)" like into the first example because with the test did in the past there was a little issues for example the timer was never trigger ... but i need to check this ... is possible ?

Another curiosity that I've is that: If I call "tm1start.minutes" etc etc one time into the setup is working without anyproblem if i call this into the loop is not working ... If not understood bad is not working because each time change in background the value passed to the function ... make sense ?

thanks for the support,
i will try and I'll let you know :slight_smile:

If you create an alarm in setup() it will only be created once.
If you create an alarm in loop() it will be set up each time round the loop unless it is already set up, hence the timerActive variable in my routine.

Try extending my routine to set up 3 alarms, each triggered once at a different time, using an array to hold the timerActive flag so that you can keep track of each of them.

gnusso:
Taking your examples, and when you have completed your project and it is working great:

Let's say right now its 9:30am. And someone has set it for "start" 9:45 and "stop" 10:00. so your code executes:
( tm0start has the value 9:45am)

  • Alarm.TriggerOnce(maketime(tm0start),FunctionStartTimer0);
    ( tm0stop has the value 10:00am)
  • Alarm.TriggerOnce(maketime(tm0stop),FunctionStopTimer0);

Now we wait til 9:45. What happens? (e.g. Bell rings, Oven Turns On, Display starts counting 00:00:00, :01, :02, :03)?
Now we wait til 10:00. What happens? (e.g. Bell,Oven Turns Off, Display reads 00:15:00)?
Was there something that started at 9:45 that ended at 10:00? If so, what?

I'm trying to figure out exactly what you mean by "Start the timer" and "Stop the timer". Please give some examples of what the "timer" will be used for? Timing your boiling eggs? Waking you up? Laps around the track? Watering your lawn? What?

Depending on your answers, I'm not sure you need a tm0start and tm0stop

Cheers,
John

Yes could be used for example for turn on a "Coffe Machine" ... it a general purpose ...

for example :

  • turn on at 9:45 of 30-01-2013
  • turn on off at 10:10 of 30-01-2013

so, now it's working ... i'm testing in all position on the loop, out loop etc etc,

thanks for the support,
john very great!

Setting/changing/cancelling the alarm on/off times will need to be done inside loop() or a function called from it or you will need to reset the Arduino to enable setup() to run again.

What is it that you have got working ?

Hi,
I've tried to setup a timer with Alarm.TriggerOnce(); from a menu and it's working ... also changing the timer with new value it's working again ... so now i need to adjust a little bit and clean a program ... then when i will finish the project i can did some Minutes with my experience ... maybe could be useful :slight_smile: for the moment I think could be solved :slight_smile:

thanks for the support,
very appreciate it,

regards,
gnux

That's good news.

Good luck with tidying it up - don't break it !

You Should deservedly be Very Proud of your self. You did a fine job all the way, A very fine Joj.

Bob

Thanks Bob,
I'm try to put "all of me" for "understand", "try", "know", and then at end give the answer because I thinks is a respect for the people that have helped you to fix a issues ... this is the "sense" of the forum I thinks ...

warm regards,
gnux

Hey gnusso, that's terrific! Congratulations!

John

so, it's the true ... for example without you i was not able to understand how it's working what there into the background :slight_smile: and then this is important ...:slight_smile:

Hi, good morning again,

so now that i've take a little bit confidence with that, I would like to create an array of TimeElements in order to do some operations using the "Top Down Methodologies" ...

Is possible to do that ? if yes how ? So, i've did just for give you an idea this quickly steps could be fine ?

#include <Time.h>
#include <TimeAlarms.h>
#include <LiquidCrystal.h>	// ensure that the include path is set
#include "M2tk.h"
#include <VirtualWire.h>
#include <Wire.h>
#include <DS1307.h>
#include <EEPROM.h>
#include "utility/m2ghlc.h"

void setup() 
{
     TimeElements tm0start[10];
     tm0start[0].Day = 01;
     tm0start[0].Month = 12;
     tm0start[0].Year = 2013;
     tm0start[0].Hour = 01;
     tm0start[0].Minute = 25;
     tm0start[0].Second = 00;
     tm0start[1].Day = 03;
     tm0start[1].Month = 4;
     tm0start[1].Year = 2013;
     tm0start[1].Hour = 07;
     tm0start[1].Minute = 43;
     tm0start[1].Second = 23;   
}
void loop() {
    
}

so, I didn't have back issues than can i hope :slight_smile: or better i need to try but now i didn't have with me the stuff :frowning:

thanks for the support,
gnux

An array of TimeElements that is local to setup() doesn't seem too useful. Other than that, the code looks fine. Does it compile?

yes the compilation it's fine but you have reason it need to be declare into global scope ... the example was for see the array of time elements can works ...