My moonlights are too bright - need a time schedule

Do you have a question on how to do something.
Ask in here.
Post Reply
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

My moonlights are too bright - need a time schedule

Post by TanksNStuff »

My LED's come with 3 x 1w RB LED's (constant current... no dimming) that are simply too bright to be left on all night. My fish are having troubles realizing it's time for bed and I think this will be an issue long term.

Currently, my "loop" section begins like this:

Code: Select all

void loop()
{
    // Specific functions
    ReefAngel.Refresh();  //WDT check
    ReefAngel.StandardLights(Box1_Port1); //Left Blue LEDs
    ReefAngel.StandardLights(Box1_Port2); //Right Blue LEDs
    ReefAngel.MHLights(Box1_Port3); //Left White LEDs
    ReefAngel.MHLights(Box1_Port4); //Right White LEDs
 
    ReefAngel.StandardHeater(Port2);
    ReefAngel.MoonLights(Box1_Port5); //Left Moonlight
    ReefAngel.MoonLights(Box1_Port6); //Right Moonlight
    ReefAngel.MoonLights(Port4); //Fuge light on when main lights are out
    ReefAngel.Portal("tanksnstuff");
... which automatically turns the moonlights on when my other LED's are off.

So, my plan to rectify this is to just set the moonlight outlet ports to off after 2-3 hours.

What would be the simplest way to just turn off the power to (Box1_Port5) and (Box1_Port6) between the hours of midnight and 7:30 AM?

NOTE: I don't want to shut off (Port4), also labeled as a "Moonlight" port, because the Fuge light needs to run through the night.

Thanks in advance.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: My moonlights are too bright - need a time schedule

Post by TanksNStuff »

I'm thinking the solution might be something like the following... but how do I make it 7:30 instead of 7:00?

Code: Select all

    if ( hour() >= 0 && hour() < 7 )
    {
      ReefAngel.Relay.Off(Box1_Port5);
      ReefAngel.Relay.Off(Box1_Port6);
    }
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: My moonlights are too bright - need a time schedule

Post by rimai »

You are in the right path :)
You can use NumMins function, which gives number of minutes from midnight.

Code: Select all

    if ( NumMins(hour(),minute()) < 450 )
    {
      ReefAngel.Relay.Off(Box1_Port5);
      ReefAngel.Relay.Off(Box1_Port6);
    }
Roberto.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: My moonlights are too bright - need a time schedule

Post by TanksNStuff »

That would work, thanks Roberto!

Would I need to specify the (hour(),minute()) part to declare the "starting point" or just leave it just as you wrote it?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: My moonlights are too bright - need a time schedule

Post by rimai »

Use just like I wrote.
You can change the 450, which is the number of minutes for 7 hour and 30 minutes
Roberto.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: My moonlights are too bright - need a time schedule

Post by TanksNStuff »

Awesome, thanks again.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: My moonlights are too bright - need a time schedule

Post by TanksNStuff »

Roberto, sadly, this didn't work for me. I stayed up past midnight (12:30 am) and the moonlights never went off.

Could this be an issue of both the lines you gave me above and the slope code both being in the loop? Maybe the Moonlight function is overriding the Relay.Off function on every round of the loop? I'm wondering if I should just remove these two lines entirely...

Code: Select all

    ReefAngel.MoonLights(Box1_Port5); //Left Moonlight
    ReefAngel.MoonLights(Box1_Port6); //Right Moonlight
And then just change the lines you gave me to this....

Code: Select all

if ( NumMins(hour(),minute()) > 1350 ) // If time is past 22:30 (10:30 PM)
{
ReefAngel.Relay.On(Box1_Port5);
ReefAngel.Relay.On(Box1_Port6);
}
Would I also need an else... Relay.Off to go with these too, or will it just leave them on until midnight as I have it above?
My moonlights don't dim so I really only need to power those 2 outlets for a few hours.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: My moonlights are too bright - need a time schedule

Post by TanksNStuff »

Here's my current .ino file in case you need it:

Code: Select all

// Autogenerated file by RAGen (v1.2.1.158), (03/08/2012 22:54)
// RA_030812_2254.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File: 
#define DisplayImages
#define DateTimeSetup
#define DirectTempSensor
#define DisplayLEDPWM
#define wifi
#define StandardLightSetup
#define SaveRelayState
#define RelayExp
#define InstalledRelayExpansionModules 1
#define WDT
#define PWMEXPANSION
#define CUSTOM_MAIN
#define RFEXPANSION
#define FONT_8x16
#define NUMBERS_8x16
*/

