switching on and of in intervals

Do you have a question on how to do something.
Ask in here.
Post Reply
williet
Posts: 7
Joined: Sun Sep 16, 2012 9:36 am

switching on and of in intervals

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

Re: switching on and of in intervals

Post by lnevo »

ReefAngel.Relay.Set(PortX, now()%(SECS_PER_HOUR*2)<SECS_PER_HOUR);

I think that should do it..
Naptalene
Posts: 98
Joined: Tue Nov 05, 2013 12:50 am

Re: switching on and of in intervals

Post 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
Believe it or not.... I can ask even stupider questions than this one.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: switching on and of in intervals

Post 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
Naptalene
Posts: 98
Joined: Tue Nov 05, 2013 12:50 am

Re: switching on and of in intervals

Post 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);
Believe it or not.... I can ask even stupider questions than this one.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: switching on and of in intervals

Post 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 :)
Roberto.
Naptalene
Posts: 98
Joined: Tue Nov 05, 2013 12:50 am

Re: switching on and of in intervals

Post 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 :)
Believe it or not.... I can ask even stupider questions than this one.
Post Reply