ReefAngel.LightsOn(); during feeding then off when exit

Do you have a question on how to do something.
Ask in here.
Post Reply
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

ReefAngel.LightsOn(); during feeding then off when exit

Post by Smotz »

Hi All,

Can someone help me with this?

I want to turn my my ReefAngel.LightsOn(); when I enter feeding mode and water change mode but then I want the lights to go off when I exit the mode.

I can turn the lights on but how to I turn them off - I was thinking :

Code: Select all

  if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE)
    {
    ReefAngel.PWM.SetActinic(0);
    ReefAngel.PWM.SetDaylight(0);
    ReefAngel.LightsOn();
    }
    else ReefAngel.LightsOff();    
But (logically speaking) that will turn my lights off all the other times. - Don't want that :)

any thoughts?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by rimai »

You don't need the else.
Also, instead of LightsOn(), use Relay.On(Port1)
Roberto.
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by Smotz »

rimai wrote:You don't need the else.
Also, instead of LightsOn(), use Relay.On(Port1)
but that wont turn it off when the mode is exited..
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by rimai »

Is it a fact or speculation?
If fact, please post your code.
Roberto.
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by Smotz »

rimai wrote:Is it a fact or speculation?
If fact, please post your code.
speculation. Let me test..
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by rimai »

The reason it won't stay on is that the Relay.On is actually overriding your StandardLights function.
The order is important though.
The StandardLights has to come before your if statement.
If positioned like that, when you enter water change mode, the Relay.On function will force the port to be on instead of whatever StandardLights is setup for.
When not in water change mode, the StandardLights will still control the port on/off as normal.
Roberto.
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by Smotz »

rimai wrote:The reason it won't stay on is that the Relay.On is actually overriding your StandardLights function.
The order is important though.
The StandardLights has to come before your if statement.
If positioned like that, when you enter water change mode, the Relay.On function will force the port to be on instead of whatever StandardLights is setup for.
When not in water change mode, the StandardLights will still control the port on/off as normal.
I actually don't have a StandardLights statement.

how should I have that formatted? (code below)

Code: Select all

////  Port 1			Heater
////  Port 2			ATO pump
////  Port 3			NOT USED  Reactor Pump  
////  Port 4			Protien Skimmer
////  Port 5			Return Pump
////  Port 6			Wavemaker
////  Port 7                    UV Sterilizer
////  Port 8                    Fan
////  BOX 1 PORT 8              Fuge Light
#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

#define Heater Port1
#define Topoff Port2
// #define Reactor Port3
#define Skimmer Port4
#define Return Port5
#define Wave Port6
#define UVlight Port7
#define Fugelight Port8
#define Fan  Box1_Port8
#define FugelightBit   1<<7
#define UVlightBit   1<<6
#define WaveBit   1<<5
#define ReturnBit   1<<4
#define SkimmerBit   1<<3
// #define ReactorBit   1<<2
#define TopoffBit   1<<1
#define HeaterBit   1<<0

static byte wpMode;
static byte wpWavStr;
static byte wpWavOff;


////// 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 = SkimmerBit | ReturnBit | TopoffBit;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = HeaterBit | SkimmerBit | ReturnBit | TopoffBit | WaveBit;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = FugelightBit;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = HeaterBit | TopoffBit | SkimmerBit | ReturnBit | WaveBit;

  // Use T1 (SUMP) probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;
  
//ReefAngel.WaterLevel.GetLevel

  // Ports that are always on
  ReefAngel.Relay.On( Return );
  ReefAngel.Relay.On( Wave );
  ReefAngel.Relay.On( Box1_Port1 );
  ReefAngel.Relay.On( Box1_Port2 );
  ReefAngel.Relay.On( Box1_Port3 );
  ReefAngel.Relay.On( Box1_Port4 );
  ReefAngel.Relay.On( Box1_Port5 );
  ReefAngel.Relay.On( Box1_Port6 );
  ReefAngel.Relay.On( Box1_Port7 );

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


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

