I have a routine in my code that says "if in custom mode then set my dc pump to do reefcrest , x y ,z"
As the code runs and cycles through itself over and over, does it re-read that "if" line and re-apply the statement?
So if reefmode is supposed to run at a set speed for 5 seconds, if the code re-applies because it completed and restarted, does it interrupt that ?
[
Flow question
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Flow question
No it won't the variables within the reefcrestmode are "static" meaning it doesnt reset each times its run.
And if you didn't do that in your custom mode code, the default code does exactly that..runs that same function each iteration of loop()
And if you didn't do that in your custom mode code, the default code does exactly that..runs that same function each iteration of loop()
-
Smotz
- Posts: 401
- Joined: Sat Mar 30, 2013 5:02 pm
- Location: CT, USA
Re: Flow question
By static do you mean that if the program determines that the value is the same it does not change it or re-apply it?lnevo wrote:No it won't the variables within the reefcrestmode are "static" meaning it doesnt reset each times its run.
And if you didn't do that in your custom mode code, the default code does exactly that..runs that same function each iteration of loop()
Did I do that correctly?
Code: Select all
//// Port 1 Heater
//// Port 2 ATO pump
//// Port 3 Reactor Pump
//// Port 4 Protien Skimmer
//// Port 5 Return Pump
//// Port 6 Wavemaker
//// Port 7 UV Sterilizer
//// Port 8 Fuge Light
//// Always on - Lights & Salinity Module
#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 <DCPump.h>
#include <ReefAngel.h>
////// Place global variable code below here
#define Heater Port1
#define Topoff Port2
#define Reactor Port3
#define Skimmer Port4
#define Return Port5
#define Wave Port6
#define UVlight Port7
#define Fugelight Port8
#define FugelightBit 1<<7
#define UVlightBit 1<<6
#define WaveBit 1<<5
#define ReturnBit 1<<4
#define SkimmerBit 1<<3
#define ReactorBit 1<<2
#define TopoffBit 1<<1
#define HeaterBit 1<<0
static byte wpMode;
static byte wpWavStr;
static byte wpWavOff;
////// 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 = TopoffBit | ReactorBit | SkimmerBit | ReturnBit | UVlightBit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = FugelightBit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = HeaterBit | TopoffBit | ReactorBit | SkimmerBit | ReturnBit | WaveBit | UVlightBit;
// Use T1 (SUMP) probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Ports that are always on
ReefAngel.Relay.On( Return );
ReefAngel.Relay.On( Reactor );
ReefAngel.Relay.On( Wave );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardHeater( Heater );
ReefAngel.StandardATO( Topoff );
ReefAngel.MoonLights( Fugelight );
////// Place your custom code below here
ReefAngel.LCD.DrawText(0,255,20,80,"Joe's Reef Tank");
ReefAngel.Relay.DelayedOn(Skimmer,2);
ReefAngel.Relay.DelayedOn(UVlight,1);
ReefAngel.DCPump.FeedingSpeed=30;
ReefAngel.DCPump.WaterChangeSpeed=0;
ReefAngel.DCPump.UseMemory = true;
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = AntiSync;
// Custom Wave Routine
if (ReefAngel.DCPump.Mode==Custom) {
ReefAngel.DCPump.UseMemory=false;
ReefAngel.DCPump.SetMode( ReefCrest,wpWavStr,wpWavOff );
// Set Wave Str
if (wpMode=1) wpWavStr=45;
if (wpMode=2) wpWavStr=50;
if (wpMode=3) wpWavStr=55;
//Set the Wave OffSet
wpWavOff=15;
// set the wpMode
if ( (hour() >= 5) && (hour() < 8) ) wpMode=1; // from 5am - 8am
if ( (hour() >= 8) && (hour() < 11) ) wpMode=2; // from 8am - 11am
if ( (hour() >= 11) && (hour() < 14) ) wpMode=3; // from 11a - 2pm
if ( (hour() >= 14) && (hour() < 17) ) wpMode=2; // from 2pm - 5pm
if ( (hour() >= 17) && (hour() < 20) ) wpMode=1; // from 5pm - 8pm
if ( (hour() >= 20) && (hour() < 23) ) wpMode=2; // from 8pm - 11p
if ( (hour() >= 23) && (hour() < 2) ) wpMode=3; // from 11pm - 2am
if ( (hour() >= 2) && (hour() < 5) ) wpMode=2; // from 2am - 5am
}
// end Custom Wave Routine
// Only turn on UV Sterilizer between 11pm and 5am
if ( (hour() >= 5) && (hour() < 23) ) // from 5a - 11p
ReefAngel.Relay.Off(UVlight);
else ReefAngel.Relay.On(UVlight);
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "Smotz" );
ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
int x,y;
char text[10];
char buf[16];
if (ReefAngel.DCPump.Mode==Custom) sprintf(buf,"RC %d% +/-%d%",wpWavStr,wpWavOff);
else sprintf(buf,"%d%",ReefAngel.DCPump.Mode);
x = 15;
y = 52;
//ReefAngel.LCD.DrawText(0,255,x,y,"RF:");
//ReefAngel.LCD.Clear(DefaultBGColor,x,y,128-x,y+8);
ReefAngel.LCD.DrawText(0,255,x,y,buf);
// 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
pingSerial();
// Salinity
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,15,66, "SAL:" );
ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,39,66, ReefAngel.Params.Salinity );
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()
{
}
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: Flow question
No, you don't need to make your variables static because they are global variables.
The point was inside the ReefCrestMode function, the variables that track the time and when to change, etc are static and so they are not re-initialized each time ReefCrestMode is called.
You can leave your global variables (wpMode, etc..) the way you called them originally.
The only thing I would do different with your code is put the SetMode command after all your wpWavStr and wpWavOff are determined. It will still work, but whatever you choose in the logic after it currently will not be applied till the next iteration of loop...
The point was inside the ReefCrestMode function, the variables that track the time and when to change, etc are static and so they are not re-initialized each time ReefCrestMode is called.
You can leave your global variables (wpMode, etc..) the way you called them originally.
The only thing I would do different with your code is put the SetMode command after all your wpWavStr and wpWavOff are determined. It will still work, but whatever you choose in the logic after it currently will not be applied till the next iteration of loop...