Need a quick check of my code plz
Posted: Wed Feb 13, 2013 7:52 am
I've copy/pasted several snippets of code from here and just want to make sure it is all in the right place and not missing anything
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 <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port7Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port7Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 790 );
// Ports that are always on
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port6 );
ReefAngel.Relay.On( Port7 );
ReefAngel.Relay.On( Port8 );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );
////// Place your custom code below here
if (hour()>20 && hour()<8)
{
ReefAngel.PWM.SetActinic(30);
ReefAngel.PWM.SetDaylight(30);
}
//*** Define only one mode ***
//#define TUNZE_MODE_SINE // sine wave, no pulse
//#define TUNZE_MODE_LONG // no sine wave, long pulse
//#define TUNZE_MODE_SHORT // no sine wave, short pulse
//#define TUNZE_MODE_LONGSINE // sine wave, long pulse
#define TUNZE_MODE_SHORTSINE // sine wave, short pulse
#define TUNZE_MIN 30
#define TUNZE_MAX 85
#define TUNZE_SINE_SEC 23400
#define TUNZE_SINE_SYNC false
#define TUNZE_LONGPULSE_SEC 2
#define TUNZE_LONGPULSE_SYNC true
#define TUNZE_SHORTPULSE_MS 500
#define TUNZE_SHORTPULSE_SYNC true
//PulseMinSpeed - % for minimal speed
//PulseMaxSpeed - % for maximum speed
//PulseDuration - Duration (milliseconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will stay at maximum speed for PulseDuration.
//PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
byte TunzeShortPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
byte tspeed=0;
PulseMinSpeed=constrain(PulseMinSpeed,30,100);
PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
tspeed=(millis()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
if (PulseSync)
return tspeed;
else
return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}
//PulseMinSpeed - % for minimal speed
//PulseMaxSpeed - % for maximum speed
//PulseDuration - Duration (seconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will stay at maximum speed for PulseDuration.
//PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
byte tspeed=0;
PulseMinSpeed=constrain(PulseMinSpeed,30,100);
PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
if (PulseSync)
return tspeed;
else
return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}
byte TunzeSineWave(boolean isleftpump, byte minspeed, byte maxspeed, int period_sec) {
double x,y;
x=double(now()%(period_sec));
x/=period_sec;
x*=2.0*PI;
if (!isleftpump) x+=PI; // shift the sine wave for the right pump
y=sin(x);// y is now between -1 and 1
y+=1.0; // y is now between 0 and 2
y/=2.0; // y is now between 0 and 1
// now compute the tunze speed
y*=double(maxspeed-minspeed);
y+=double(minspeed);
y+=0.5; // for proper rounding
// y is now between minspeed and maxspeed, constrain for safety
return constrain(byte(y),30,100);
}
void RunTunzes() {
#ifdef TUNZE_MODE_SINE
ReefAngel.PWM.SetDaylight(TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // left tunze
ReefAngel.PWM.SetActinic(TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // right tunze
#endif
#ifdef TUNZE_MODE_LONG
ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,true)); // left tunze
ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
#endif
#ifdef TUNZE_MODE_SHORT
ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,true)); // left tunze
ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
#endif
#ifdef TUNZE_MODE_LONGSINE
ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,true)); // left tunze
ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
#endif
#ifdef TUNZE_MODE_SHORTSINE
ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,true)); // left tunze
ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
#endif
}
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "Mason Dixon" );
ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
int x,y;
char text[10];
// Dimming Expansion
x = 15;
y = 2;
for ( int a=0;a<6;a++ )
{
if ( a>2 ) x = 75;
if ( a==3 ) y = 2;
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :" );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a );
ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,ReefAngel.PWM.GetChannelValue(a) );
y += 10;
}
pingSerial();
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();
// pH Expansion
ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,15,76, "PHE:" );
ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,39,76, ReefAngel.Params.PHExp );
pingSerial();
// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 93, TempRelay );
pingSerial();
// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}
void DrawCustomGraph()
{
}