Simple bit of coding help please!!

Do you have a question on how to do something.
Ask in here.
Post Reply
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Simple bit of coding help please!!

Post by dazza1304 »

Ok, I want to use the ATO low and high switches to do the following:

ATO High active , turn off the skimmer until the switch reads low, then when switch not active skimmer switched on.
Why - switch is skimmer lid to stop skimmer overflowing

ATO Low active , disable my ATO pump until switch is not active, then when non active, allow the ATO pump to be controlled as normal (currently controlling ATO pump based off salinity.
Why - to stop ATO pump and send email when ATO reservoir empty.

I look forward to your help!!
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Re: Simple bit of coding help please!!

Post by dazza1304 »

OK, I am trying to work through this myself, but have a few questions.
Taking it one bit at a time and my first bit is to get the skimmer turning off and on correctly.

Currently I have the skimmer set (port 7), so that when reset or power off, there is a 10 min delay.

I have come up with the code below, but the bit of code "else ReefAngel.Relay.On( Port7 )" seems to override the delay on, which makes sense as I guess as I am turning the port on with that instruction.

So how do I code so that if the delayed time on is invoked, that takes precedence over the "else ReefAngel.Relay.On( Port7 )" instruction??

void loop()
{
ReefAngel.Relay.DelayedOn( Port7,10 );
ReefAngel.StandardHeater( Port6,259,261 );
ReefAngel.StandardFan( Port7,260,263 );
////// Place your custom code below here
if (ReefAngel.Params.Salinity<351) lastLowSal=now();
ReefAngel.Relay.Set(Port1,(now()-lastLowSal>120));
if (ReefAngel.HighATO.IsActive()) ReefAngel.Relay.Off(Port7); else ReefAngel.Relay.On( Port7 );
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Simple bit of coding help please!!

Post by lnevo »

I use a mask instead of turning on an off if the float switch is triggered. This way you set the mask or clear the mask but you don't turn it on if it should be off.

Code: Select all

    if (ReefAngel.LowATO.IsActive()) {
      bitClear(ReefAngel.Relay.RelayMaskOff,Return-1);
      }
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Re: Simple bit of coding help please!!

Post by dazza1304 »

lnevo wrote:I use a mask instead of turning on an off if the float switch is triggered. This way you set the mask or clear the mask but you don't turn it on if it should be off.

Code: Select all

    if (ReefAngel.LowATO.IsActive()) {
      bitClear(ReefAngel.Relay.RelayMaskOff,Return-1);
      }
Hi, thanks for the reply, and I can see how the mask function will do what I want, the only problem, is I dont understand the syntax!!
What does this bit mean? bitClear(ReefAngel.Relay.RelayMaskOff,Return-1)

And how do I relate that to "masking" Port 7 of the relay box?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Simple bit of coding help please!!

Post by lnevo »

Replace Return-1 with 6 for port 7. The mask bits are set from 0-7 for ports 1-8.

Clearing the OffMask for that port enables that mask. Whereas for the OnMask you'll want to bitSet. You can also override the OffMask with bitSet.
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Re: Simple bit of coding help please!!

Post by dazza1304 »

Well, I have got it working, but it seems to be reversed?

So, I have set port 8 with a 1 minute delay to test.

During this 1 minute delay, everything is as I would expect, port 8 stays off, regardless of the state of the float switch.

After the 1 minute delay, port 8 is still off, but when the float switch is active, the port switches on, and not active the port switches off.

Below is my code, I am sure it is something simples that I have done wrong!!!!

ReefAngel.Relay.DelayedOn( Port8,1 );
////// Place your custom code below here
if (ReefAngel.HighATO.IsActive()) {
bitSet(ReefAngel.Relay.RelayMaskOff,7);
}
else {
bitClear(ReefAngel.Relay.RelayMaskOff,7);
}
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Re: Simple bit of coding help please!!

Post by dazza1304 »

Well, I changed the code around to this, and it works, fine, but I am confused as to why!!!

if (ReefAngel.HighATO.IsActive()) {
bitClear(ReefAngel.Relay.RelayMaskOff,7);
}
else {
bitSet(ReefAngel.Relay.RelayMaskOff,7);
}
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple bit of coding help please!!

Post by rimai »

The maskoff variable is an AND bit comparison.
The default state is 255, so clearing a bit means turning off the port.
Roberto.
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Re: Simple bit of coding help please!!

Post by dazza1304 »

rimai wrote:The maskoff variable is an AND bit comparison.
The default state is 255, so clearing a bit means turning off the port.
So if I understand you correctly with this code below:
bitClear(ReefAngel.Relay.RelayMaskOff,7);
}

I am setting a bit mask for bit 7 with a "0" from the bitclear function, making it always a zero output

and then with this code below:
else {
bitSet(ReefAngel.Relay.RelayMaskOff,7);

I am setting a bit mask for bit 7 with a "1"with the bit set function which then allows the output to follow the auto function?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple bit of coding help please!!

Post by rimai »

Correct.
The same concept applies to mask on, except the maskon is a OR bit comparison.
The default value is 0 and setting a bit means turning on that port and clearing the bit means returning to auto.
The only thing you must be careful is to not cause the masks to be out of sync.
You should never have a maskon bit set to 1 while maskoff bit is set to 0. This state would mean you are trying to override on and override off at the same time, which should never exist.
These should be the valid states:
Auto: maskon=0 and maskoff=1
Override On: maskon=1 and maskoff=1
Override Off: maskon=0 and maskoff=0
Invalid: maskon=1 and maskoff=0
Roberto.
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Re: Simple bit of coding help please!!

Post by dazza1304 »

Cool- I understand why my code works now!

Thanks Roberto!

No more having to worry about the skimmer overflowing!
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple bit of coding help please!!

Post by rimai »

Yeap :)
I do the same thing... I drain my skimmate to an external container and have a float switch as safety too.
My tank is in the living room and I have no place to drain, so I have to store it in a container.
The container handled 2 1/2 weeks of my vacation just fine :)
I just returned yesterday and it was 3/4 full.
Roberto.
jerkyjunky
Posts: 12
Joined: Wed Nov 07, 2012 10:08 am

Re: Simple bit of coding help please!!

Post by jerkyjunky »

I hate to sound ignorant, but I feel as if I am. What is the difference in setting the mask on the relay verses simply turning the port on and off? Don't they accomplish the same thing?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Simple bit of coding help please!!

Post by lnevo »

By using the on/off commands directly, he was overriding the DelayedOn setting for the port. By using the mask the ato switch applies an override instead of messing with standard behavior.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Simple bit of coding help please!!

Post by rimai »

The masks are a way to override a port, regardless of what the port is programmed to do.
That's what the Portal or smart phone apps do when you want to override any port.
Roberto.
jerkyjunky
Posts: 12
Joined: Wed Nov 07, 2012 10:08 am

Re: Simple bit of coding help please!!

Post by jerkyjunky »

I see! ;)
Post Reply