Pages: 1 2 [3] 4   Go Down
Author Topic: Project Timer with DS1307 - Array of TimeElements; - Is Possible ?  (Read 4279 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So if I put the Alarm.TriggerOnce(); with my value the alarm trig correct ... is not this the issues ...

you said ... you do realise that TriggerOnce will only do what it says and only trigger once ?

Ok ... so then I can change my questions ...

How i can do fom Trigger and events and the specific time dynamically ? (like Alarm.TriggerOnce(); but when I want ...and not only once ?)

otherwise if there something that told me when the function is execute maybe retrieve true or false I can call into the loop also ...

thanks gnux
« Last Edit: January 28, 2013, 10:38:58 am by gnusso » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4016
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Each TriggerOnce will only trigger once, which makes sense, but you can have several active TriggerOnce alarms set for different future dates and times.  There is normally a limit of six alarms that can be active but you can change this.
Logged

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Then ...
I've not understand bad ...

is not possible change dynamically trigger once ... because of course will be call once ... but I can call several times I think if not wrong will be max 255 modify the library ...

So, for you will be possible do ...

- Configure the Alarm.TriggerOnce(); in the setup in this way will start the first time, always into the setup read timer in eeprom

then

- I configure a timer from a menu and i store the new value in eeprom, then reset arduino ... now the system will read all the timer in eeprom and i'll apply it ... but is possible reset the micro via software ?

make sense for you ?

otherwise I don't know How to trigger an events dynamically ...

Thanks
gnux



Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe can be used some function into yellow rectangle ? see the picture below reported ...

thanks
gnux


* Untitled.png (64.83 KB, 1216x620 - viewed 25 times.)
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use the ones above the line that says "private:".  You probably don't want to use the ones below "private:" even if you can.

In particular you may want to use enable() and disable().  You wouldn't ordinarily have need for those functions, but earlier I think you said something about "stopping" and "starting" alarms, so perhaps these enable() and disable() might be useful for what you are thinking.

What is your native language?  I too have a very hard time understanding your posts, because of the English.

Cheers,
John
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so, i think that problem is not the mother language but try to define correctly the issues that I've :-) Anyway I'm Italian ...

I try to explain better what I've in mind:

Scenario:

Set timer from a menu trigger at specific time.

Well, what I've understand using timer that is possible Trigger at specific date time using Alarm.TriggerOnce();  But this is used from one time only.

Assuming that I want call this "several times" changing the "timer value" from a Menu (then dynamically)... Which function should I use instead of Alarm.TriggerOnce() ? which is the correct approach ?

Is possible kindly have a simple example ?

Thanks for the support you are very great!,
gnux


« Last Edit: January 28, 2013, 01:08:33 pm by gnusso » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4016
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this
Code:
#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
Logged

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :-)
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4016
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually there is some stuff in the code that is not necessary left over from my experiments.
Try this version
Code:
#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);
}
Logged

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

thanks
gnux
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4016
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

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

Offline Offline
Sr. Member
****
Karma: 2
Posts: 427
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :-) 

Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 108
Posts: 4016
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Pages: 1 2 [3] 4   Go Up
Jump to: