Countdown timer for relay

Community contributed apps
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Oct 10, 2015 8:43 am
Pretty sure there's an issue, and if not, it's still a red flag so I registered an issue https://github.com/reefangel/Libraries/issues/222 and will be submitting a patch. If using this for any critical dosing, I would hesitate. I'll put the patch up here as well to make it easier for people to grab, since I'll be submitting it to the current dev repository.
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Oct 10, 2015 8:46 am
Well in defense of my code, I will say that if you are setting it up for dosing, it will work properly. The issue at the moment is that if Repeat is set to 0 or is less than the Time setting, then you could have an issue. Also the TimedPort has a separate value for Time and triggered time (StartTime) so instead of saying swabbie.Time=120; I would have used swabbie.StartTime=120; The difference is if you are automating you may want 5 seconds every hour, but if you explicitly start it, you might want it for 10 seconds. I clearly need to put some documentation into this class :) I haven't looked at it in a while so having to figure out how it works again.
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Oct 10, 2015 10:45 am
Ok so I added a sanity check and a few comments to make it clearer. I'm also going to see if I can find the post where I originally posted it as the discussion might lend itself better in there. Here's the patched class. Just unzip it in your Libraries folder and it should overwrite the existing folder.

TimedPort.zip
(3.29 KiB) Downloaded 83 times
User avatar
Posts: 2746
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Sat Oct 10, 2015 6:44 pm
I will take a look at it this week. kinda busy this week.

Sent from my Moto X
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Oct 11, 2015 5:04 am
Awesome!

Posts: 173
Joined: Fri May 23, 2014 8:09 am
PostPosted: Sun Oct 11, 2015 9:13 am
lnevo wrote:Just change Box1_Port2 to whatever port you want to control and then use the repeat and runtime to set how long you want the port to run and how often to repeat. If you don't want it to repeat then just take out the else statement at the end.


I'm still a bit confused about how and where to post code. Can I put this in the custom code area?
Image
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Oct 11, 2015 9:14 am
Yep

Posts: 173
Joined: Fri May 23, 2014 8:09 am
PostPosted: Sun Oct 11, 2015 11:08 am
lnevo wrote:Yep


Oh dear, I'm doing something wrong.

Code: Select all
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <DCPump.h>
#include <PAR.h>
#include <ReefAngel.h>

////// Place global variable code below here


////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen
    ReefAngel.AddSalinityExpansion();  // Salinity Expansion Module
    ReefAngel.AddWaterLevelExpansion();  // Water Level Expansion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port7Bit | Port8Bit;
    ReefAngel.FeedingModePortsE[0] = 0;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port7Bit | Port8Bit;
    ReefAngel.WaterChangePortsE[0] = 0;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port2Bit;
    ReefAngel.OverheatShutoffPortsE[0] = 0;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;


    // Ports that are always on
    ReefAngel.Relay.On( Port3 );

    ////// Place additional initialization code below here
   

    ////// Place additional initialization code above here
}

void loop()
{
    ReefAngel.StandardFan( Port1,784,790 );
    ReefAngel.StandardHeater( Port2,780,785 );
    ReefAngel.Relay.DelayedOn( Port4,8 );
    ReefAngel.Relay.DelayedOn( Port5,8 );
    ReefAngel.WaterLevelATO( Port7,3600,80,100 );
    ReefAngel.Relay.DelayedOn( Port8,10 );
    ReefAngel.StandardLights( Box1_Port1,8,0,21,0 );
    ReefAngel.StandardLights( Box1_Port2,8,0,21,0 );
    ReefAngel.StandardLights( Box1_Port3,8,0,21,0 );
    ReefAngel.StandardLights( Box1_Port4,8,0,21,0 );
    ReefAngel.PWM.SetChannel( 0, PWMSlope(8,0,21,0,10,50,65,10) );
    ReefAngel.PWM.SetChannel( 1, PWMSlope(8,0,21,0,9,30,65,9) );
    ReefAngel.PWM.SetChannel( 2, PWMSlope(8,0,21,0,8,50,65,8) );
    ReefAngel.PWM.SetChannel( 3, PWMSlope(8,0,21,0,6,30,65,6) );
    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.SetMode( LongPulse,90,10 );
    ReefAngel.DCPump.DaylightChannel = Sync;
    ReefAngel.DCPump.ActinicChannel = AntiSync;
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = None;
    ReefAngel.DCPump.ExpansionChannel[2] = None;
    ReefAngel.DCPump.ExpansionChannel[3] = None;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
    if(ReefAngel.HighATO.IsActive())
{
ReefAngel.Relay.Override(Port8,0);
ReefAngel.Relay.On(Port8);
}
  int repeat=3600; // in minutes
  int runtime=120; // in seconds
  static time_t t;
 
  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Box2_Port6)) {
    ReefAngel.Relay.Auto(Box2_Port6);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Box2_Port6);
  } else {
    ReefAngel.DosingPumpRepeat(Box2_Port6,0,repeat,runtime);   
  } 
     ////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "paperdesk" );
    ReefAngel.ShowInterface();
Image
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sun Oct 11, 2015 11:17 am
What error are you getting?

Posts: 173
Joined: Fri May 23, 2014 8:09 am
PostPosted: Sun Oct 11, 2015 11:45 am
I don't get an error, it just doesn't do anything. When I toggle the port it stays on and never turns off unless I toggle it again.
Image
PreviousNext

Return to Apps

Who is online

Users browsing this forum: No registered users and 2 guests

cron