port Off at certain timing

Do you have a question on how to do something.
Ask in here.
Post Reply
Amos Poh
Posts: 107
Joined: Sun Jul 22, 2012 4:51 am
Location: Singapore

port Off at certain timing

Post 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 :)
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: port Off at certain timing

Post 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
Roberto.
Amos Poh
Posts: 107
Joined: Sun Jul 22, 2012 4:51 am
Location: Singapore

Re: port Off at certain timing

Post 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
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

port Off at certain timing

Post 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 :)
Amos Poh
Posts: 107
Joined: Sun Jul 22, 2012 4:51 am
Location: Singapore

Re: port Off at certain timing

Post 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 :)
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: port Off at certain timing

Post 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
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: port Off at certain timing

Post by rimai »

It's already coded to do those times, btw.
Roberto.
Post Reply