Toggle ports for different modes

Related to the development libraries, released by Curt Binder
User avatar
Posts: 2754
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Sun Jan 15, 2012 8:16 am
The controller has a couple different built-in modes that can be entered.
  • Feeding Mode
  • Water Change Mode
  • Overheat Shutoff Mode - triggered when the overheat temperature is met or exceeded
  • Lights On Mode - triggered when Lights On menu item is selected (built in to Main menu, not in Simple menu or Custom menu (unless you add it in manually))

There are default ports that get toggled ON or OFF when entering and exiting the respective mode.
  • Feeding - Ports 8, 6, 5
  • Water Change - Ports 8, 6, 5
  • Overheat Shutoff - Ports 3
  • Lights On - Ports 3, 2

Note: This is for the main relay only.
These are set inside your PDE/INO file. There are 2 ways to change these ports.

1. Through the wizard. The wizard will prompt you for this and do it all for you.
2. Manually add to your PDE/INO file. This is done as follows:
Code: Select all
void setup()
    ReefAngel.Init();  //Initialize controller

    // Set the ports that get toggled on & off during the following modes
    // To enable a port to be toggled, place a 1 in the appropriate position
    // Uncomment and update as needed
    //                           Port   87654321
    //ReefAngel.FeedingModePorts =     B10110000;
    //ReefAngel.WaterChangePorts =     B10110000;
    //ReefAngel.OverheatShutoffPorts = B00000100;
    //ReefAngel.LightsOnPorts =        B00000110;

  // Rest of code goes here ....
Note: Make sure you UNCOMMENT and update the line as needed. Uncommenting means to remove the double slash (//) in front of the line.

If you are running 0.9.0 or later libraries, you can still use the above mentioned way OR you can use an easier to read way:
Code: Select all
    ReefAngel.FeedingModePorts = Port5Bit | Port6Bit | Port8Bit;
    ReefAngel.WaterChangePorts = Port5Bit | Port6Bit | Port8Bit;
    ReefAngel.OverheatShutoffPorts = Port3Bit;
    ReefAngel.LightsOnPorts = Port2Bit | Port3Bit;

The | between the Port bits is the Vertical Bar ( | ) and not a lowercase l or uppercase I or 1.
Doing it this way is a little easier to read and edit. Both ways accomplish the same thing.

For those who have an expansion relay, you must edit your PDE/INO file manually (like option 2 above). Going along with the example above, you need to add the following to the setup for the expansion relays.
Code: Select all
//                             Port   87654321
ReefAngel.FeedingModePortsE[x] =     B00000000;
ReefAngel.WaterChangePortsE[x] =     B00000000;
ReefAngel.OverheatShutoffPortsE[x] = B00000000;
ReefAngel.LightsOnPortsE[x] =        B00000000;

Inside the code, you will see [ x ] at the end of the variable. That refers to the index / position in the array of relay boxes. The index will change based on what expansion relay you are referring to. The index for the expansion relays are as follows:
Code: Select all
0 - Expansion Relay 1
1 - Expansion Relay 2
2 - Expansion Relay 3
3 - Expansion Relay 4
4 - Expansion Relay 5
5 - Expansion Relay 6
6 - Expansion Relay 7
7 - Expansion Relay 8
Note: A simple way to figure the index for the expansion relay is to subtract 1 off of the Expansion Relay Number.

Going off of that index example, here are some code examples:
Code: Select all
// Expansion Relay 1
//                             Port   87654321
ReefAngel.FeedingModePortsE[0] =     B00000000;
ReefAngel.WaterChangePortsE[0] =     B00000000;
ReefAngel.OverheatShutoffPortsE[0] = B00000000;
ReefAngel.LightsOnPortsE[0] =        B00000000;

// Expansion Relay 2
//                             Port   87654321
ReefAngel.FeedingModePortsE[1] =     B00000000;
ReefAngel.WaterChangePortsE[1] =     B00000000;
ReefAngel.OverheatShutoffPortsE[1] = B00000000;
ReefAngel.LightsOnPortsE[1] =        B00000000;

To explain the code, NO ports are toggled ON or OFF when you enter the various modes. Just like with the main relay, you must add a 1 to the position of the port to toggle it during the modes.

Once added to your PDE/INO file, you upload the file to the controller and now your controller will toggle those ports ON/OFF when you enter the modes.
Last edited by binder on Tue Jan 01, 2013 6:01 pm, edited 2 times in total.
Reason: Updated default ports toggled. Added code example for 0.9.0 libraries and later.

Return to Development Libraries

Who is online

Users browsing this forum: No registered users and 2 guests