Page 1 of 1

What kind of variable to use to change a port reference?

Posted: Mon Oct 20, 2014 3:42 pm
by gaberosenfield
Hi RA users and admins,

I am in the process of writing code to control my new setup, in which automation is the name of the game. I am programming in an "acclimation mode" as an option that I can turn on when I want to drip acclimate a new arrival. Basically, all that will change during acclimation mode is that instead of my ATO pumping in RODI water when the low float switch in my sump is triggered, my automatic water change pump will pump in saltwater to replace the water lost from my main system that is dripping into my acclimation tank. I already know how to use the #define command, but this can only be run once when the code is loaded. What I want to know is what kind of variable I can use to refer to a certain port that can be changed while my program is running. Will a string work? I want to be able to do something like this:

Code: Select all

#define AWCFillPump Box1_Port2
#define ATOPump Box1_Port3

boolean acclimationMode = false;

int ATOTimeOut = 300;  //ATO timeout in seconds

string fillPump = ATOPump;

if (acclimationMode == true)
{
  ATOTimeOut = 60;
  
  fillPump = AWCFillPump;
}

if(acclimationMode == false)
{
  ATOTimeOut = 300;

  fillPump = ATOPump;
}

ReefAngel.StandardATO(fillPump, ATOTimeOut);
Will the above code work? Or is there any other variable type that can make it work? Or, if not, is there another way I can accomplish the same thing?

Thanks in advance!

Re: What kind of variable to use to change a port reference?

Posted: Mon Oct 20, 2014 3:55 pm
by lnevo
Ports are bytes. Just change it to a byte and you can do

byte fillPump = ATOPump;

Re: What kind of variable to use to change a port reference?

Posted: Mon Oct 20, 2014 4:57 pm
by gaberosenfield
Exactly what I wanted to know. Thanks Inevo!