How to set time for Feeding Mode

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: How to set time for Feeding Mode

Post by lnevo »

Try this instead

Code: Select all

if ( (now()%(SECS_PER_HOUR*17)==0) || (now()%(SECS_PER_HOUR*21)==0) ) {
  FeedingModeStart();
}
Added some parens to make sure the math was in correct order.
kirkwood
Posts: 173
Joined: Mon Apr 29, 2013 6:50 am

Re: How to set time for Feeding Mode

Post by kirkwood »

I loaded the new code and it did not go into feeding mode at 21:00
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: How to set time for Feeding Mode

Post by lnevo »

Lets eliminate math problems...

Do now()%75600==0 for 9pm and 61200 for 5pm

If it still doesnt work then I'll need to see your whole code because you may have a delay somewhere that would cause that code not to get hit each second...

It may also be why your pump is logging extra seconds if you have something taking too much time in your code.

If thats the case we can change the logic to just do it when the hour and minute are at 5pm and 9pm.
kirkwood
Posts: 173
Joined: Mon Apr 29, 2013 6:50 am

Re: How to set time for Feeding Mode

Post by kirkwood »

kirkwood wrote:I loaded the new code and it did not go into feeding mode at 21:00
Well I reloaded the old code at 945 because I wasn't 100% sure the cable was fully connected to the RA the previous time I tried to upload. Anyway the feeding mode ran at 2200 which I thought meant it was going to run every hour. However it did NOT run at 2300 or 0000. So that's a good thing. I will see how it continues to play out before I try the new code.
Image
kirkwood
Posts: 173
Joined: Mon Apr 29, 2013 6:50 am

Re: How to set time for Feeding Mode

Post by kirkwood »

I still can't get the feeding mode to run properly. I just loaded in the simplified code that eliminated all the math and the feeding mode did not run at 9pm. Here is my full code.

#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 <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
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port5Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port6Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 825 );


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

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


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

void loop()
{
ReefAngel.MHLights( Port1,16,0,23,0,5 );
ReefAngel.MHLights( Port2,17,0,21,30,10 );
ReefAngel.DosingPumpRepeat( Port3,0,120,292 );
ReefAngel.DosingPumpRepeat( Port4,60,120,340 );
ReefAngel.StandardHeater( Port6,775,805 );
ReefAngel.StandardATO( Port7,900 );
////// Place your custom code below here

//Start Feeding Mode at 17:00 and 21:00
if ( (now()%61200==0) || (now()%75600==0) ) {
ReefAngel.FeedingModeStart();
}

const byte numPumps=3;
byte pump[numPumps] = { Port3, Port4, Port7 };
byte portalMinutes[numPumps] = { 0, 2, 4 };
byte portalSeconds[numPumps] = { 1, 3, 5 };

static time_t pumpTimer[numPumps];
static boolean pumpStatus[numPumps];
static boolean atoDisabled;

for (int i=0;i< numPumps;i++) {
if (ReefAngel.Relay.Status(pump)) {
if (!pumpStatus) {
pumpTimer=now()-pumpTimer; // Pump was off, timer is now a time
pumpStatus=true;
}
} else {
if (pumpStatus) {
pumpTimer=now()-pumpTimer; // Pump was on, timer is now a timer
pumpStatus=false;

// Normalize and assign to CustomVar for reporting on the portal
ReefAngel.CustomVar[portalMinutes]=pumpTimer[i]/60; // Number of Minutes
ReefAngel.CustomVar[portalSeconds[i]]=pumpTimer[i]%60; // Number of Seconds
}
}
}


if (now()%SECS_PER_DAY==SECS_PER_DAY-1) pumpTimer[0]=0; // Clear timer for DPump1
if (now()%SECS_PER_DAY==SECS_PER_DAY-1) pumpTimer[1]=0; // Clear timer for DPump2

if (bitRead(ReefAngel.Relay.RelayMaskOn, 6)==1) { // ATO relay was forced on
atoDisabled=true; // don't want to change the variable names yet.. but you may want to to make it clearer..
}
if (atoDisabled && (bitRead(ReefAngel.Relay.RelayMaskOn, 6)==0)) { // ATO override has been cleared
pumpTimer[2]=0; // Clear timer for ATOPort
atoDisabled=false;
}

////// Place your custom code above here

// This should always be the last line
ReefAngel.Portal( "kirkwood" );
ReefAngel.ShowInterface();
}
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: How to set time for Feeding Mode

Post by rimai »

Well... I guess the math is wrong :(
It took me a good 5 minutes and a few scratches in my head saying WTF is going on??? LOL
We need to actually do module of 24hrs and check the remainder for the hours you want...
So, here it is:

Code: Select all

if ( (now()%86400==61200) || (now()%86400==75600) ) {
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: How to set time for Feeding Mode

Post by lnevo »

Wow good catch. I'm losing it these days... :)
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: How to set time for Feeding Mode

Post by binder »

lnevo wrote:Wow good catch. I'm losing it these days... :)
are you sure you ever had it to begin with??? ;-)
i know that feeling all too well.

Sent from my Nexus 7
kirkwood
Posts: 173
Joined: Mon Apr 29, 2013 6:50 am

Re: How to set time for Feeding Mode

Post by kirkwood »

Sweet I will try the new code tomorrow. I've got a trip coming up soon so I'm trying to have everything set up just right before I go. With the RA this will be the first true stress free vacation. ;-)
Image
kirkwood
Posts: 173
Joined: Mon Apr 29, 2013 6:50 am

Re: How to set time for Feeding Mode

Post by kirkwood »

The new code worked great today. Thanks!
Image
User avatar
ewaldsreef
Posts: 82
Joined: Tue Oct 08, 2013 8:22 pm
Location: Salt Lake City, UT
Contact:

Re: How to set time for Feeding Mode

Post by ewaldsreef »

Found this post on a search. Looks like its an older one but is this code the best way to activate feedmode at a set time each day?
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: How to set time for Feeding Mode

Post by binder »

ewaldsreef wrote:Found this post on a search. Looks like its an older one but is this code the best way to activate feedmode at a set time each day?
yes, this is the best way to do that. even though the code is old, it is still valid and the only way to do it.


Sent from my iPad mini
User avatar
ewaldsreef
Posts: 82
Joined: Tue Oct 08, 2013 8:22 pm
Location: Salt Lake City, UT
Contact:

Re: How to set time for Feeding Mode

Post by ewaldsreef »

Glad I found this old post. Tried the code and it works perfectly.
Image
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: How to set time for Feeding Mode

Post by binder »

ewaldsreef wrote:Glad I found this old post. Tried the code and it works perfectly.
Awesome!


Sent from my iPad mini
Post Reply