Re: Custom code, please help
Posted: Wed Oct 03, 2012 10:36 am
The new relay box seems quieter than the old one. Nice.
I have few questions about my code:
- I tried to setup wavemaker on box1_port5&6 but the compiler gave me a file too big error. What am I doing wrong?
- to control a power head I'm using ReefAngel.StandardLights(Box1_Port8,20,0,22,0);. Can i use a more appropriate variable. I tried using ReefAngel.Relay.On code but it gave me an error.
- the new wizard produces new lines of code. What is the purpose of this command? ReefAngel.FeedingModePortsE[0] = 0; // I got it. it's for the 2nd relay ports.
- if I remove/disconnect the RA head unit, the relay boxes turn all the ports off. Is it possible to make them retain the current state or at least only few of the ports like pumps, skimmer, lights.
- is it possible to turn on specific ports during feeding? I'd like to have a circulation pump turn on for few minutes during feeding on port box1_port3.
- how to setup a timeout time for Dosing pumps?
Thank you.
===
Thne main code is:
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
void setup()
{
ReefAngel.Init();
ReefAngel.FeedingModePorts = Port8Bit;
ReefAngel.FeedingModePortsE[0] = 0;
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port8Bit | Port7Bit;
ReefAngel.WaterChangePortsE[0] = 0;
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port7Bit;
ReefAngel.WaterChangePortsE[0] = 0;
ReefAngel.LightsOnPorts = 0;
ReefAngel.Relay.On( Port8 );
ReefAngel.Relay.On( Box1_Port4 );
ReefAngel.Relay.On( Box1_Port5 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
ReefAngel.PHMin = 537;
ReefAngel.PHMax = 860;
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
InternalMemory.OverheatTemp_write( 830 );
}
void loop()
{
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.DosingPumpRepeat(Box1_Port1,0,120,2);
ReefAngel.DosingPumpRepeat(Box1_Port1,1,120,2);
if (hour() >= 10 && hour() < 20)
{
ReefAngel.StandardLights(Port1,11,1,19,0);
ReefAngel.StandardLights(Port3,11,0,19,0);
ReefAngel.StandardLights(Port4,10,0,19,59);
ReefAngel.StandardLights(Box1_Port3,11,0,19,0);
ReefAngel.PWM.SetDaylight(PWMSlope(11,0,19,0,0,0,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(10,0,19,59,0,20,180,0));
}
else
{
ReefAngel.StandardLights(Port3,20,0,6,0);
ReefAngel.StandardLights(Port4,21,0,5,0);
ReefAngel.StandardLights(Port2,21,1,5,0);
ReefAngel.StandardLights(Box1_Port8,20,0,22,0);
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(20,0,6,0,0,20,180,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(21,0,5,0,0,0,180,0));
}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1200 || ReefAngel.Params.Temp[T3_PROBE] >= 1200) {ReefAngel.Relay.On(Port6);}
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) {ReefAngel.Relay.Off(Port6);}
ReefAngel.ShowInterface();
ReefAngel.Portal("d0lph1n","*****");
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte
endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+((unsigned long)NumMins(startHour, startMinute)*60);
if (hour()<startHour) Start-=86400;
unsigned long StartD = Start + (Duration*60);
unsigned long End = nextMidnight(now())+((unsigned long)NumMins(endHour, endMinute)*60);
if (hour()<startHour) End-=86400;
unsigned long StopD = End - (Duration*60);
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM,
endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM,
endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
return oldValue;
}
I have few questions about my code:
- I tried to setup wavemaker on box1_port5&6 but the compiler gave me a file too big error. What am I doing wrong?
- to control a power head I'm using ReefAngel.StandardLights(Box1_Port8,20,0,22,0);. Can i use a more appropriate variable. I tried using ReefAngel.Relay.On code but it gave me an error.
- the new wizard produces new lines of code. What is the purpose of this command? ReefAngel.FeedingModePortsE[0] = 0; // I got it. it's for the 2nd relay ports.
- if I remove/disconnect the RA head unit, the relay boxes turn all the ports off. Is it possible to make them retain the current state or at least only few of the ports like pumps, skimmer, lights.
- is it possible to turn on specific ports during feeding? I'd like to have a circulation pump turn on for few minutes during feeding on port box1_port3.
- how to setup a timeout time for Dosing pumps?
Thank you.
===
Thne main code is:
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
void setup()
{
ReefAngel.Init();
ReefAngel.FeedingModePorts = Port8Bit;
ReefAngel.FeedingModePortsE[0] = 0;
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port8Bit | Port7Bit;
ReefAngel.WaterChangePortsE[0] = 0;
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port7Bit;
ReefAngel.WaterChangePortsE[0] = 0;
ReefAngel.LightsOnPorts = 0;
ReefAngel.Relay.On( Port8 );
ReefAngel.Relay.On( Box1_Port4 );
ReefAngel.Relay.On( Box1_Port5 );
ReefAngel.Relay.On( Box1_Port6 );
ReefAngel.Relay.On( Box1_Port7 );
ReefAngel.PHMin = 537;
ReefAngel.PHMax = 860;
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
InternalMemory.OverheatTemp_write( 830 );
}
void loop()
{
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.DosingPumpRepeat(Box1_Port1,0,120,2);
ReefAngel.DosingPumpRepeat(Box1_Port1,1,120,2);
if (hour() >= 10 && hour() < 20)
{
ReefAngel.StandardLights(Port1,11,1,19,0);
ReefAngel.StandardLights(Port3,11,0,19,0);
ReefAngel.StandardLights(Port4,10,0,19,59);
ReefAngel.StandardLights(Box1_Port3,11,0,19,0);
ReefAngel.PWM.SetDaylight(PWMSlope(11,0,19,0,0,0,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(10,0,19,59,0,20,180,0));
}
else
{
ReefAngel.StandardLights(Port3,20,0,6,0);
ReefAngel.StandardLights(Port4,21,0,5,0);
ReefAngel.StandardLights(Port2,21,1,5,0);
ReefAngel.StandardLights(Box1_Port8,20,0,22,0);
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(20,0,6,0,0,20,180,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(21,0,5,0,0,0,180,0));
}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1200 || ReefAngel.Params.Temp[T3_PROBE] >= 1200) {ReefAngel.Relay.On(Port6);}
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) {ReefAngel.Relay.Off(Port6);}
ReefAngel.ShowInterface();
ReefAngel.Portal("d0lph1n","*****");
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte
endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+((unsigned long)NumMins(startHour, startMinute)*60);
if (hour()<startHour) Start-=86400;
unsigned long StartD = Start + (Duration*60);
unsigned long End = nextMidnight(now())+((unsigned long)NumMins(endHour, endMinute)*60);
if (hour()<startHour) End-=86400;
unsigned long StopD = End - (Duration*60);
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM,
endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM,
endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
return oldValue;
}