a pump on for 3 hours then off for 3 hours?

Do you have a question on how to do something.
Ask in here.
Post Reply
MDB1029
Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio

a pump on for 3 hours then off for 3 hours?

Post by MDB1029 »

I am still no good at the code writing, I think this will work but not sure.

Code: Select all

ReefAngel.Relay.On(Port8);
if (hour()==03 && minute()<180) ReefAngel.Relay.Off(Port8);
if (hour()==09 && minute()<180) ReefAngel.Relay.Off(Port8);
if (hour()==15 && minute()<180) ReefAngel.Relay.Off(Port8);
if (hour()==21 && minute()<180) ReefAngel.Relay.Off(Port8);
Any thoughts or suggestions? Am i totally wrong?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: a pump on for 3 hours then off for 3 hours?

Post by rimai »

no.
minute() is how many minutes in an hour. So, max is 59.
Roberto.
MDB1029
Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio

Re: a pump on for 3 hours then off for 3 hours?

Post by MDB1029 »

Am i still off?

Code: Select all

ReefAngel.Relay.On(Port8);
if (hour()==03 && hour()<3) ReefAngel.Relay.Off(Port8);
if (hour()==09 && hour()<3) ReefAngel.Relay.Off(Port8);
if (hour()==15 && hour()<3) ReefAngel.Relay.Off(Port8);
if (hour()==21 && hour()<3) ReefAngel.Relay.Off(Port8);
If so, i may need a hint
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: a pump on for 3 hours then off for 3 hours?

Post by rimai »

That's going to turn port 8 off for 3 minutes at 3,9,15 and 21 hours.
This is an easy to understand code:

Code: Select all

ReefAngel.Relay.On(Port8);
if (hour()==03) ReefAngel.Relay.Off(Port8);
if (hour()==04) ReefAngel.Relay.Off(Port8);
if (hour()==05) ReefAngel.Relay.Off(Port8);
So, it would turn off for the full hour of hour 3,4 and 5.
Then you can go and repeat for the other hours you would like.
But, a more compact code that would do what you want would be:

Code: Select all

ReefAngel.Relay.Set(Port8, now()%21600<10800);
The code above would make port 8 turn on for 3 hours and off for 3 hours. Just a little bit harder to understand without some math knowledge behind it, but both would work for what you want. Different ways of coding.
Roberto.
MDB1029
Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio

Re: a pump on for 3 hours then off for 3 hours?

Post by MDB1029 »

rimai wrote:That's going to turn port 8 off for 3 minutes at 3,9,15 and 21 hours.
This is an easy to understand code:

Code: Select all

ReefAngel.Relay.On(Port8);
if (hour()==03) ReefAngel.Relay.Off(Port8);
if (hour()==04) ReefAngel.Relay.Off(Port8);
if (hour()==05) ReefAngel.Relay.Off(Port8);
So, it would turn off for the full hour of hour 3,4 and 5.
Then you can go and repeat for the other hours you would like.
But, a more compact code that would do what you want would be:

Code: Select all

ReefAngel.Relay.Set(Port8, now()%21600<10800);
The code above would make port 8 turn on for 3 hours and off for 3 hours. Just a little bit harder to understand without some math knowledge behind it, but both would work for what you want. Different ways of coding.

Code: Select all

ReefAngel.Relay.Set(Port8, now()%21600<10800);
So this in saying out of 21600 seconds, 10800 of those seconds the relay would be off?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: a pump on for 3 hours then off for 3 hours?

Post by rimai »

yes :)
Roberto.
MDB1029
Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio

Re: a pump on for 3 hours then off for 3 hours?

Post by MDB1029 »

Is this what it should look like in internal memory?

Code: Select all

    ReefAngel.Relay.Set(Port8, now()%21600<10800);
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: a pump on for 3 hours then off for 3 hours?

Post by lnevo »

This type of code would not use internal memory. If you wanted to be able to change any of the values, you'd have to put them in some custom memory locations. This is an advanced topic so if that's what you want we can walk you through the process. A good place to start would be to post your full code.
MDB1029
Posts: 178
Joined: Wed Nov 12, 2014 3:10 pm
Location: An Oklahoman in Ohio

Re: a pump on for 3 hours then off for 3 hours?

Post by MDB1029 »

I can just change the code when i need it changed. I don't need to be able to change it on the app or portal. I did get it working with the code above. Thanks Roberto!
Image
Post Reply