#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 <RF.h>
#include <ReefAngel.h>
#include <avr/wdt.h>

//*********************************************************************************************************************************
//--------------------------------------------------- Start of Global Variables ---------------------------------------------------
// This is just how we are going to reference the PWM expansion ports within the code.
// You can change the labels if you would like, just as long as they are changed all throughout the code too.
#define LEDPWM0 0
#define LEDPWM1 1
#define LEDPWM2 2
#define LEDPWM3 3
#define LEDPWM4 4
#define LEDPWM5 5

// Initial values to all 6 PWM channels at startup. They will always be 0.
byte PWMChannel[]={
0,0,0,0,0,0};

// Globals Needed for Params on Custom Main
byte x,y;
char text[10];
int v;

// Globals Needed for RF Mode on Custom Main
byte vtechmode;
boolean bFeeding=false;
//------------------------------------------------------ End of Global Variables --------------------------------------------------
//*********************************************************************************************************************************
//---------------------------------------------Custom Main for PWM Expansion Module------------------------------------------------

void DrawCustomMain()
{
        //Top Banner
        ReefAngel.LCD.DrawText(COLOR_BLACK, COLOR_SKYBLUE, 9, 2, " George's 75G Reef "); 
        
        // Display T1 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,8,14,"Tank");
  
        // Display the T1 Temp Value
        char text[7];
        ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
        ReefAngel.LCD.Clear(255, 4, 21, 37, 37);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 4, 24, text, Num8x16);
        pingSerial();

        // Display the T2 Header Text
        ReefAngel.LCD.DrawText(COLOR_CRIMSON,255,52,14,"Canopy");
  
        // Display the T2 Temp Value
        ConvertNumToString(text, ReefAngel.Params.Temp[T2_PROBE], 10);
        ReefAngel.LCD.Clear(255, 52, 21, 75, 37);
        ReefAngel.LCD.DrawLargeText(COLOR_CRIMSON, 255, 52, 24, text, Num8x16);
        pingSerial();

        // Display pH Header Text
        ReefAngel.LCD.DrawText(COLOR_INDIGO,255,108,14,"pH");
  
        // Display pH Value
        ConvertNumToString(text, ReefAngel.Params.PH, 100);
        ReefAngel.LCD.Clear(255, 94, 21, 106, 37);
        ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 94, 24, text, Num8x16);
        pingSerial();
        
        // Display Vortech MP40wES Mode Header Text
        ReefAngel.LCD.Clear(DefaultFGColor,5,39,127,39);
        ReefAngel.LCD.DrawText(0,255,18,42,"EcoSmart Vortech");

        // Display EcoSmart Mode Value      
        ReefAngel.LCD.Clear(255, 1, 49, 128, 64);
        if (vtechmode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,35,50,"Constant");
        else if(vtechmode == 1) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,42,50,"Lagoon");
        else if (vtechmode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,25,50,"Reef Crest");
        else if (vtechmode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,22,50,"Short Pulse");
        else if (vtechmode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,25,50,"Long Pulse");
        else if (vtechmode == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,8,50,"Nutrient Trnsp.");
        else if (vtechmode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,23,50,"Tidal Swell");
        else if (vtechmode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,45,50,"Night");

        // Display PMW Expansion Channel Headers and % Values
        ReefAngel.LCD.Clear(DefaultFGColor,5,65,127,65);
        ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,31,68,"LED Dimming");
        x=15;
        y=78;
        for (int a=0;a<4;a++)
        {
          if (a>1) x=75;
          if (a==2) y=78;
          ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :");
          ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a);
          v = int(ReefAngel.PWM.GetChannelValue(a));
          // v = int(ReefAngel.PWM.GetChannelValue(a)/2.55);
          ConvertNumToString(text, v, 1);
          strcat(text,"  ");
          ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,text);
          y+=10;
        }
        pingSerial();
        
        // Display Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox(13, 97, TempRelay);
        pingSerial();
 
        // Display Expansion Relay Box 1
        TempRelay = ReefAngel.Relay.RelayDataE[0];
        TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
        TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
        ReefAngel.LCD.DrawOutletBox(13, 109, TempRelay);
        pingSerial();
        
        //Draw Date & Time
        ReefAngel.LCD.DrawDate(6, 123);
        pingSerial();
}