void loop()
{
  ReefAngel.StandardHeater( Heater );
  //ReefAngel.StandardATO( Topoff );
  ReefAngel.MoonLights( Fugelight );
  ReefAngel.StandardFan( Fan );
  
  ////// Place your custom code below here
  ReefAngel.SalMax=InternalMemory.SalMax_read();
  
// if the hour is 6a and minute is 58 and seconds is 0
// start the feeding mode
    if ( ((hour() == 6)) && 
    (minute() == 58) && 
    (second() == 0) ) {
    ReefAngel.FeedingModeStart();
}
// end feeding mode
  
/// If PH is higher than 8.4 disable the auto top off
    if (ReefAngel.Params.PH>840) ReefAngel.Relay.Off(Topoff);

    ReefAngel.Relay.DelayedOn(Skimmer,2);
    
// Custom Wave Routine 
// set the wpMode based on what time it is
    if ( (hour() >= 2) && (hour() < 5) ) wpMode=2;       // from 2am - 5am  
    if ( (hour() >= 5) && (hour() < 8) )  wpMode=1;     // from 5am - 8am
    if ( (hour() >= 8) && (hour() < 11) ) wpMode=2;      // from 8am - 11am
    if ( (hour() >= 11) && (hour() < 14) ) wpMode=3;     // from 11a - 2pm
    if ( (hour() >= 14) && (hour() < 17) ) wpMode=2;     // from 2pm - 5pm
    if ( (hour() >= 17) && (hour() < 20) ) wpMode=1;     // from 5pm - 8pm
    if ( (hour() >= 20) && (hour() < 23) ) wpMode=2;     // from 8pm - 11p
    if (hour() >= 23) wpMode=3;                          // from 11pm - midnight 
    if (hour() < 2) wpMode=3;                            // from midnight - 2am
    
    
// set the Wave Strength based on wpMode
    if (wpMode==1) wpWavStr=45;
    if (wpMode==2) wpWavStr=50;
    if (wpMode==3) wpWavStr=55;
//Set the Wave OffSet
    wpWavOff=15;  

    ReefAngel.PWM.SetDaylight( ReefCrestMode(wpWavStr,wpWavOff,true) );
    ReefAngel.PWM.SetActinic(wpWavStr);    
   
    if (ReefAngel.DisplayedMenu==FEEDING_MODE)
    {
    ReefAngel.PWM.SetActinic(30);
    ReefAngel.PWM.SetDaylight(30);
    ReefAngel.Relay.On(Fugelight);
    }
    
    
    if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE)
    {
    ReefAngel.PWM.SetActinic(0);
    ReefAngel.PWM.SetDaylight(0);
    ReefAngel.Relay.On(Fugelight);
    }
    
// end Custom Wave Routine

// DC Return Pump using internal memory
    pinMode(lowATOPin,OUTPUT);
    analogWrite(lowATOPin,InternalMemory.LEDPWMActinic_read()*2.55);
// END DC Return Pump

//  Only turn on UV Sterilizer between 11pm and 4am
    if ( (hour() >= 4) && (hour() < 23) )  // from 4a - 11p
    ReefAngel.Relay.Off(UVlight);
    else ReefAngel.Relay.On(UVlight);

 ////// Place your custom code above here
// This should always be the last line
    ReefAngel.Portal( "Smotz" );
    ReefAngel.ShowInterface();
}

void DrawCustomMain()
{

// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 5, ReefAngel.Params,
    ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 5, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
    pingSerial();

// Salinity
    ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,20,80, "SAL:" );
    ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,44,80, ReefAngel.Params.Salinity );
    pingSerial();

// Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 12, 95, TempRelay );
    pingSerial();

// Relay Expansion
    TempRelay = ReefAngel.Relay.RelayDataE[0];
    TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
    TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
    ReefAngel.LCD.DrawOutletBox( 12, 105, TempRelay );
    pingSerial();

// Date and Time
    ReefAngel.LCD.DrawDate( 6, 122 );
    pingSerial();

//draw the mode on the screen
    char buf[16];
    char buf2[16];
    char buf3[32];
    sprintf(buf,"RC %d%% +/- %d%%",wpWavStr,wpWavOff);
    sprintf(buf2,"Wave Mode = %d%",wpMode);
    sprintf(buf3,"Return Power = %d%",InternalMemory.LEDPWMActinic_read());
    ReefAngel.LCD.DrawText(0,255,10,40,buf3);
    ReefAngel.LCD.DrawText(0,255,20,60,buf);
    ReefAngel.LCD.DrawText(0,255,20,50,buf2);
    
}
void DrawCustomGraph()
{
}
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by rimai »

FugeLight (Port8), right?
Same thing. You are using MoonLights()
I think it looks good. Did you try?
Roberto.
Smotz
Posts: 401
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: ReefAngel.LightsOn(); during feeding then off when exit

Post by Smotz »

rimai wrote:FugeLight (Port8), right?
Same thing. You are using MoonLights()
I think it looks good. Did you try?
Yup - it works. Thanks for your help, as always.
Post Reply