Code: Select all
#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 <Humidity.h>
#include <DCPump.h>
#include <ReefAngel.h>
#include <SunLocation.h>
////// ------------------Place global variable code below here
byte wp40mode;
byte WPSpeed;
SunLocation sl;
////// ------------------Place global variable code above here
void setup(){
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Add Standard Menu
ReefAngel.AddStandardMenu();
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port3Bit | Port6Bit | Port7Bit| Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port7Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Ports that are always on
ReefAngel.Relay.On( Port3 ); //Mag 12 Return Pump
ReefAngel.Relay.On( Port4 ); //Reef Octopus Skimmer
////// ------------------Place additional initialization code below here
// initialize the sunrise / sunset location
sl.Init(30.197220, -92.080637); // Latitude , Longitude values set (LA)
sl.SetOffset(-5,0,-5,0); // rise_hour, rise_seconds, set_hour, set_seconds (LA)
// initialize default values for Custom Variables
ReefAngel.CustomVar[4]=100;
ReefAngel.CustomVar[6]=130;
ReefAngel.CustomVar[7]=75;
////// ------------------Place additional initialization code above here
}
void loop(){
//Alkalinity Drip
if (ReefAngel.Params.PH < 840) {
ReefAngel.DosingPumpRepeat(Port1, 15,
InternalMemory.DP1RepeatInterval_read(),
InternalMemory.DP1Timer_read());
}
//Calcium Drip
ReefAngel.DosingPumpRepeat(Port2, 45,
InternalMemory.DP2RepeatInterval_read(),
InternalMemory.DP2Timer_read());
//Cooling Fans
ReefAngel.StandardFan( Port6 );
//Ehiem 150W Heater
ReefAngel.StandardHeater( Port7 );
//MAXI Jet 600 ATO Pump
ReefAngel.StandardATO( Port8 );
//Right & Left Philips Rebel ES Royal Blue and Cool White & UV & Cree XT-E Green
ReefAngel.PWM.Channel1PWMSlope();
//Right Daylight Cree XP-G2 R5 Cool White
ReefAngel.PWM.Channel2PWMSlope();
//Right Actinic Cree XT-E Royal Blue
ReefAngel.PWM.Channel3PWMSlope(InternalMemory.ActinicOffset_read());
//Left Daylight Cree XP-G2 R5 Cool White
ReefAngel.PWM.Channel4PWMSlope();
//Left Actinic Cree XT-E Royal Blue
ReefAngel.PWM.Channel5PWMSlope(InternalMemory.ActinicOffset_read());
////// ------------------Place your custom code below here
// handle updating sunrise and sunset values
sl.CheckAndUpdate();
//PWM Expansion Channels = 0 if Overheat or Lights off
if ((ReefAngel.Params.Temp[T1_PROBE]>InternalMemory.OverheatTemp_read()) || (now()<sl.GetSunRise() || now()>sl.GetSunSet())) {
ReefAngel.PWM.SetChannel (1,0);
ReefAngel.PWM.SetChannel (2,0);
ReefAngel.PWM.SetChannel (3,0);
ReefAngel.PWM.SetChannel (4,0);
ReefAngel.PWM.SetChannel (5,0);
}
// moonlight are on between sunset hour and sunrise hour
if (hour()>=sl.GetSetHour() || hour()<=sl.GetRiseHour()) ReefAngel.PWM.SetChannel (0, (map(MoonPhase(), 0,100,10,25)));
else ReefAngel.PWM.SetChannel (0,0);
//Start Feeding Mode at 17:00 (hour*60*60)
if ( (now()%86400==61200) /*|| (now()%86400==39600) */) ReefAngel.FeedingModeStart();
//Hydor Evolution 1400 Circulation Pump & LED Cooling Fan (Port5) Off Between sunrise hour and sunset hour
if (hour()<sl.GetRiseHour() || hour()>=sl.GetSetHour()) {
ReefAngel.Relay.Off(Port5);
}
else {
ReefAngel.Relay.On(Port5);
}
//Custom Variables and Calculations for Dosing and Lighting Durations
int DailyAlk = ((InternalMemory.DP1Timer_read() * (.75)) * (1440 / InternalMemory.DP1RepeatInterval_read())); //Alk ml/day
int DailyCalc = ((InternalMemory.DP2Timer_read() * (.75)) * (1440 / InternalMemory.DP2RepeatInterval_read())); //Calc ml/day
int S1 = (NumMins(sl.GetSetHour(), sl.GetSetMinute()));
int S2 = (NumMins(sl.GetRiseHour(), sl.GetRiseMinute()));
int DayMins = (S1-S2);
int duration = map((DayMins), 615, 850, 60, 150);
if (duration!=ReefAngel.CustomVar[3]) {
ReefAngel.CustomVar[3]=duration;
InternalMemory.ActinicOffset_write(duration);
InternalMemory.PWMSlopeDuration1_write(duration);
InternalMemory.PWMSlopeDuration2_write(duration);
InternalMemory.PWMSlopeDuration3_write(duration);
InternalMemory.PWMSlopeDuration4_write(duration);
InternalMemory.PWMSlopeDuration5_write(duration);
}
if (DailyAlk!=ReefAngel.CustomVar[0]) ReefAngel.CustomVar[0]=DailyAlk;
if (DailyCalc!=ReefAngel.CustomVar[1]) ReefAngel.CustomVar[1]=DailyCalc;
if ((DayMins/10)!=ReefAngel.CustomVar[2]) ReefAngel.CustomVar[2]=DayMins/10;
WPSpeed = ReefAngel.CustomVar[4];
//assignmenets are = and comparisons are ==
if (ReefAngel.CustomVar[5] == 1){
ReefAngel.PWM.SetDaylight( millis()%((10 * ReefAngel.CustomVar[6]))<((10 * ReefAngel.CustomVar[7]))?WPSpeed:0); //Test "W1"
ReefAngel.PWM.SetActinic( millis()%((10 * ReefAngel.CustomVar[6]))>((10 * ReefAngel.CustomVar[6])-(10 * ReefAngel.CustomVar[7]))?0:WPSpeed); //Test "W1"
wp40mode=11;
}else{
if (hour()>=sl.GetRiseHour() && hour()<12) wp40mode=6; //sunrise hour - 11:59am
else if (hour()>=12 && hour()<17) wp40mode=7; //12pm - 4:59pm
else if (hour()>=17 && hour()<18) wp40mode=5; //5pm - 5:59pm
else if (hour()>=18 && hour()<24) wp40mode=3; //6pm - 11:59pm
else wp40mode=4; //12am - sunrise hour
};
if (wp40mode==10) ReefAngel.PWM.SetDaylight( WPSpeed ); //Constant Speed
if (wp40mode==10) ReefAngel.PWM.SetActinic( WPSpeed ); //Constant Speed
if (wp40mode==9) ReefAngel.PWM.SetActinic( GyreMode(50,(WPSpeed),3,true ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (s), PulseSync
if (wp40mode==9) ReefAngel.PWM.SetActinic( GyreMode(50,(WPSpeed),3,false ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (s), PulseSync
if (wp40mode==8) ReefAngel.PWM.SetDaylight( ElseMode(75,25,true) ); //Midpoint, Offset, PulseSync
if (wp40mode==8) ReefAngel.PWM.SetActinic( ElseMode(75,25,false) ); //Midpoint, Offset, PulseSync
if (wp40mode==7) ReefAngel.PWM.SetDaylight( millis()%1300<750?WPSpeed:0); // "W1"
if (wp40mode==7) ReefAngel.PWM.SetActinic( millis()%1300>550?0:WPSpeed); // "W1"
if (wp40mode==6) ReefAngel.PWM.SetDaylight( TidalSwellMode(WPSpeed,true ) ); //WaveMaxSpeed, PulseSync
if (wp40mode==6) ReefAngel.PWM.SetActinic( TidalSwellMode(WPSpeed,false ) ); //WaveMaxSpeed, PulseSync
if (wp40mode==5) ReefAngel.PWM.SetDaylight( NutrientTransportMode(0,WPSpeed,2000,true ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (ms), PulseSync
if (wp40mode==5) ReefAngel.PWM.SetActinic( NutrientTransportMode(0,WPSpeed,2000,false ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (ms), PulseSync
if (wp40mode==4) ReefAngel.PWM.SetDaylight( LongPulseMode(0,(WPSpeed-20),3,true ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (s), PulseSync
if (wp40mode==4) ReefAngel.PWM.SetActinic( LongPulseMode(0,(WPSpeed-20),3,false ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (s), PulseSync
if (wp40mode==3) ReefAngel.PWM.SetDaylight( ShortPulseMode(0,WPSpeed,1200,true ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (ms), PulseSync
if (wp40mode==3) ReefAngel.PWM.SetActinic( ShortPulseMode(0,WPSpeed,1200,false ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (ms), PulseSync
if (wp40mode==2) ReefAngel.PWM.SetDaylight( ReefCrestMode(WPSpeed,20,true ) ); //WaveSpeed, WaveOffset, PulseSync
if (wp40mode==2) ReefAngel.PWM.SetActinic( ReefCrestMode(WPSpeed,20,false ) ); //WaveSpeed, WaveOffset, PulseSync
if (wp40mode==1) ReefAngel.PWM.SetDaylight( SineMode(0,WPSpeed,10,true ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (ms), PulseSync
if (wp40mode==1) ReefAngel.PWM.SetActinic( SineMode(0,WPSpeed,10,false ) ); //PulseMinSpeed, PulseMaxSpeed, PulseDuration (ms), PulseSync
if (wp40mode==0) ReefAngel.PWM.SetDaylight( TideMode(WPSpeed,100,20 ) ); //WaveSpeed, minOffset, maxOffset
if (wp40mode==0) ReefAngel.PWM.SetActinic( TideMode(WPSpeed,100,20 ) ); //WaveSpeed, minOffset, maxOffset
//WP-40s off for water change
if( ReefAngel.DisplayedMenu==WATERCHANGE_MODE ) ReefAngel.PWM.SetDaylight(0);
if( ReefAngel.DisplayedMenu==WATERCHANGE_MODE ) ReefAngel.PWM.SetActinic(0);
////// ------------------Place your custom code above here