Page 1 of 1

New Code - Some Troubles and Questions

Posted: Fri Feb 01, 2013 2:32 pm
by mvwise
I've been working on a new PDE for my son's tank and I've run into some issues that I'm looking for help on.

I have set up a custom menu to include two menu items that increment the RF Mode and Speed on the Vortech pumps each time they are selected. The Mode increases by 1 and cycles around to the beginning and actually sets the internal memory so that it will revert back to this mode after my feeding mode code is enabled. I would like to have the speed setting increase by 10% each time it is selected, but can't quite seem to figure out the logic in the code. Same idea as the mode menu item, just increase speed by factors of 10 each time. Is the value stored in the memory location an actual percentage or is it based on 0-255?

Before anyone asks - yes I could change this with the iphone app or through the portal if only he had the wifi module, but he doesn't. So this is a temporary workaround until he can afford to purchase the wife module and the expansion hub...

The final issue we were having was in the Custom Main. I have chosen to display the 8x16 font for the temperature and PH values, but it is not being detected during the compile. I have used the exact same code from my own PDE and it is automatically detached, but I can't seem to get it to work on this file.

Here is our current PDE:

Code: Select all

//
// This version updated for v1.0.3 or later

/* 
Ports assignment:
Port1 - Return Pump
Port2 - Skimmer
Port3 - Heater 1 & 2
Port4 - Avast ATO 
Port5 - Tank Lights (White)
Port6 - Tank Lights (Blue)
Port7 - Moonlights
Port8 - 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>

//*********************************************************************************************************************************
//--------------------------------------------------- Start of Global Variables ---------------------------------------------------

// Globals Needed for RF Mode on Custom Menu
byte vtmode=InternalMemory.RFMode_read();
byte vtspeed=InternalMemory.RFSpeed_read();

// 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;
byte vtechspeed;
boolean bFeeding=false;

//------------------------------------------------------ End of Global Variables --------------------------------------------------
//*********************************************************************************************************************************
//----------------------------------------------------------- Custom Menu ---------------------------------------------------------

#include <avr/pgmspace.h>
prog_char menu0_label[] PROGMEM = "Feeding";
prog_char menu1_label[] PROGMEM = "Water Change";
prog_char menu2_label[] PROGMEM = "Vortech Mode";
prog_char menu3_label[] PROGMEM = "Vortech Speed";
prog_char menu4_label[] PROGMEM = "Lights On";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Overheat Clear";
prog_char menu7_label[] PROGMEM = "Date / Time";
prog_char menu8_label[] PROGMEM = "Version";
PROGMEM const char *menu_items[] = {
menu0_label, menu1_label, menu2_label,
menu3_label, menu4_label, menu5_label,
menu6_label, menu7_label, menu8_label
};

void MenuEntry1()
{
     ReefAngel.FeedingModeStart();
}
void MenuEntry2()
{
     ReefAngel.WaterChangeModeStart();
}
void MenuEntry3()
{
     vtmode++;
     if (vtmode>6) vtmode=1;
     InternalMemory.RFMode_write(vtmode); // Set the Internal Memory Setting for RF Mode
     ReefAngel.RF.SetMode(InternalMemory.RFMode_read(), InternalMemory.RFSpeed_read(), InternalMemory.RFDuration_read());
     ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
}
void MenuEntry4()
{
     vtspeed++;
     if (vtspeed>100) vtmode=10;
     InternalMemory.RFSpeed_write(vtspeed); // Set the Internal Memory Setting for RF Speed
     ReefAngel.RF.SetMode(InternalMemory.RFMode_read(), InternalMemory.RFSpeed_read(), InternalMemory.RFDuration_read());
     ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
}
void MenuEntry5()
{
     ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
     ReefAngel.Relay.Write();
}
void MenuEntry6()
{
     ReefAngel.OverheatClear();
     ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry7()
{
     ReefAngel.SetupCalibratePH();
     ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry8()
{
     ReefAngel.SetupDateTime();
     ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry9()
{
     ReefAngel.DisplayVersion();
}

//--------------------------------------------------------- End Custom Menu -------------------------------------------------------
//*********************************************************************************************************************************
//----------------------------------------------------------- Custom Main ---------------------------------------------------------

void DrawCustomMain()
{
        //Top Banner
        ReefAngel.LCD.DrawLargeText(COLOR_BLACK, 255, 25, 2, "JAW'S REEF"); 
        ReefAngel.LCD.Clear(DefaultFGColor,3,11,126,11);
        
        // Display T1 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,10,13,"Tank");
        char text[7];
  
        // Display the T1 Temp Value
        ReefAngel.LCD.Clear(255,4,22,125,37);
        ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 4, 22, text, Font8x16);
  
        // Display T2 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,55,13,"Sump");

        // Display the T2 Temp Value
        ConvertNumToString(text, ReefAngel.Params.Temp[T2_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 49, 22, text, Font8x16);
 
        // Display pH Header Text
        ReefAngel.LCD.DrawText(COLOR_INDIGO,255,105,13,"pH");
  
        // Display pH Value
        ConvertNumToString(text, ReefAngel.Params.PH, 100);
        ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 94, 22, text, Font8x16);

        // Display EcoSmart Mode Value & Speed %     
        ReefAngel.LCD.Clear(DefaultFGColor,3,39,126,39);
        ReefAngel.LCD.Clear(255,1,41,128,48);
        vtechspeed = InternalMemory.RFSpeed_read();
        ConvertNumToString(text, vtechspeed, 1);
        if (vtechmode == 0)
        {
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,16,41,"Constant-");
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,89,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,106,41,"%");
        }
        else if(vtechmode == 1) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,20,41,"Lagoon-");
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,85,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,102,41,"%");
         }
        else if (vtechmode == 2) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,8,41,"Reef Crest-");
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,97,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,114,41,"%");
        }
        else if (vtechmode == 3) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,4,41,"Short Pulse-");
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,101,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,118,41,"%");
        }
        else if (vtechmode == 4) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,8,41,"Long Pulse-");
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,97,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,114,41,"%");
        }
        else if (vtechmode == 5) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,41,"Nutrient TM-");
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,41,"%");
         }
        else if (vtechmode == 6) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,41,"Tidal Swell-");
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,41,"%");
        }
        else if (vtechmode == 9) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,28,41,"Night-");
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,77,41,text);
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,94,41,"%");
        }

        // Draw Graph
        //ReefAngel.LCD.DrawGraph(4,53);

        // Display Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox(13, 105, TempRelay);

        //Draw Date & Time
        ReefAngel.LCD.Clear(DefaultFGColor,3,118,126,118);
        ReefAngel.LCD.DrawDate(6, 120);
}

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

    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port4Bit; // Turn off Return pump, Skimmer & ATO when feeding mode is activated
    ReefAngel.WaterChangePorts = Port2Bit | Port4Bit; // Turn off Skimmer & ATO when water change mode is actived
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.LightsOnPorts = Port5Bit | Port6Bit | Port8Bit;
    ReefAngel.TempProbe = T1_PROBE; // Use T1 probe as temperature and overheat functions
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 850 ); // Set the Overheat temperature setting
        
    // Ports that are always on
    ReefAngel.Relay.On(Port1);
         
    vtechmode = InternalMemory.RFMode_read();
    
}
//---------------------------------------------------------- End Setup ------------------------------------------------------------
//*********************************************************************************************************************************
//--------------------------------------------------------- Begin Loop ------------------------------------------------------------
void loop()
{
    // Specific functions
    ReefAngel.Relay.DelayedOn(Port2, 1); // Turn on Port 4 (Skimmer) with 1 minute delay
    ReefAngel.Relay.DelayedOn(Port4, 2); // Turn on Port 5 (Avast ATO) with 2 minute delay
    ReefAngel.StandardLights( Port5,10,0,20,0 ); // White and Blue LED's on During Standard Hours
    ReefAngel.StandardLights( Port6,9,0,21,0 ); // White and Blue LED's on During Standard Hours
    ReefAngel.StandardLights( Port7,21,0,9,0 ); //Fuge Light and Moonlights on at night
    ReefAngel.StandardLights( Port8,21,0,9,0 ); //Fuge Light and Moonlights on at night
    ReefAngel.StandardHeater(Port3,765,785); // Standard Heater Using Internal Memory
    
/*
------------------------------------------------ Start Time-of-Day Based Functions ----------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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
    
    RF Mode      = http://YOURIPADDRESS:2000/mb855,X
    RF Speed     = http://YOURIPADDRESS:2000/mb856,X
    RF Duration  = http://YOURIPADDRESS:2000/mb857,X
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

//-------------------------------------------------------- Start RF Smart Nutrient Mode After Feeding ---------------------------
  if ((hour() >=8 && minute() >=30) || (hour() <= 20 && minute() <30))
  {  
    if (vtechmode == 9)
    {
      ReefAngel.RF.UseMemory=true;  
      vtechmode = InternalMemory.RFMode_read();
    }
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding)
    {
      bFeeding=false; 
      ReefAngel.Timer[1].SetInterval(600); // Timer for 10min
      ReefAngel.Timer[1].Start();
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,200,6);
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[1].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }
  }
  else
  {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
  }
  
//---------------------------------------------------------- End RF Smart Nutrient Mode After Feeding -----------------------------   

    ReefAngel.ShowInterface();
}
//--------------------------------------------------------------- End Loop --------------------------------------------------------

//*********************************************************************************************************************************

Any help would be appreciated!

Re: New Code - Some Troubles and Questions

Posted: Fri Feb 01, 2013 2:49 pm
by Piper
Assuming it's based on 100 and not 255 (someone with more info will have to chime in here) you can use this:

Code: Select all

    void MenuEntry4()
    {
         vtspeed += 10;
         if (vtspeed>100) vtspeed=10;  // <== note that you had vtmode here; change to vtspeed
         InternalMemory.RFSpeed_write(vtspeed); // Set the Internal Memory Setting for RF Speed
         ReefAngel.RF.SetMode(InternalMemory.RFMode_read(), InternalMemory.RFSpeed_read(), InternalMemory.RFDuration_read());
         ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
    }
And for the font, put this just under your includes:

Code: Select all

#define NUMBERS_8x16

Re: New Code - Some Troubles and Questions

Posted: Fri Feb 01, 2013 4:26 pm
by binder
There isn't really a straight forward answer for you.

These 2 lines should be modified and moved.

Code: Select all

// Globals Needed for RF Mode on Custom Menu
byte vtmode=InternalMemory.RFMode_read();
byte vtspeed=InternalMemory.RFSpeed_read();
To ensure things are initialized properly, you should define the variables and then initialize them in the setup() just after the ReefAngel class is initialize. It shouldn't hurt anything but it can make sure all the other stuff is initialized properly.
So, have it be like this:

Code: Select all

byte vtmode;
byte vtspeed;

// other code here

void setup()
{
ReefAngel.Init();
vtmode=InternalMemory.RFMode_read();
vtspeed=InternalMemory.RFSpeed_read();
}
Like I said, the other way should work fine but just in case.

Now for your question about the speed. The value that is stored is the percentage of the pump speed. So the value stored is from 0-100. To increase by 10%, you would just need to add on 10. The code the piper provided is "almost" correct. When you exceed 100, he sets it back to 10% and not 0. It should be changed to this:

Code: Select all

    void MenuEntry4()
    {
         vtspeed += 10;
         if (vtspeed>100) vtspeed=0;  // <== note that you had vtmode here; change to vtspeed
         InternalMemory.RFSpeed_write(vtspeed); // Set the Internal Memory Setting for RF Speed
         ReefAngel.RF.SetMode(InternalMemory.RFMode_read(), vtspeed, InternalMemory.RFDuration_read());
         ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
    }
Then I also changed the InternalMemory.RFSpeed_read() to just be the vtspeed. It doesn't matter if you use the function or not, but why add in extra overhead of a function call if you already have the value in the variable.

I noticed that the RF Mode only cycles from modes 1 - 6. This means that it never gets to the constant mode (mode 0). If you want to cycle through the constant mode to, I would update your code to be this:

Code: Select all

void MenuEntry3()
{
     vtmode++;
     if (vtmode>6) vtmode=0;
     InternalMemory.RFMode_write(vtmode); // Set the Internal Memory Setting for RF Mode
     ReefAngel.RF.SetMode(vtmode, InternalMemory.RFSpeed_read(), InternalMemory.RFDuration_read());
     ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
}
Again, I just used the vtmode variable instead of the function when setting the mode for the same reason I previously mentioned.

The last thing I would do is to change the ReefAngel.ShowInterface() and put it as the first line inside the loop() instead of the last line. It may help with some relay toggling and interface displaying. You don't have to change it, just making a suggestion because now all the INO (PDE) files generated are that way.

New Code - Some Troubles and Questions

Posted: Fri Feb 01, 2013 6:19 pm
by mvwise
Awesome, thanks guys for the help. We'll make hose changes and try it all out.


Sent from my iPad using Tapatalk HD

New Code - Some Troubles and Questions

Posted: Fri Feb 01, 2013 6:38 pm
by lnevo
Really, so ShowInterface at the beginning now?

Re: New Code - Some Troubles and Questions

Posted: Fri Feb 01, 2013 6:43 pm
by rimai
No....
At the end is best :)

Re: New Code - Some Troubles and Questions

Posted: Sat Feb 02, 2013 12:46 pm
by mvwise
Okay I made the changes, but when the code begins to run I start with a blank screen. I can get my custom display running by clicking the joystick, but something is amiss there.

Also, when I click the joystock to go into the custom menu it only displays:

Main:

Exit

Clicking the joystick again takes me to feeding mode. So I think there is something missing or messed up with my custom menu code.

Here is my revised PDE:

Code: Select all

//
// This version updated for v1.0.3 or later

/* 
The following features are enabled for this File: 
#define DisplayImages
#define OverheatSetup
#define DateTimeSetup
#define VersionMenu
#define DirectTempSensor
#define DisplayLEDPWM
#define SaveRelayState
#define WDT
#define CUSTOM_MAIN
#define COLORS_PDE
#define RFEXPANSION
#define FONT_8x8
#define FONT_8x16

Ports assignment:
Port1 - Return Pump
Port2 - Skimmer
Port3 - Heater 1 & 2
Port4 - Avast ATO 
Port5 - Tank Lights (White)
Port6 - Tank Lights (Blue)
Port7 - Moonlights
Port8 - 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>

//*********************************************************************************************************************************
//--------------------------------------------------- Start of Global Variables ---------------------------------------------------

// Globals Needed for RF Mode on Custom Menu
byte vtmode;
byte vtspeed;

// 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;
byte vtechspeed;
boolean bFeeding=false;

//------------------------------------------------------ End of Global Variables --------------------------------------------------
//*********************************************************************************************************************************
//----------------------------------------------------------- Custom Menu ---------------------------------------------------------

#include <avr/pgmspace.h>
prog_char menu0_label[] PROGMEM = "Feeding";
prog_char menu1_label[] PROGMEM = "Water Change";
prog_char menu2_label[] PROGMEM = "Vortech Mode";
prog_char menu3_label[] PROGMEM = "Vortech Speed";
prog_char menu4_label[] PROGMEM = "Lights On";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Overheat Clear";
prog_char menu7_label[] PROGMEM = "Date / Time";
prog_char menu8_label[] PROGMEM = "Version";
PROGMEM const char *menu_items[] = {
menu0_label, menu1_label, menu2_label,
menu3_label, menu4_label, menu5_label,
menu6_label, menu7_label, menu8_label
};

void MenuEntry1()
{
     ReefAngel.FeedingModeStart();
}
void MenuEntry2()
{
     ReefAngel.WaterChangeModeStart();
}
void MenuEntry3()
{
     vtmode++;
     if (vtmode>6) vtmode=0;
     InternalMemory.RFMode_write(vtmode); // Set the Internal Memory Setting for RF Mode
     ReefAngel.RF.SetMode(vtmode, InternalMemory.RFSpeed_read(), InternalMemory.RFDuration_read());
     ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
}
void MenuEntry4()
{
     vtspeed+=10;
     if (vtspeed>100) vtspeed=0;
     InternalMemory.RFSpeed_write(vtspeed); // Set the Internal Memory Setting for RF Speed
     ReefAngel.RF.SetMode(InternalMemory.RFMode_read(), vtspeed, InternalMemory.RFDuration_read());
     ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
}
void MenuEntry5()
{
     ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
     ReefAngel.Relay.Write();
}
void MenuEntry6()
{
     ReefAngel.OverheatClear();
     ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry7()
{
     ReefAngel.SetupCalibratePH();
     ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry8()
{
     ReefAngel.SetupDateTime();
     ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry9()
{
     ReefAngel.DisplayVersion();
}

//--------------------------------------------------------- End Custom Menu -------------------------------------------------------
//*********************************************************************************************************************************
//----------------------------------------------------------- Custom Main ---------------------------------------------------------

void DrawCustomMain()
{
        //Top Banner
        ReefAngel.LCD.DrawLargeText(COLOR_BLACK, 255, 25, 4, "JAW'S REEF", Font8x16); 
        ReefAngel.LCD.Clear(DefaultFGColor,3,23,126,23);
        
        // Display T1 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,10,27,"Tank");
        char text[7];
  
        // Display the T1 Temp Value
        ReefAngel.LCD.Clear(255,4,37,125,52);
        ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 4, 37, text, Font8x16);
  
        // Display T2 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,55,27,"Sump");

        // Display the T2 Temp Value
        ConvertNumToString(text, ReefAngel.Params.Temp[T2_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 49, 37, text, Font8x16);
 
        // Display pH Header Text
        ReefAngel.LCD.DrawText(COLOR_INDIGO,255,105,27,"pH");
  
        // Display pH Value
        ConvertNumToString(text, ReefAngel.Params.PH, 100);
        ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 94, 37, text, Font8x16);

        // Display EcoSmart Mode Value & Speed %     
        ReefAngel.LCD.Clear(DefaultFGColor,3,56,126,56);
        ReefAngel.LCD.Clear(255,1,60,128,75);
        vtechspeed = InternalMemory.RFSpeed_read();
        ConvertNumToString(text, vtechspeed, 1);
        if (vtechmode == 0)
        {
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,16,60,"Constant-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,89,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,106,60,"%", Font8x16);
        }
        else if(vtechmode == 1) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,20,60,"Lagoon-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,85,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,102,60,"%", Font8x16);
         }
        else if (vtechmode == 2) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,8,60,"Reef Crest-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,97,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,114,60,"%", Font8x16);
        }
        else if (vtechmode == 3) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,4,60,"Short Pulse-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,101,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,118,60,"%", Font8x16);
        }
        else if (vtechmode == 4) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,8,60,"Long Pulse-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,97,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,114,60,"%", Font8x16);
        }
        else if (vtechmode == 5) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,60,"Nutrient TM-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,60,"%", Font8x16);
         }
        else if (vtechmode == 6) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,60,"Tidal Swell-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,60,"%", Font8x16);
        }
        else if (vtechmode == 9) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,28,60,"Night-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,77,60,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,94,60,"%", Font8x16);
        }

        // Display Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox(13, 99, TempRelay);

        //Draw Date & Time
        ReefAngel.LCD.Clear(DefaultFGColor,3,114,126,114);
        ReefAngel.LCD.DrawDate(6, 118);
}

void DrawCustomGraph()  // Not Used
{
}
//------------------------------------------------------ End Custom Main ----------------------------------------------------------
//*********************************************************************************************************************************
//-------------------------------------------------------- Begin Setup ------------------------------------------------------------
void setup()
{
    ReefAngel.Init();  //Initialize controller
    vtmode=InternalMemory.RFMode_read();
    vtspeed=InternalMemory.RFSpeed_read();
    
    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port4Bit; // Turn off Return pump, Skimmer & ATO when feeding mode is activated
    ReefAngel.WaterChangePorts = Port2Bit | Port4Bit; // Turn off Skimmer & ATO when water change mode is actived
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.LightsOnPorts = Port5Bit | Port6Bit | Port8Bit;
    ReefAngel.TempProbe = T1_PROBE; // Use T1 probe as temperature and overheat functions
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 850 ); // Set the Overheat temperature setting
        
    // Ports that are always on
    ReefAngel.Relay.On(Port1);
         
    vtechmode = InternalMemory.RFMode_read();
    
}
//---------------------------------------------------------- End Setup ------------------------------------------------------------
//*********************************************************************************************************************************
//--------------------------------------------------------- Begin Loop ------------------------------------------------------------
void loop()
{
    // Specific functions
    ReefAngel.Relay.DelayedOn(Port2, 1); // Turn on Port 4 (Skimmer) with 1 minute delay
    ReefAngel.Relay.DelayedOn(Port4, 2); // Turn on Port 5 (Avast ATO) with 2 minute delay
    ReefAngel.StandardLights( Port5,10,30,19,30 ); // White LED's on During Standard Hours
    ReefAngel.StandardLights( Port6,9,0,21,0 ); // Blue LED's on During Standard Hours
    ReefAngel.StandardLights( Port7,21,0,9,0 ); //Fuge Light and Moonlights on at night
    ReefAngel.StandardLights( Port8,21,0,9,0 ); //Fuge Light and Moonlights on at night
    ReefAngel.StandardHeater(Port3,770,790); // Standard Heater Using Internal Memory
    
/*
------------------------------------------------ Start Time-of-Day Based Functions ----------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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
    
    RF Mode      = http://YOURIPADDRESS:2000/mb855,X
    RF Speed     = http://YOURIPADDRESS:2000/mb856,X
    RF Duration  = http://YOURIPADDRESS:2000/mb857,X
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

//-------------------------------------------------------- Start RF Smart Nutrient Mode After Feeding ---------------------------
  if ((hour() >=9 && minute() >=00) || (hour() <= 21 && minute() <00))
  {  
    if (vtechmode == 9)
    {
      ReefAngel.RF.UseMemory=true;  
      vtechmode = InternalMemory.RFMode_read();
    }
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding)
    {
      bFeeding=false; 
      ReefAngel.Timer[1].SetInterval(600); // Timer for 10min
      ReefAngel.Timer[1].Start();
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(5,100,6);
      vtechmode = 5;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[1].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
    }
  }
  else
  {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(9,15,0);
      vtechmode = 9;
  }
  
//---------------------------------------------------------- End RF Smart Nutrient Mode After Feeding -----------------------------   

    ReefAngel.ShowInterface();
}
//--------------------------------------------------------------- End Loop --------------------------------------------------------

//*********************************************************************************************************************************

Re: New Code - Some Troubles and Questions

Posted: Sat Feb 02, 2013 12:53 pm
by rimai
You need to initialize the menu system.
Add this after ReefAngel.Init();

Code: Select all

  ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));

Re: New Code - Some Troubles and Questions

Posted: Sat Feb 02, 2013 1:07 pm
by mvwise
Great, thanks that did it!

Re: New Code - Some Troubles and Questions

Posted: Sat Feb 02, 2013 2:26 pm
by binder
rimai wrote:No....
At the end is best :)
oops. my bad. i wasn't paying close attention. guess that's what i get for not creating a few ino files lately and not looking it up.

Re: New Code - Some Troubles and Questions

Posted: Sat Feb 02, 2013 3:24 pm
by mvwise
I've made a couple of changes as I was having some issues displaying the speed settings. I figure some of the variables are redundant and I can get rid of them eventually, but first I want to make sure it runs smoothly.

My issue right now is that it doesnt' seem to go into night mode once the time hits 9pm. I realize it's not 9pm yet, but I changed the time on the RA to see what would happen and the standard light ports switched off as desired, but the Vortech didn't switch into night mode. Feeding mode seems to work with no troubles.

Here is my updated code:

Code: Select all

//
// This version updated for v1.0.3 or later

/* 
The following features are enabled for this File: 
#define DisplayImages
#define OverheatSetup
#define DateTimeSetup
#define VersionMenu
#define DirectTempSensor
#define DisplayLEDPWM
#define SaveRelayState
#define WDT
#define CUSTOM_MAIN
#define COLORS_PDE
#define RFEXPANSION
#define FONT_8x8
#define FONT_8x16

Ports assignment:
Port1 - Return Pump
Port2 - Skimmer
Port3 - Heater 1 & 2
Port4 - Avast ATO 
Port5 - Tank Lights (White)
Port6 - Tank Lights (Blue)
Port7 - Moonlights
Port8 - 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>

//*********************************************************************************************************************************
//--------------------------------------------------- Start of Global Variables ---------------------------------------------------

// Globals Needed for RF Mode on Custom Menu
byte vtmode;
byte vtspeed;

// 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;
byte vtechspeed;
boolean bFeeding=false;

//------------------------------------------------------ End of Global Variables --------------------------------------------------
//*********************************************************************************************************************************
//----------------------------------------------------------- Custom Menu ---------------------------------------------------------

#include <avr/pgmspace.h>
prog_char menu0_label[] PROGMEM = "Feeding";
prog_char menu1_label[] PROGMEM = "Water Change";
prog_char menu2_label[] PROGMEM = "Vortech Mode";
prog_char menu3_label[] PROGMEM = "Vortech Speed";
prog_char menu4_label[] PROGMEM = "Lights On";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Overheat Clear";
prog_char menu7_label[] PROGMEM = "Date / Time";
prog_char menu8_label[] PROGMEM = "Version";
PROGMEM const char *menu_items[] = {
menu0_label, menu1_label, menu2_label,
menu3_label, menu4_label, menu5_label,
menu6_label, menu7_label, menu8_label
};

void MenuEntry1()
{
     ReefAngel.FeedingModeStart();
}
void MenuEntry2()
{
     ReefAngel.WaterChangeModeStart();
}
void MenuEntry3()
{
     vtmode++;
     vtechmode++;
     if (vtmode>6)
     {
       vtmode=0;
       vtechmode=0;
     }
     InternalMemory.RFMode_write(vtmode); // Set the Internal Memory Setting for RF Mode
     ReefAngel.RF.SetMode(vtmode, InternalMemory.RFSpeed_read(), InternalMemory.RFDuration_read());
     ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
}
void MenuEntry4()
{
     vtspeed+=10;
     vtechspeed+=10;
     if (vtspeed>100)
     {
       vtspeed=0;
       vtechspeed=0;
     }
     InternalMemory.RFSpeed_write(vtspeed); // Set the Internal Memory Setting for RF Speed
     ReefAngel.RF.SetMode(InternalMemory.RFMode_read(), vtspeed, InternalMemory.RFDuration_read());
     ReefAngel.DisplayedMenu = RETURN_MAIN_MODE;   
}
void MenuEntry5()
{
     ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
     ReefAngel.Relay.Write();
}
void MenuEntry6()
{
     ReefAngel.OverheatClear();
     ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry7()
{
     ReefAngel.SetupCalibratePH();
     ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry8()
{
     ReefAngel.SetupDateTime();
     ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}
void MenuEntry9()
{
     ReefAngel.DisplayVersion();
}

//--------------------------------------------------------- End Custom Menu -------------------------------------------------------
//*********************************************************************************************************************************
//----------------------------------------------------------- Custom Main ---------------------------------------------------------

void DrawCustomMain()
{
        //Top Banner
        ReefAngel.LCD.DrawLargeText(COLOR_BLACK, 255, 25, 4, "JAW'S REEF", Font8x16); 
        ReefAngel.LCD.Clear(DefaultFGColor,3,23,126,23);
        
        // Display T1 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,10,27,"Tank");
        char text[7];
  
        // Display the T1 Temp Value
        ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 4, 37, text, Font8x16);
  
        // Display T2 Header Text
        ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,55,27,"Sump");

        // Display the T2 Temp Value
        ConvertNumToString(text, ReefAngel.Params.Temp[T2_PROBE], 10);
        ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE, 255, 49, 37, text, Font8x16);
 
        // Display pH Header Text
        ReefAngel.LCD.DrawText(COLOR_INDIGO,255,105,27,"pH");
  
        // Display pH Value
        ConvertNumToString(text, ReefAngel.Params.PH, 100);
        ReefAngel.LCD.DrawLargeText(COLOR_INDIGO, 255, 94, 37, text, Font8x16);

        // Display EcoSmart Mode Value & Speed %     
        ReefAngel.LCD.Clear(DefaultFGColor,3,56,126,56);
        ReefAngel.LCD.DrawLargeText(COLOR_BLACK, 255, 17, 62, "Ecotech Mode");
        //vtechmode = InternalMemory.RFMode_read();
        //vtechspeed = InternalMemory.RFSpeed_read();
        ConvertNumToString(text, vtechspeed, 1);
        if (vtechmode == 0)
        {
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,16,74,"Constant-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,89,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,106,74,"%", Font8x16);
        }
        else if(vtechmode == 1) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,20,74,"Lagoon-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,85,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,102,74,"%", Font8x16);
        }
        else if (vtechmode == 2) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,8,74,"Reef Crest-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,97,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,114,74,"%", Font8x16);
        }
        else if (vtechmode == 3) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,4,74,"Short Pulse-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,101,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,118,74,"%", Font8x16);
        }
        else if (vtechmode == 4) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,8,74,"Long Pulse-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,97,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,114,74,"%", Font8x16);
        }
        else if (vtechmode == 5) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,74,"Nutrient TM-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,74,"%", Font8x16);
         }
        else if (vtechmode == 6) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,4,74,"Tidal Swell-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,101,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,118,74,"%", Font8x16);
        }
        else if (vtechmode == 9) 
        {
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,28,74,"Night-", Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,77,74,text, Font8x16);
          ReefAngel.LCD.DrawLargeText(COLOR_WHITE,0,94,74,"%", Font8x16);
        }

        // Display Main Relay Box
        ReefAngel.LCD.Clear(DefaultFGColor,3,95,126,95);
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox(13, 99, TempRelay);

        //Draw Date & Time
        ReefAngel.LCD.Clear(DefaultFGColor,3,114,126,114);
        ReefAngel.LCD.DrawDate(6, 118);
}

void DrawCustomGraph()  // Not Used
{
}
//------------------------------------------------------ End Custom Main ----------------------------------------------------------
//*********************************************************************************************************************************
//-------------------------------------------------------- Begin Setup ------------------------------------------------------------
void setup()
{
    ReefAngel.Init();  //Initialize controller
    ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));  //Intialize Custom Menu
    
    vtmode=InternalMemory.RFMode_read();
    vtspeed=InternalMemory.RFSpeed_read();
    vtechmode=InternalMemory.RFMode_read();
    vtechspeed=InternalMemory.RFSpeed_read();
     
    ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port4Bit; // Turn off Return pump, Skimmer & ATO when feeding mode is activated
    ReefAngel.WaterChangePorts = Port2Bit | Port4Bit; // Turn off Skimmer & ATO when water change mode is actived
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.LightsOnPorts = Port5Bit | Port6Bit | Port8Bit;
    ReefAngel.TempProbe = T1_PROBE; // Use T1 probe as temperature and overheat functions
    ReefAngel.OverheatProbe = T1_PROBE;
    InternalMemory.OverheatTemp_write( 850 ); // Set the Overheat temperature setting
        
    // Ports that are always on
    ReefAngel.Relay.On(Port1);
         
}
//---------------------------------------------------------- End Setup ------------------------------------------------------------
//*********************************************************************************************************************************
//--------------------------------------------------------- Begin Loop ------------------------------------------------------------
void loop()
{
    // Specific functions
    ReefAngel.Relay.DelayedOn(Port2, 1); // Turn on Port 4 (Skimmer) with 1 minute delay
    ReefAngel.Relay.DelayedOn(Port4, 2); // Turn on Port 5 (Avast ATO) with 2 minute delay
    ReefAngel.StandardLights( Port5,10,30,19,30 ); // White LED's on During Standard Hours
    ReefAngel.StandardLights( Port6,9,0,21,0 ); // Blue LED's on During Standard Hours
    ReefAngel.StandardLights( Port7,21,0,9,0 ); //Fuge Light and Moonlights on at night
    ReefAngel.StandardLights( Port8,21,0,9,0 ); //Fuge Light and Moonlights on at night
    ReefAngel.StandardHeater(Port3,770,790); // Standard Heater Using Internal Memory
    
/*
------------------------------------------------ Start Time-of-Day Based Functions ----------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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
    
    RF Mode      = http://YOURIPADDRESS:2000/mb855,X
    RF Speed     = http://YOURIPADDRESS:2000/mb856,X
    RF Duration  = http://YOURIPADDRESS:2000/mb857,X
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

//-------------------------------------------------------- Start RF Smart Nutrient Mode After Feeding ---------------------------
  if ((hour() >=9 && minute() >=00) || (hour() <= 21 && minute() <00))
  {  
    if (vtechmode == 9)
    {
      ReefAngel.RF.UseMemory=true;  
      vtechmode = InternalMemory.RFMode_read();
      vtechspeed = InternalMemory.RFSpeed_read();
    }
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) bFeeding=true;
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && bFeeding)
    {
      bFeeding=false; 
      ReefAngel.Timer[1].SetInterval(600); // Timer for 10min
      ReefAngel.Timer[1].Start();
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Smart_NTM,100,6);
      vtechmode = 5;
      vtechspeed = 100;
    }
    if (ReefAngel.DisplayedMenu==DEFAULT_MENU && ReefAngel.Timer[1].IsTriggered())
    {
      ReefAngel.RF.UseMemory=true;
      vtechmode = InternalMemory.RFMode_read();
      vtechspeed = InternalMemory.RFSpeed_read();
    }
  }
  else
  {
      ReefAngel.RF.UseMemory=false;
      ReefAngel.RF.SetMode(Night,15,0);
      vtechmode = 9;
      vtechspeed = 15;
  }
//---------------------------------------------------------- End RF Smart Nutrient Mode After Feeding -----------------------------   

    ReefAngel.ShowInterface();
}
//--------------------------------------------------------------- End Loop --------------------------------------------------------

//*********************************************************************************************************************************

Re: New Code - Some Troubles and Questions

Posted: Sat Feb 02, 2013 4:03 pm
by rimai
You need this:

Code: Select all

if (hour() >=9  && hour() < 21)
Instead of this:

Code: Select all

if ((hour() >=9 && minute() >=00) || (hour() <= 21 && minute() <00))

Re: New Code - Some Troubles and Questions

Posted: Sun Feb 10, 2013 1:45 pm
by mvwise
Okay, we've got the RA hooked up to the tank and all appears to be running fine except for one issue with the lights on menu item (see code above). When selected the whites, blues and fuge light are supposed to turn on, which they do, but when returning to the standard screen or exiting out of the menu it doesn't default back to the standard lights. As an example, at 3pm whites and blues are on. Selecting lights on turns on the fuge light as well. Exiting the menu however leaves the fuge light on instead of turning it back off.

Is there something in the menu I need to add?

Re: New Code - Some Troubles and Questions

Posted: Sun Feb 10, 2013 7:25 pm
by rimai
If you choose lights on, you are overriding the lights to be on all the time.
To cancel this override, you have to choose lights off, which will bring lights back into standardlights schedule.

Re: New Code - Some Troubles and Questions

Posted: Sun Feb 10, 2013 7:28 pm
by rimai
Sorry... I missed the part where you had custom menu.
You must implement another menu entry to clear the override.
Something like this:

Code: Select all

void MenuEntry5()
{
     ReefAngel.Relay.RelayMaskOn = 0;
     ReefAngel.Relay.Write();
}