Page 1 of 1

switching on and of in intervals

Posted: Wed Mar 26, 2014 10:20 am
by williet
Hi all

I wanting to add a ozonizer to my setup and have it switch on for an hour then off for an hour repeatedly the whole day long

How would I do this ?

Re: switching on and of in intervals

Posted: Wed Mar 26, 2014 10:23 am
by lnevo
ReefAngel.Relay.Set(PortX, now()%(SECS_PER_HOUR*2)<SECS_PER_HOUR);

I think that should do it..

Re: switching on and of in intervals

Posted: Thu Apr 17, 2014 1:46 pm
by Naptalene
Hi, I found that code earlier and have just tried to implement it.
I'm getting strange time intervals.

Could you explain the code a touch for me please?

What is Set? Then you are defining which relay port is being used.
Then the current time is loaded.
What is the % sign?
I then thought the next bracket section was just where I put my "off" duration in seconds but if I time it I get unexpected durations? I think I'm just not understanding how to use it.
finally why is there a less than before the last section. If I put the the on duration in seconds in here I get exactly what I put in.

If there is already a link explaining it his please can you share it.
Thanks

Re: switching on and of in intervals

Posted: Thu Apr 17, 2014 1:53 pm
by lnevo
ReefAngel.Relay.Set(port, status) - This set's the specified port to On/Off depending on the value of status

% = Modulus operator. It's just like +,-,x,/ but it represents the "remainder" when you divide.
So 100%30 = 10

So the expression now()%(SECS_PER_HOUR*2) means if you devide now() - time in seconds by 2 hours.. how much time is left over...

If we're < less than one hour.. then you'll get true, if you're over you'll get false.

So for the first hour, you'll be on and the second hour you'll be off.

A better way to think about the statement is the following:

now()%(ON+OFF)<ON

Re: switching on and of in intervals

Posted: Thu Apr 17, 2014 2:35 pm
by Naptalene
Thank you!

I'm almost there.
now() is time in seconds with referance to?

here is what I'm doing,

if (!ReefAngel.HighATO.IsActive()) // relay on High ATO switches off so power is out
{
ReefAngel.Relay.Set(Skimmer,now()%1800<120); //
}

I thought that would be on for 120" then off for 1800"

So should I be

ReefAngel.Relay.Set(Skimmer,now()%1920<120);

Re: switching on and of in intervals

Posted: Thu Apr 17, 2014 2:49 pm
by rimai
now() is the number of seconds from 01/01/1970
Also called epoch time or UNIX time.
You are correct on your thinking :)

Re: switching on and of in intervals

Posted: Thu Apr 17, 2014 3:12 pm
by Naptalene
Thanks to both of you.

I think my problem was/is that I read the brackets etc. as a Maths sum.
So I expect a number to come out, not the word true. My brain is adjusting :)