void DrawCustomGraph()  // Not Used
{
}
//------------------------------------------------------ End Custom Main ----------------------------------------------------------
//*********************************************************************************************************************************
//-------------------------------------------------------- Begin Setup ------------------------------------------------------------
void setup()
{
    ReefAngel.Init();  //Initialize controller

    ReefAngel.FeedingModePorts = Port1Bit;
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port6Bit | Port7Bit |Port8Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port4Bit;
    ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port4Bit;

    // Ports that are always on
    ReefAngel.Relay.On(Port1);
    ReefAngel.Relay.On(Port3);
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
    ReefAngel.Relay.On(Port7);
    ReefAngel.Relay.On(Port8);
    ReefAngel.Relay.On(Box1_Port7);
    ReefAngel.Relay.On(Box1_Port8);
//--------------------------------------------------------- RF Module Setup -------------------------------------------------------
// This section commented out because it prevented RF Module from syncing with Vortech
/*    ReefAngel.RF.SetMode(Slave_Start,0,0);
    
    If you get a compile error similar to this:
    'class ReefAngelClass' has no member named 'RF'
    Please make sure that you enabled RF Expansion on your features file.
  
    Open RAGen and make sure you have RF Expansion checked under the Features tab.

    Or, you can manually edit the file.
    The file is located at "Documents\Arduino\libraries\ReefAngel_Features.h" file and has to include this line in it:
    #define RFEXPANSION  
    
    InternalMemory.RFMode_write(0);
    InternalMemory.RFSpeed_write(128);
    InternalMemory.RFDuration_write(10);
*/    
//------------------------------------------------------ End RF Module Setup ------------------------------------------------------  
}
//---------------------------------------------------------- End Setup ------------------------------------------------------------
//*********************************************************************************************************************************
//--------------------------------------------------------- Begin Loop ------------------------------------------------------------
void loop()
{
    // Specific functions
    ReefAngel.Refresh();  //WDT check
    ReefAngel.StandardLights(Box1_Port1); //Left Blue LEDs
    ReefAngel.StandardLights(Box1_Port2); //Right Blue LEDs
    ReefAngel.MHLights(Box1_Port3); //Left White LEDs
    ReefAngel.MHLights(Box1_Port4); //Right White LEDs
 
    ReefAngel.StandardHeater(Port2);
    ReefAngel.MoonLights(Box1_Port5); //Left Moonlight
    ReefAngel.MoonLights(Box1_Port6); //Right Moonlight
    ReefAngel.MoonLights(Port4); //Fuge light on when main lights are out
    ReefAngel.Portal("tanksnstuff");
    
//------------------------------------------------ Start PWM Expansion Code for Slope ----------------------------------------------
    //  Temporarily using Memory Locations from PWM Slope Actinic (for LEDPWM0 and LEDPWM1) and 
    //  PWM Slope Daylight (for LEDPWM2 and LEDPWM3) for the start, end, durations.
    //  Will change the start%, end%, duration of each to new memory locations for each channel when Curt provides libraries update.
    PWMChannel[LEDPWM0]=PWMSlope(
      InternalMemory.StdLightsOnHour_read(),
      InternalMemory.StdLightsOnMinute_read(),
      InternalMemory.StdLightsOffHour_read(),
      InternalMemory.StdLightsOffMinute_read(),
      InternalMemory.read(852),  // start %
      InternalMemory.read(853),  // end %
      InternalMemory.read(854),  // duration
      PWMChannel[LEDPWM0]);
      
    PWMChannel[LEDPWM1]=PWMChannel[LEDPWM0];

    PWMChannel[LEDPWM2]=PWMSlope(
      InternalMemory.MHOnHour_read(),
      InternalMemory.MHOnMinute_read(),
      InternalMemory.MHOffHour_read(),
      InternalMemory.MHOffMinute_read(),
      InternalMemory.read(849),  // start %
      InternalMemory.read(850),  // end %
      InternalMemory.read(851),  // duration
      PWMChannel[LEDPWM2]);

    PWMChannel[LEDPWM3]=PWMChannel[LEDPWM2];

    // The lines above are what calculates the slope.
    // You can change the schedule by changing the parameter inside the parenthesis of the PWMSlope() function
    // The are as follow:
    // 1st parameter: hour to start slope
    // 2nd parameter: minute to start slope
    // 3rd parameter: hour to end slope
    // 4th parameter: minute to end slope
    // 5th parameter: % of the PWM signal to start slope
    // 6th parameter: % of the PWM signal to end slope
    // 7th parameter: duration of slope in minutes
    // 8th parameter: always the same as the variable before the PWMSlope() call

    //PWMChannel[LEDPWM1]=PWMSlope(15,0,21,30,15,45,90,PWMChannel[LEDPWM1]);

    // In the example above, we are starting the slope at 3:00pm with 15% and going up to 45% within 90 minutes, which would be 4:30pm.
    // Then it would stay at 45% from 4:30 to 90 minutes prior to 9:30pm, which would be 8:00pm.
    // Then from 8:00pm, it would start sloping down from 45% all the way back to 15% within 90 minutes, which would be 9:30pm.
    //CheckCloud(); (May be used at a later date with cloud/storm effects)
    ReefAngel.PWM.Expansion(LEDPWM0,int(PWMChannel[LEDPWM0]));
    ReefAngel.PWM.Expansion(LEDPWM1,int(PWMChannel[LEDPWM1]));
    ReefAngel.PWM.Expansion(LEDPWM2,int(PWMChannel[LEDPWM2]));
    ReefAngel.PWM.Expansion(LEDPWM3,int(PWMChannel[LEDPWM3]));
    ReefAngel.ShowInterface();

//------------------------------------------------- End PWM Expansion Code for Slope ----------------------------------------------

//------------------------------------------------ Start Time-of-Day Based Functions ----------------------------------------------
//-------------------------------------------------------- Moonlight Schedule -----------------------------------------------------
    if ( NumMins(hour(),minute()) < 450 )  // Turn off Moonlights from Midnight to 7:30 MAM
    {
      ReefAngel.Relay.Off(Box1_Port5);
      ReefAngel.Relay.Off(Box1_Port6);
    }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These are the mode numbers for the RF Expansion Module for reference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //#define Constant      0
    //#define Random1       1 // Lagoonal
    //#define Random2       2 // Reef Crest
    //#define ShortWave     3
    //#define LongWave      4
    //#define Smart_NTM     5 // Nutrient Transport Mode
    //#define Smart_TSM     6 // Tidal Swell Mode
    //#define Feeding_Start 7
    //#define Feeding_Stop  8
    //#define Night         9
    //#define Slave_Start   97
    //#define Slave_Stop    98
    //#define None          99
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//------------------------------ Start Feeding Mode Schedule (Start 1st Feeding at 9:55 AM and 2nd at 1:55 PM)---------------------
    // if the hour is 9a or 1p, minute is 55 and seconds is 0
    // start the feeding mode
    if ( ((hour() == 9) || (hour() == 13)) && 
       (minute() == 55) && 
       (second() == 0) ) 
    {
      ReefAngel.FeedingModeStart();
      vtechmode = InternalMemory.RFMode_read();     
    }
//------------------------------------------------------ End of Feeding Mode Schedule ---------------------------------------------

//-------------------------------------------------------- Start RF Daytime Control -----------------------------------------------
  if (hour() >=8 && hour() <= 22)
  {  
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding )
    {
      bFeeding=false; 
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,155,5);
      ReefAngel.Timer[4].SetInterval(1800); // Timer for 30min
      ReefAngel.Timer[4].Start();
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[4].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }  
  }
