Page 1 of 1
port Off at certain timing
Posted: Sun Mar 24, 2013 5:16 am
by Amos Poh
Hi guys any idea how to code this out?
i would like OFF port 5 from
-0858 to 0902
-1158 to 1202
-1458 to 1502
-1758 to 1802.
the rest of time keep ON.
Thanks in advance

Re: port Off at certain timing
Posted: Sun Mar 24, 2013 9:19 am
by rimai
Try this:
Code: Select all
int t=now()%10800; // We are interested in 3 hr intervals
if (hour()>=8 && hour()<=18) // The off period only happens between 8 and 18
ReefAngel.Relay.Set(Port5, !(t<120 || t>10680) ); // Turn off for 2 minutes before and after our intervals
else
ReefAngel.Relay.On( Port5 ); // Keep port on for hours that are not within the off period
Re: port Off at certain timing
Posted: Mon Mar 25, 2013 1:15 am
by Amos Poh
rimai wrote:Try this:
Code: Select all
int t=now()%10800; // We are interested in 3 hr intervals
if (hour()>=8 && hour()<=18) // The off period only happens between 8 and 18
ReefAngel.Relay.Set(Port5, !(t<120 || t>10680) ); // Turn off for 2 minutes before and after our intervals
else
ReefAngel.Relay.On( Port5 ); // Keep port on for hours that are not within the off period
Roberto please pardon me, but i dont know how to code my requirements using the example code :p
port Off at certain timing
Posted: Mon Mar 25, 2013 5:36 am
by lnevo
Put that in your loop instead of any other line for that port. You can put it in between the comments that say place custom code here

Re: port Off at certain timing
Posted: Mon Mar 25, 2013 9:04 am
by Amos Poh
lnevo wrote:Put that in your loop instead of any other line for that port. You can put it in between the comments that say place custom code here

Thanks i understand the part on replacing this code with the existing code. but iam still not sure how to make it always on except the following timing;
-0858 to 0902
-1158 to 1202
-1458 to 1502
-1758 to 1802.
Sorry pardon my noobness

Re: port Off at certain timing
Posted: Mon Mar 25, 2013 9:25 am
by lnevo
Look at the comments...
This breaks down the day into 3 hour intervals and sets the remainder into the variable t for checking later.
int t=now()%10800; // We are interested in 3 hr intervals
Since your condition is only for the hours of 8am to 6pm
if (hour()>=8 && hour()<=18) // The off period only happens between 8 and 18
This will turn the port to the result of the operation !(t<120 || t>10680).
If t is less than 120 (2 minutes at the beginning of the 3 hour window) or t is greater than 10680 (2 minutes at the end of the 3 hour window) then we turn off the port using the ! to reflect we want the opposite of the result to turn off the port.
ReefAngel.Relay.Set(Port5, !(t<120 || t>10680) ); // Turn off for 2 minutes before and after our intervals
else
Otherwise it's on

ReefAngel.Relay.On( Port5 ); // Keep port on for hours that are not within the off period
Re: port Off at certain timing
Posted: Mon Mar 25, 2013 9:36 am
by rimai
It's already coded to do those times, btw.