Code: Select all
#include <Salinity.h>
#include <Relay.h>
#include <RA_ATO.h>
#include <RF.h>
#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>fa
#include <RA_CustomColors.h>f
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>
////// Place global variable code below here
byte myRFMode=0;
byte myRFDuration=0;
byte myRFSpeed=0;
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled
ReefAngel.WaterChangePorts = Port5 |Port6; // Turn off Return, UV, Skimmer, Heater, Sump Equipment, ATO
ReefAngel.FeedingModePorts = Port6; // Turn off Return and Skimmer
ReefAngel.LightsOnPorts = Port2|Port4|Box1_Port1|Box1_Port8; //Turn on ATI lights, Fan and Fuge Light
ReefAngel.OverheatShutoffPorts = Port1 |Port4|Port6| Box1_Port1| Box1_Port4|Box1_Port6;
ReefAngel.TempProbe = T2_PROBE;
ReefAngel.OverheatProbe = T2_PROBE;
InternalMemory.OverheatTemp_write( 825 ); // Set the Overheat temperature setting
// Ports that are always on
////// Place additional initialization code above here
}
// ReefAngel.StandardLights( Port3,23,0,12,0 ); // Fuge Light
// ReefAngel.Relay.On(Port3); // Port3 Return Pump -- Always on
//ReefAngel.StandardLights( Port2,10,0,23,0 ); // ReefBrites
// ReefAngel.Relay.Off( Port4); // 11 Box1_Port3 UV - Only turn on UV Sterilizer between 11pm and 4am
// if ( (hour() >= 7) && (hour() < 23) )
// ReefAngel.Relay.Off(Port4);
// else ReefAngel.Relay.On(Port4);
// ReefAngel.StandardLights( Port4,12,00,20,30 ); // Light --- Actinic 12 to 8:30
//ReefAngel.Relay.On(Port5); // Port5 Saltwater Change
// ReefAngel.Relay.On(Port6); //ATO
// ReefAngel.Relay.Set(Port6, ReefAngel.HighATO.IsActive()); //Turns port 6 off when High ATO is on
//ReefAngel.StandardHeater(Port7,777,790 ); // 9 Box1_Port1 Heater
// // ReefAngel.Relay.On (Port7); // Port7 Frag Tank -- Always on
//ReefAngel.Relay.On( Port8); // Port8 Skimmer -- 5 min delay start
void loop()
{
//Box1
ReefAngel.StandardHeater(Port1,778,790 ); // 1 Heater
ReefAngel.StandardLights( Port2,13,0,22,0 ); // 2 ReefBrites
ReefAngel.Relay.Off(Port3) ; // 3 Saltwater Pump
ReefAngel.StandardLights( Port4,14,0,20,0 ); // 4 Daylights
ReefAngel.SingleATO( true,Port5,900,0 ); // 5 ATO - RODI
ReefAngel.Relay.On(Port6) ; // 6 Return Pump
ReefAngel.Relay.Set(Port7,ReefAngel.Relay.Status(Port6)); // 7 UV Pump
ReefAngel.Relay.Set(Port8,ReefAngel.Relay.Status(Port6)); // 8 Calcium Reactor faPump
ReefAngel.UseFlexiblePhCalibration();
//box 2 (Box1_Portxx)
//!flips the status of the port for conditional statements
ReefAngel.StandardLights( Box1_Port1,13,30,21,0 ); // 9 Actinics
ReefAngel.StandardHeater( Box1_Port2,778,790 ); // 10 Heater
ReefAngel.Relay.Set(Box1_Port3,ReefAngel.Relay.Status(Port6)); // 11 Skimmer
ReefAngel.Relay.Set(Box1_Port4,!ReefAngel.Relay.Status(Port2)); // 12 Fuge Lights
ReefAngel.Relay.On(Box1_Port5); // 13 Ecotech Pumps
ReefAngel.StandardHeater(Box1_Port6,770,790 ); // 14 Heater
ReefAngel.CO2Control( Box1_Port7,720,725); // 15 Box1_Port7 Regulator (PhLow,PhHigh)
ReefAngel.StandardLights( Box1_Port8,12,0,21,45 ); // 16 Box1_Port8 Fan
// ReefAngel.StandardLights( Port1,12,0,19,0 );
// ReefAngel.StandardLights( Port2,9,0,19,0 );
// Old Code
//moonlight dimming
// if (hour()>=6 && hour()<10) ReefAngel.PWM.SetDaylight( PWMParabola(6,0,10,0,9,100,9) ); // Moonlight Between 5-10am turn the relay on
// if (hour()>=20 && hour()<=23) ReefAngel.PWM.SetDaylight( PWMParabola(20,0,23,0,100,0,100) ); // From 8pm-Midnight turn the relay on
// else ReefAngel.PWM.SetDaylight(0);
// ReefAngel.Relay.Set( Port2, !ReefAngel.Relay.Status( Port4 ) ); //Refuge opposite of Actinic
// ReefAngel.Relay.Off( Box1_Port3); // Start with the relay off Port #11 Moonlight
//if (hour()>=5 && hour()<10) ReefAngel.Relay.On(Box1_Port3); // Moonlight Between 5-10am turn the relay on
//if (hour()>=20 && hour()<=23) ReefAngel.Relay.On(Box1_Port3); // From 8pm-Midnight turn the relay
// ReefAngel.PWM.SetDaylight( PWMSlope(20,0,23,0,100,0,180,100) );
// ReefAngel.PWM.SetDaylight( PWMSlope(6,0,10,0,9,100,240,9) );
//ReefAngel.Relay.off(Box1_Port3);
// if (hour()>=10 || hour()<20) ReefAngel.PWM.SetDaylight(0);
// ReefAngel.PWM.SetDaylight( MoonPhase()+10 );
// ReefAngel.PWM.SetDaylight(PWMParabola(20,0,23,0,0, MoonPhase(),0 ));
//ReefAngel.PWM.SetDaylight(PWMSlope(6,0,23,0,0,100,240,0));
//if (hour()>=5 && hour()<20) ReefAngel.PWM.SetDaylight(0);
//ReefAngel.PWM.SetDaylight( PWMParabola(20,0,23,0,100,0,100) );
//ReefAngel.PWM.SetDaylight( PWMParabola(6,0,10,0,9,100,9) );
////// Place your custom code below here
// ReefAngel.RF.UseMemory = false;
// if (hour()>=6 && hour()<11)
// myRFSetMode(ReefCrest,85,10);
// else if (hour()>=11 && hour()<13)
// myRFSetMode(ReefCrest,85,10);
//else if (hour()>=13 && hour()<16)
//myRFSetMode(Smart_NTM,85,50);
//else if (hour()>=16 && hour()<19)
//myRFSetMode(ReefCrest,65,10);
//else
// myRFSetMode(Lagoon,40,10);
// Hardcode PH calibrations
//ReefAngel.PHMin=544; // PH7.0
//ReefAngel.PHMax=830; // PH10.0
// RunDosingPumps();
// LogDosingPumps();
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "ecam" );
ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
ReefAngel.LCD.DrawDate(6, 122);
pingSerial();
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue()
);
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 20, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
//sALINITY
pingSerial();
char text[10];
ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
strcat(text," ");
ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,15,50,"Salinity:");
ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,75,50,text);
//PH Expansion
pingSerial();
ConvertNumToString(text, ReefAngel.Params.PHExp, 1);
strcat(text," ");
ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,15,60,"pH_Expan:");
ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,75,60,text);
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
//ReefAngel.LCD.DrawOutletBox(12, 103, TempRelay);
// Main Relay Box
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 102, TempRelay );
pingSerial();
// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}
/////////////////////////////////////////
// Define Your dosing pumps
/////////////////////////////////////////
//#define numDPumps 3
// byte pumpRelays[numDPumps]={ Box1_Port2};
// int DPVolume[numDPumps]={ 0, 25,28} ; // 1ml for each alk and calcium - total volume for the day
//int DPRepeat[numDPumps]={ 360, 240, 240 } ; // Repeat every 4 hrs 6x a day --- in mins
/////////////////////////////////////////
// Define Calibration here
/////////////////////////////////////////
// int CalTime[numDPumps]={ 600, 600, 600 }; // 10 minutes / 10 minutes
//int CalVol[numDPumps]={ 350, 300,384 }; // 350ml / 300ml... .58 / .5/.64
/////////////////////////////////////////
// Function: RunDosingPumps()
/////////////////////////////////////////
//void RunDosingPumps() {
//float rate;
//int calcTime[numDPumps];
// for (int i=0;i < numDPumps; i++) {
// rate=(float)CalVol[i]/CalTime[i];
// calcTime[i]=DPVolume[i]/rate/(1440/DPRepeat[i]);
// Run the pumps
// ReefAngel.DosingPumpRepeat(pumpRelays[i], i*5, DPRepeat[i], calcTime[i]); // Offset between each pump is 5 minutes
// }
// Display Time calculated in portal
// ReefAngel.CustomVar[0]=calcTime[0];
// ReefAngel.CustomVar[1]=calcTime[1];
///ReefAngel.CustomVar[2]=calcTime[2];
// }
/////////////////////////////////////////
// Function: LogDosingPumps()
/////////////////////////////////////////
//void LogDosingPumps() {
//static time_t pumpTimer[numDPumps];
//static boolean pumpStatus[numDPumps];
//float rate;
//for (int i=0;i< numDPumps;i++) {
// if (ReefAngel.Relay.Status(pumpRelays[i])) {
// if (!pumpStatus[i]) {
// pumpTimer[i]=now()-pumpTimer[i]; // Pump was off, timer is now a time
//pumpStatus[i]=true;
// }
// } else {
// if (pumpStatus[i]) {
// pumpTimer[i]=now()-pumpTimer[i]; // Pump was on, timer is now a timer
// pumpStatus[i]=false;
// rate=(float)CalVol[i]/CalTime[i];
// Report How much volume has been dosed per day.fa
// Could make this in minutes... excercise for the reader..
// ReefAngel.CustomVar[3]=pumpTimer[0]*rate;
//ReefAngel.CustomVar[4]=pumpTimer[1]*rate;
//ReefAngel.CustomVar[5]=pumpTimer[2]*rate;
// }
// }
// Clear timer at end of day
// if (now()%SECS_PER_DAY==SECS_PER_DAY-1) pumpTimer[i]=0;
// }
// }
void DrawCustomGraph()
{
}
void myRFSetMode(byte m, byte s, byte d)
{
if (m!=myRFMode || s!=myRFSpeed || d!=myRFDuration || millis()<5000)
{
myRFMode=m;
myRFSpeed=s;
myRFDuration=d;
ReefAngel.RF.SetMode(m,s,d);
}
}