Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set alarm every X minutes #13

Open
fedcas opened this issue Jul 11, 2018 · 6 comments
Open

Set alarm every X minutes #13

fedcas opened this issue Jul 11, 2018 · 6 comments

Comments

@fedcas
Copy link

fedcas commented Jul 11, 2018

Hi,
thanks for your library, it's the one that I'm using ;) there's just a couple of things I feel the need for.

I understand I can I can set these alarms:

ALARM_EVERY_MINUTE [fires every minute]
ALARM_MATCH_SECOND [fires every minute at a specified second]
ALARM_HOURLY [fires every minute]
ALARM_MATCH_MINUTE [fires every hour at a specified minute]

But how can I, for example, set an alarm every 5 minutes, 10 minutes, 15 minutes or 30 minutes? I'm using your library for a datalogger, and I would like to increase the logging interval. I'm using a counter for the moment, but hopefully there's a better way.

Thanks

P.S.
opening a separate discussion for the second question ;)

@geologic
Copy link

The only way is using a counter.
For 15 minutes, you set an ALARM_EVERY_MINUTE and increment a counter. When counter=15, thats your 15 minute interval.

@Experiment-6-2-6
Copy link

You can use ALARM_MATCH_MINUTE_HOUR.
First you have to check and save the time then the alarm starts.
Next you adding your time (for example 5 or 30 minutes but mind you sometime have to can change the hour)
Next you set second alarm clock to match that time.

@fedcas
Copy link
Author

fedcas commented Jul 17, 2018

thanks ;) I think I like your approach better than what I was doing with the counter. The only thing is, isn't it more simple to use just the minutes?

here is the code that I'm trying at the moment, it seems to work. Basically I'm declaring the global variables, then I initialize them in the setup with

  time = Clock.read();
  mins = time.Minute;`

then I use this lines both in setup and in loop functions:

  mins = mins + interval;
  if (mins >= 60) mins = mins - 60;
  time.Minute = mins;
  Clock.setAlarm(time, DS3231_Simple::ALARM_MATCH_MINUTE);

The whole code:

[...]
    int interval = 2;
    DateTime time;
    int mins;
[...]



void setup() {
[...]
  time = Clock.read();
  mins = time.Minute;
  
  mins = mins + interval;
  if (mins >= 60) mins = mins - 60;
  time.Minute = mins;
  Clock.setAlarm(time, DS3231_Simple::ALARM_MATCH_MINUTE);
[...]
}



void loop() 
{ 
  if(Clock.checkAlarms())
  {
[...]
    mins = mins + interval;
    if (mins >= 60) mins = mins - 60;
    time.Minute = mins;
    Clock.setAlarm(time, DS3231_Simple::ALARM_MATCH_MINUTE);
[...]
  }
}

@Experiment-6-2-6
Copy link

Well, that is better than my idea (of course if the interval is less than 59 minutes)
By the way, I found this article very instructive about limitation of DS3231 alarms.
https://gist.github.com/JChristensen/0359516e3780a819cbffef0db5419213

@fedcas
Copy link
Author

fedcas commented Jul 18, 2018

two heads are better than one ;) I'll read the article too, thanks ;)

@Chilkos
Copy link

Chilkos commented May 5, 2019

Thanks, this is exactly what I'm looking for!

Just a note for future visitors/users, if (mins >= 60) mins = mins - 60; can be replaced with mins = mins % 60;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants