TimedPort Class

Do you have a question on how to do something.
Ask in here.
User avatar
Posts: 5343
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Jan 22, 2016 9:36 am
Hi everyone. I wanted to start a thread on the usage of the TimedPort class. This is essentially a Class to define a Relay with some properties. Right now it's similar to the DosingPumpRepeat function but with additional features. Here are some examples of things you could do

1. Have a defined runtime, offset, delay (like DelayedPort), repeat - Easy stuff
2. Have a defined StartTime and StopTime (say you want to shut off a pump but only for 10 minutes...) or you want to manually trigger a relay but only want it to run for 5 minutes (when it's normal programming is for 20)
3. Pause/Resume
4. Load/Save settings to/from memory

In the future, I would like to extend this class to a DosingPump class so that it could have parameters like Volume, and Rate and Calibration.

To start off, you will need to define the class

Code: Select all
TimedPort mainPump;

void setup() {
  mainPump.Scale=60; // in minutes (use 1 for seconds, 360 for hours...)
  mainPump.Save(100); // Will save in memory location 100-115 (16 bytes are required)

Now in order to have the port run the way we want, we need a call to mainPump.Run() in loop. Also since we're using memory to store the info, you need to refresh from memory also in loop

Code: Select all
void loop() {

So this will run the mainPump based on the settings I declared in setup. The pump will run for 1 hour and repeat every 2 hours.

If you wanted a 10 minutes offset, it's easy

Code: Select all

If you wanted a 5 minute delay after startup, or mode changes

Code: Select all

Now for me, this pump is the mixing pump for my saltwater station so when I do a new batch of salt, I want it to run for 12 hours, not the usual 60. I don't want to have to remember to turn it off 12 hours later... so we can do something like this:

Code: Select all
if (ReefAngel.Relay.isMaskOn(Port1)) {

So now I've turn the port on and triggered the Start of the TimedPort. Based on the settings it will now run for 12 hours. I then reset the Relay Mask so it will not stay on forever.

The same could be done for Stop()

Code: Select all
if (ReefAngel.Relay.isMaskOff(Port1)) {

So now the pump will be disabled for 15 minutes based on the StopTime I have set. This is great if you want to turn off your skimmer because you glued some frags and don't want to forget to turn it back on for instance.

Now, the Run() command I mentioned earlier is only needed for managing the timed operations for start/stop and to auto run the schedule. You can also use this without using Run by using the normal Relay commands.


and another usage that is nice is Osc. Osc is similar to the Apex usage.


This will run with 0 offset, for 60 minutes on then 60 minutes off, and true for ON. This is actually called by the Run() command along with the other timer monitoring.

There is more commands that I did not discuss, but most are self explanatory, such as the following.

Toggle(), Pause(), Resume(), SetActive(), IsRunning(), IsStarted(), IsStopped(), IsActive()

Hope this helps people get started with this functionality.

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 1 guest