TimedPort Class
Posted: 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
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
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
If you wanted a 5 minute delay after startup, or mode changes
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:
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()
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.
mainPump.On();
mainPump.Off();
mainPump.DelayedOn();
and another usage that is nice is Osc. Osc is similar to the Apex usage.
mainPump.Osc(0,60,60,true);
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.
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.Init();
mainPump.ID=Box1_Port1;
mainPump.Time=60;
mainPump.Repeat=120;
mainPump.StartTime=720;
mainPump.StopTime=15;
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)
}
Code: Select all
void loop() {
mainPump.Load(100);
mainPump.Run();
}
If you wanted a 10 minutes offset, it's easy
Code: Select all
mainPump.Offset=10;
Code: Select all
mainPump.Delay=5;
Code: Select all
if (ReefAngel.Relay.isMaskOn(Port1)) {
mainPump.Start();
ReefAngel.Relay.Auto(Port1);
}
The same could be done for Stop()
Code: Select all
if (ReefAngel.Relay.isMaskOff(Port1)) {
mainPump.Stop();
ReefAngel.Relay.Auto(Port1);
}
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.
mainPump.On();
mainPump.Off();
mainPump.DelayedOn();
and another usage that is nice is Osc. Osc is similar to the Apex usage.
mainPump.Osc(0,60,60,true);
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.