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,53,14,"Sump");
// 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.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE; // Will change to T3_PROBE when can extend the T3 Probe to reach canopy.
ReefAngel.FeedingModePorts = Port1Bit;
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port6Bit | Port7Bit |Port8Bit;
ReefAngel.OverheatShutoffPorts = Port2Bit;
ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port4Bit;
ReefAngel.LightsOnPortsE[0] = Port1Bit | Port2Bit | Port3Bit | Port4Bit;
// Ports that are always on
// ReefAngel.Relay.On(Port1); Temporary taking this out to see if StandardATO code works
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.StandardATOExtended(Port1); // ATO using Internal Memory for timeout
ReefAngel.StandardHeater(Port2);
ReefAngel.StandardFan(Box1_Port7);
ReefAngel.ActinicLights(Box1_Port1); //Left Blue LEDs
ReefAngel.ActinicLights(Box1_Port2); //Right Blue LEDs
ReefAngel.DayLights(Box1_Port3); //Left White LEDs
ReefAngel.DayLights(Box1_Port4); //Right White LEDs
ReefAngel.MoonLights(Box1_Port5); //Left Moonlight
ReefAngel.MoonLights(Box1_Port6); //Right Moonlight
ReefAngel.MoonLights(Port4); //Fuge light on when main lights are out
//------------------------------------------------ Start PWM Expansion Code for Slope ----------------------------------------------
ReefAngel.PWM.SetChannel(LEDPWM0,int(PWMChannel[LEDPWM0]));
ReefAngel.PWM.SetChannel(LEDPWM1,int(PWMChannel[LEDPWM1]));
ReefAngel.PWM.SetChannel(LEDPWM2,int(PWMChannel[LEDPWM2]));
ReefAngel.PWM.SetChannel(LEDPWM3,int(PWMChannel[LEDPWM3]));
ReefAngel.PWM.Channel0PWMParabola(InternalMemory.ActinicOffset_read());
ReefAngel.PWM.Channel1PWMParabola(InternalMemory.ActinicOffset_read());
ReefAngel.PWM.Channel2PWMParabola();
ReefAngel.PWM.Channel3PWMParabola();
//------------------------------------------------- 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();
}
// This sends all the data to the portal
// Do not add any custom code that changes any relay status after this line
// The only code after this line should be the ShowInterface function
ReefAngel.Portal("TanksNStuff");
// This should always be the last line
ReefAngel.ShowInterface();
//---------------------------------------------------------- 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.)