Pages: [1]   Go Down
Author Topic: An every X-days alarm/output, suggestions?  (Read 436 times)
0 Members and 1 Guest are viewing this topic.
Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using TimeAlarms.h for daily event scheduling, but from what I can see Timealarms.h doesn't go beyond a daily alarm event, unless I use seconds, like 172,800 seconds for 2 days.

Does anyone have any suggestions for an every X-Days timer, 2-day, 4-day, etc. ?
Would using seconds with timealarms.h consum any more resources than another long-duration library?

I'll be testing for odd/even day(), by adding an If statement in a daily alarm, then disallow the daily alarm of Odd, etc..   This doesn't help my every second, third, etc. day...
« Last Edit: April 02, 2013, 05:33:36 pm by Ashton » Logged

Germany
Offline Offline
Edison Member
*
Karma: 133
Posts: 1448
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Derive the julian day number (JDN) from the date: http://en.wikipedia.org/wiki/Julian_day
Condition "JDN % 2 == 0" is true every second day
Condition "JDN % 3 == 0" is true  every third day
Condition "JDN % 4 == 0" is true  every fourth day
etc

An similar version for the JDN calculation is also part of our RTC Arduino lib: http://code.google.com/p/ds1307new/source/browse/DS1307new.cpp (void DS1307new::calculate_cdn(void))

Oliver
Logged

Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks

I have my RTC timing project designed around the libraries RTClib.h, Time.h, and TimeAlarms.h, and its working great.  It has 1-2 daily timed events now working.  But I need to add a couple of events evrey X-days.

So, it looks like the DS1307new.h library is also aware of Daylight Saving Time, the 'isMEZSummerTime'.  True?
Logged

Germany
Offline Offline
Edison Member
*
Karma: 133
Posts: 1448
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So, it looks like the DS1307new.h library is also aware of Daylight Saving Time, the 'isMEZSummerTime'.  True?

Yes, but only the European rule is implemented here.

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could also divide now() by the number of seconds of the day (86400) to get a sort of absolute day since ever (1/1/1970)

Code:

(now()/8640)%2==0 //gives true if today is even
(now()/8640)%3==0 // true every third day

In my case, I allocated an int counter for this, set up an alarm to every day 6am and increment the counter at the alarm. Every time the counter hits %x==0 I would reset the counter and perform the actions I need every x days. For an every other day case, I used a simple bool type. This way I can easily see how many days are left to my event occur and alter it by external interfaces, e.g. telnet server.

Off-topic:
Just finished my first arduino project and filled a UNO flash memory! This is great guys, great forum and great platform!
In this one I used the ethernet shield to get the time via Network Time Protocol (ntp), set up alarms to water my herbs (nothing illegal hehe) every other day, set up alarms to post temperature and soil moisture via http POST requests, a telnet server responds to basic commands such as get temperature, get moisture, set watering interval. I have a 12v water pump that is turned on via relays during the watering interval. Hope to blog the project soon!
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12579
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like a cool project, well done. The Arduino playground is thebest place to show off your work.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: