return to defaults

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

return to defaults

Post by jsclownfish »

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?

Thanks,
Jon

Code: Select all

// lowATO pin used as a power sensor coonected to 5V wall wart
  if (!digitalRead(lowATOPin))
  {
    ReefAngel.Relay.Off(Port1);
    ReefAngel.Relay.Off(Port2);
    ReefAngel.Relay.On(Port3);
    ReefAngel.Relay.Off(Port4);
    ReefAngel.Relay.Off(Port5);
    ReefAngel.Relay.Off(Port6);
    ReefAngel.Relay.Off(Port7);
    ReefAngel.Relay.Off(Port8);
    ReefAngel.Relay.Off(Box1_Port1);
    ReefAngel.Relay.Off(Box1_Port2);
    ReefAngel.Relay.Off(Box1_Port3);
    ReefAngel.Relay.Off(Box1_Port4);
    ReefAngel.Relay.Off(Box1_Port5);
    ReefAngel.Relay.Off(Box1_Port6);
    ReefAngel.Relay.Off(Box1_Port7);
    ReefAngel.Relay.Off(Box1_Port8);
  }
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: return to defaults

Post by binder »

What you could do is something like this....
  • define a list of "ports to run on battery", since you have expansion boxes, you will want 2 variables
  • when the trigger is flipped, mask off the ports
  • keep like that until your power is restored
  • clear the mask and resume operations
This would be a very generic code sample:

Code: Select all


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.
Post Reply