Not sure if I am using boolean correctly?

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

Not sure if I am using boolean correctly?

Post by dazza1304 »

Hi, I have been running this code for a little while and it doesnt seem to perform always as I would expect?

Could it be that I am not using the boolean properly, by setting to true and then setting to false?

For example here - SALduration=false;
Watduration=false;

Instead of this, should I use SALduration=!SALduration;
Watduration=!Watduration;

Or does it not make any difference??



// If salinity >33.1 for 120 sec set SALduration flag;salinity debounce
if (SalCompensation<331) lastLowSal=now();
if (now()-lastLowSal>120) SALduration=true;

///// If WL < 35 for 120 sec set Watduration flag;Waterlevel debounce
if (ReefAngel.WaterLevel.GetLevel()>35) lastLoWat=now();
if (now()-lastLoWat>120) Watduration=true;

//if salinty >33.1 and waterlevel <35, top up with RO water until WL =40
if (SALduration==true && Watduration==true) ROtopup=true;
if (ROtopup==true) ReefAngel.Relay.On(Port1);
if (ROtopup==true && ReefAngel.WaterLevel.GetLevel()>40)

{
ReefAngel.Relay.Off(Port1);
ROtopup=false;
SALduration=false;
Watduration=false;
}

//if salinty <33.1 and waterlevel < 35, top up with SALT water until WL = 40
if (SALduration==false && Watduration==true) SALTtopup=true;
if (SALTtopup==true) ReefAngel.Relay.On(Port2);
if (SALTtopup==true && ReefAngel.WaterLevel.GetLevel()>40)

{
ReefAngel.Relay.Off(Port2);
SALTtopup=false;
Watduration=false;
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Not sure if I am using boolean correctly?

Post by rimai »

=false would always make the value false
=! would flip the state. So, if it was false, it becomes true and if it was true, it becomes false.
Roberto.
Post Reply