turning on feeding mode with code

Do you have a question on how to do something.
Ask in here.
Post Reply
martinresi
Posts: 20
Joined: Wed May 28, 2014 7:16 pm

turning on feeding mode with code

Post by martinresi »

Hi,

When I'm away I want the feeding mode to kick on automatically because i have an autofeeder set up. I searched the forum for code and I think I got it...

// enter feeding mode at 11am & 5pm
if (hour()==11 && minute()==00 || hour()==17 && minute()==00)
{
ReefAngel.FeedingModeStart(); // turn on feeding mode
}

Does this look right? Thanks!
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: turning on feeding mode with code

Post by rimai »

Almost. Use something like this:

Code: Select all

// enter feeding mode at 11am & 5pm
 if ( (hour()==11 && minute()==0 && second()==0) || (hour()==17 && minute()==0 && second()==0))
 {
 ReefAngel.FeedingModeStart(); // turn on feeding mode
 }
Roberto.
martinresi
Posts: 20
Joined: Wed May 28, 2014 7:16 pm

Re: turning on feeding mode with code

Post by martinresi »

Awesome thanks Roberto!

Also, where does RA controller get the time from? Does it get it from the computer that uploads the code, then keep it going with its own internal clock?
martinresi
Posts: 20
Joined: Wed May 28, 2014 7:16 pm

Re: turning on feeding mode with code

Post by martinresi »

I also was wondering if there was any way to toggle back and forth between the code where feeding mode turns on at 11 and 5, and the code where it never turns on and I do it manually when at home? or will I need to upload separate code each time I want to switch between the 2?

Thanks for all your help!
Todd
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: turning on feeding mode with code

Post by rimai »

The controller uses its own real time clock and keeps the time using a small battery inside of the controller.
You can change it using the smartphone app.
There are ways of coding what you want.
You can add a relay box expansion code, even though you don't have one, and use the relays as trigger.
Like this:

Code: Select all

  if (ReefAngel.Relay.isMaskOn(Box1_Port1))
  {
    // Do whatever you want when at home
  }
  else
  {
    // enter feeding mode at 11am & 5pm
     if ( (hour()==11 && minute()==0 && second()==0) || (hour()==17 && minute()==0 && second()==0))
     {
     ReefAngel.FeedingModeStart(); // turn on feeding mode
     }
  }
Then, everytime you override Box1_Port1 to always on with the smartphone app, it will not trigger the feeding modes automatically.
Returning Box1_Port1 to auto will make the controller start feeding automatically again.
Roberto.
martinresi
Posts: 20
Joined: Wed May 28, 2014 7:16 pm

Re: turning on feeding mode with code

Post by martinresi »

Wow! this is wonderful, thanks again Roberto, I'll give this a try
martinresi
Posts: 20
Joined: Wed May 28, 2014 7:16 pm

Re: turning on feeding mode with code

Post by martinresi »

The auto feeding code works like a charm! Now I'm trying the toggle code with auto/manual feeding. Does adding box1_port1 require any initialization? note: I coded it backwards from yours in the sense that default is manual mode (do nothing), and override is the auto feeding (at 11am & 5pm).

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 <ReefAngel.h>

/*
Ports assignment:

Port1 - N/A
Port2 - Lights - "http://www.reefangel.com/Support.Relay-function-StandardLights.ashx"
Port3 - Skimmer Feed Pump
Port4 - Aux Powerhead
Port5 - Heater - "http://www.reefangel.com/Support.Relay-function-StandardHeater.ashx"
Port6 - Main Powerhead - "http://www.reefangel.com/Support.Activating-a-relay.ashx"
Port7 - Skimmer Air pump
Port8 - Canister Filter
*/

void setup()
{
  ReefAngel.Init();
  ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
  ReefAngel.FeedingModePorts = Port3Bit | Port4Bit | Port6Bit | Port8Bit; // Turn off Ports 3, 4, 6 and 8 when feeding mode is activated
  ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit; // Turn off Port5, Port6 and Port8 when water change mode is activated
  ReefAngel.Relay.On(Port2); // Turn on Port 2
  ReefAngel.Relay.On(Port3); // Turn on Port 3
  ReefAngel.Relay.On(Port4); // Turn on Port 4
  ReefAngel.Relay.On(Port6); // Turn on Port 6 
  ReefAngel.Relay.On(Port7); // Turn on Port 7
  ReefAngel.Relay.On(Port8); // Turn on Port 8
}

void loop()
{
  ReefAngel.StandardHeater(Port5,775,785); // Heater on at 77.5F and off at 78.5F
  
  if (ReefAngel.Relay.isMaskOn(Box1_Port1))
  {
    // enter feeding mode at 11am & 5pm
    if ((hour()==11 && minute()==0 && second()==0) || (hour()==17 && minute()==0 && second()==0))
    {
      ReefAngel.FeedingModeStart();  // turn on feeding mode
    }
  }
  
  // This should always be the last line
  ReefAngel.Portal( "martinresi" );
  ReefAngel.ShowInterface();
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: turning on feeding mode with code

Post by rimai »

Are you sure you uploaded this code?
Your portal still shows only one relay box.
Roberto.
martinresi
Posts: 20
Joined: Wed May 28, 2014 7:16 pm

Re: turning on feeding mode with code

Post by martinresi »

This was the only new line of code i added:

if (ReefAngel.Relay.isMaskOn(Box1_Port1))
martinresi
Posts: 20
Joined: Wed May 28, 2014 7:16 pm

Re: turning on feeding mode with code

Post by martinresi »

Oh i get it, by putting it in the code it then shows up in the portal. Yes, I hadn't uploaded it yet. Ok now I did and I see it in the portal. Amazing! I'll test it but it looks like it's working correctly, thanks
Post Reply