I wrote some code to carry out an automatic water change (AWC) with a bunch of checks built in. My AWC() function returns a boolean that = true if the AWC succeeded and = false if it failed for any reason. The problem is that whenever I manually call this function on my RA using a custom menu option, the RA just goes blank for about one second and then appears to reboot. Here's the code code for the function:
Code: Select all
//This function will carry out an automatic water change.
boolean AWC()
{
if (!ReefAngel.Relay.Status(returnPump)) //If the return pump is not on, don't run an AWC and return 0 (false).
{
return 0;
}
if (!ReefAngel.HighATO.IsActive())
{
AWCTimer = now();
ReefAngel.Relay.On(ATOPump); //Fill the return section to the high float with RODI.
while (true)
{
if (ReefAngel.HighATO.IsActive())
{
ReefAngel.Relay.Off(ATOPump); //Turn off the RODI pump once the high float is triggered.
break;
}
else if ((now() - AWCTimer) >= ATOTimeOut)
{
ReefAngel.Relay.Off(ATOPump); //Turn off the RODI pump.
bitSet(ReefAngel.AlertFlags,ATOTimeOutFlag); //Trigger ATO timeout flag.
return 0; //Return 0 (false) if the ATO times out.
}
}
}
ATOOn = false;
AWCTimer = now();
ReefAngel.Relay.On(AWCDrainPump); //Turn on the AWC drain pump.
while (true)
{
if (ReefAngel.LowATO.IsActive())
{
ReefAngel.Relay.Off(AWCDrainPump); //Turn off the AWC drain pump.
break;
}
else if ((now() - AWCTimer) >= AWCDrainSecs)
{
ReefAngel.Relay.Off(AWCDrainPump); //Turn off the AWC drain pump.
bitSet(ReefAngel.AlertFlags,ATOTimeOutFlag); //Trigger ATO timeout flag.
ATOOn = true;
return 0; //Return 0 (false) if the AWC times out.
}
}
AWCTimer = now();
ReefAngel.Relay.On(AWCFillPump); //Turn on the AWC fill pump.
while (true)
{
if (ReefAngel.HighATO.IsActive())
{
ReefAngel.Relay.Off(AWCFillPump); //Turn off the AWC fill pump.
break;
}
else if ((now() - AWCTimer) >= AWCFillSecs)
{
ReefAngel.Relay.Off(AWCFillPump); //Turn off the AWC fill pump.
bitSet(ReefAngel.AlertFlags,ATOTimeOutFlag); //Trigger ATO timeout flag.
ATOOn = true;
return 0; //Return 0 (false) if the AWC times out.
}
}
ATOOn = true;
return 1; //If the AWC ran successfully, return 1 (true).
}
Thanks in advance for the help!