//---------------------------------------------------------- End RF Daytime Control -----------------------------------------------   

//-------------------------------------------------------- Start RF Nightmode Control ---------------------------------------------    

  if (hour()>=23 || hour()<7) // Defining "Nightmode" hours for VorTech = between 11 PM and 7 AM
    {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
    }
  else
    {
      ReefAngel.RF.SetMode(Feeding_Stop,0,0); //Temp fix for coming out of Night mode
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    } 
//---------------------------------------------------------- End RF Nightmode Control ---------------------------------------------
//------------------------------------------------------ End Time-of-Day Based Functions ------------------------------------------
}
//--------------------------------------------------------------- End Loop --------------------------------------------------------
//*********************************************************************************************************************************

// ToDo List Functions that still need to be added above:
// 1. Add Sunrise/Sunset/MoonPhase/Cloud Chance, etc. (PWM Slope data may be altered by these?)
// 2. *Option for later date* Relay box Ports 7 and 8 changed to "Off" normally, then add line in Loop to power them on if Overheat 
//    Shutoff is active (when I get fans to plug into those ports.)   
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: My moonlights are too bright - need a time schedule

Post by rimai »

ShowInterface() has to be the last thing.
Anything after that won't take effect and that's why it didn't work.
Roberto.
TanksNStuff
Posts: 188
Joined: Fri Dec 30, 2011 6:57 am

Re: My moonlights are too bright - need a time schedule

Post by TanksNStuff »

Oh, I didn't know that had to be last.

*EDIT* I just moved the show interface to last line in the loop and now this is working perfectly (shuts off moonlights at midnight). I changed the time to 11:59 PM, waited a minute, and the ML's went off. ;)

Now my next major task is to find out why my actinic and daylight LED's are pulsing. I'll start another thread for that though.
Post Reply