Help

Do you have a question on how to do something.
Ask in here.
Post Reply
mrwlf
Posts: 17
Joined: Thu Feb 13, 2014 8:10 am

Help

Post by mrwlf »

Hi,
i need help coding my zeolite reactor on port 2:

I need to switch on port 2 at 11.00 and 23.00 for 2 minutes then OFF for the rest of the day.

Thanks for your help
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Help

Post by rimai »

Try this:

Code: Select all

ReefAngel.Relay.Set(Port2,(now()-3600)%43200<120);
Roberto.
mrwlf
Posts: 17
Joined: Thu Feb 13, 2014 8:10 am

Re: Help

Post by mrwlf »

Thanks Roberto. How to set the interval starting at 23.00?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Help

Post by rimai »

All times are based on midnight, so I decreased 3600 seconds from it.
Roberto.
dedvalson
Posts: 140
Joined: Tue Oct 04, 2011 5:49 am

Re: Help

Post by dedvalson »

Hi,

That seems like a pretty arcane way to do this.

How about:

Code: Select all

ReefAngel.Relay.Set (Port2, (hour() == 11 || hour() == 23) && minute() < 2);
I think that would be simpler and is certainly more readable.

Don
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Help

Post by rimai »

There you go :)
That's why it is good to have a second eye on things.. lol
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Help

Post by lnevo »

dedvalson wrote:Hi,

That seems like a pretty arcane way to do this.

How about:

Code: Select all

ReefAngel.Relay.Set (Port2, (hour() == 11 || hour() == 23) && minute() < 2);
I think that would be simpler and is certainly more readable.

Don
Its certainly a good way, but not the best long term and for many who do time based operations can lead to the wrong actions. Yes it is more readable, but its less flexible for many of the repeat scheduling people want to do. The way I try to explain the previous usage would be

(now() + offset) % repeat < runtime

Hope that helps clarify. Fun part of coding is coming up with different ways to accomplish things. Always good to see different ideas.
Post Reply