Page 1 of 1

Not sure if I am using boolean correctly?

Posted: Thu Aug 15, 2013 6:03 am
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;
}

Re: Not sure if I am using boolean correctly?

Posted: Thu Aug 15, 2013 8:03 am
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.