How do you code to return to default settings of the ports, kind of like the water changes or feeding modes? I am finally trying to connect my power sensor alert. If the system triggers a power drop (and short term battery back-up kicks in) I want only a powerhead to run on battery until the power returns. I set it up with an 'if' statement to trigger the "power failure setting", but I'm not sure if it returns to 'normal' and back to business. Also, is there a simpler way like "ReefAngel.FeedingModePorts = B00110000" I could use rather than all these lines?
byte BatteryPower1;
byte BatteryPower2;
static boolean fSave = true;
void setup()
{
// other stuff
BatteryPower1 = Port3Bit;
BatteryPower2 = 0;
}
void loop()
{
// other stuff
if ( ! digitalRead(lowATOPin) )
{
// only execute once during power outage
if ( fSave )
{
// Force on the ports you want, turn them on if they are
// not already on
ReefAngel.Relay.RelayMaskOn = BatteryPower1;
ReefAngel.Relay.RelayMaskOnE[0] = BatteryPower2;
ReefAngel.Relay.RelayMaskOff = ~BatteryPower1;
ReefAngel.Relay.RelayMaskOffE[0] = ~BatteryPower2;
ReefAngel.Relay.Write();
fSave = false;
}
} else
{
// only execute once after power returns
if ( ! fSave )
{
// return everything back to where it should be in normal operation
ReefAngel.Relay.RelayMaskOn = 0;
ReefAngel.Relay.RelayMaskOnE[0] = 0;
ReefAngel.Relay.RelayMaskOff = 0xff;
ReefAngel.Relay.RelayMaskOffE[0] = 0xff;
ReefAngel.Relay.Write();
fSave = true;
}
}
ReefAngel.ShowInterface();
}
It should work properly for you. We have to put in the flag for saving otherwise every time through it would be trying to mask off/on the ports and calling Relay.Write() all the time. It won't "hurt" anything but there's no need to do that if it's not necessary. In fact, you could probably get rid of the Relay.Write() and let ShowInterface() handle it for you. Test it out and see what works for you. All you have to do is just change the ports like you would for Feeding and Water change.