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

Do you have a question on how to do something.
Ask in here.

Posts: 80
Joined: Thu Mar 08, 2012 5:11 pm
Location: Oakland, California
PostPosted: Mon Oct 20, 2014 3:42 pm
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!
Gabe's Grad Reef
Image
User avatar
Posts: 5409
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Oct 20, 2014 3:55 pm
Ports are bytes. Just change it to a byte and you can do

byte fillPump = ATOPump;

Posts: 80
Joined: Thu Mar 08, 2012 5:11 pm
Location: Oakland, California
PostPosted: Mon Oct 20, 2014 4:57 pm
Exactly what I wanted to know. Thanks Inevo!
Gabe's Grad Reef
Image

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 1 guest

cron