PaulTurner911 Code

Share you PDE file with our community
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: PaulTurner911 Code

Post by lnevo »

Just adding a link to Paul's most recent code, since there's about 15 pages of me and Steve troubleshooting his... lol

http://forum.reefangel.com/viewtopic.php?p=32040#p32040
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

lnevo wrote:Just adding a link to Paul's most recent code, since there's about 15 pages of me and Steve troubleshooting his... lol

http://forum.reefangel.com/viewtopic.php?p=32040#p32040
You SIR are a gentleman and a scholar!!! :)
Just paypal'd Roberto some money for a second jeabo adapter, pumps and harness should arrive soon, patience is a virtue.

Lee, Id like to be in the same boat as Scohen running them antisync and retaining current functionality.

Sorry to beat a dead horse, but could you please run down the duration and speed setup again?!? I think I remember duration in the portal does nothing, but speed has a variance that is defined somewhere hardcoded to make the pump run from 25%-75%. Just dont remember where to define this value and what it should be.

Thank you!!
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: PaulTurner911 Code

Post by Sacohen »

Maybe Lee can add more to it, or explain it better, but this is what I have in my code of the speed variable.

Code: Select all

ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),20,true );    // ElseMode on sync mode, Portal Speed Setting +/- 20%
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: PaulTurner911 Code

Post by lnevo »

Speed is Speed and Duration is Duration. You have nothing in your code that will make anything change versus what's set in the portal. No Variance that I can find. You only had one pump... so would not even mean anything to you initially...

I sent you how to activate the second pump in the anti-sync mode... You just need to define the channel and what it is going to be Sync/Anti-Sync.

Lee
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Got it.
You make it sound so simple.
And make me feel like an ass for asking.
There is something that we used to limit the pumps range of power, effectivly stopping the pump from running full power. For whatever reason I thought it had to do with speed and duration.
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

lnevo wrote:Speed is Speed and Duration is Duration. You have nothing in your code that will make anything change versus what's set in the portal. No Variance that I can find. You only had one pump... so would not even mean anything to you initially...

I sent you how to activate the second pump in the anti-sync mode... You just need to define the channel and what it is going to be Sync/Anti-Sync.

Lee
// Change this to what you want your min/max based on vortech speed
// This is for those functions that take both, but only one memory slot.
int minOffset=25;
int maxOffset=25;

This is what I was thinking....isnt this where you would define the range of the pump (in relation to portal speed)?
PORTAL SPEED=60(currently) +/-25
Pump should run 35-85?
I must not have the correct understanding (not uncommon)
Trying to refresh my noodle.
Last edited by Paulturner911 on Mon Jun 23, 2014 1:48 pm, edited 1 time in total.
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: PaulTurner911 Code

Post by Sacohen »

lnevo wrote:Just adding a link to Paul's most recent code, since there's about 15 pages of me and Steve troubleshooting his... lol

http://forum.reefangel.com/viewtopic.php?p=32040#p32040
We never did fix the problem.
I think you said you were going to fix it on the back end.
I can start a new thread for that issue if you want.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: PaulTurner911 Code

Post by lnevo »

Lol what was the issue that you couldnt set the % on the 2nd pump differently?
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Badass! Got everything working, just need the pump!

I also added my skimmer to the feed mode and water change so it power cycles instead of running when its not needed. Added Long Pulse to the random...atleast it didnt give me an error, so I think I did :)

Thanks for the help!
I hadnt touched this stuff in ages, had to do the drivers and software install again since I replaced the HD on my PC. Kinda started to sweat for a min, but it all worked out :)

Code: Select all

// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port2Bit | Port3Bit | Port7Bit | Port8Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit | Port6Bit | Port7Bit | Port8Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;

// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;


// Ports that are always on

////// Place additional initialization code below here


////// Place additional initialization code above here
}

void loop()
{
ReefAngel.DayLights( Port1 ); // Return Pump
ReefAngel.StandardFan( Port2 ); // Canopy Fans
ReefAngel.ActinicLights( Port3 ); // Actinic LEDS
//Port4 Kalk/ATO
//Port5 Kalk Stir
ReefAngel.DayLights( Port6 );//Port 6 Skimmer
ReefAngel.DayLights( Port7 ); // MH 1
ReefAngel.DayLights( Port8 ); //MH 2
//Moonlight Phase 9pm-10am (CH4-CH5)
if ( (hour() >=10) && (hour() <21) ) 
ReefAngel.PWM.SetChannel( 4,(0) );
else 
ReefAngel.PWM.SetChannel( 4, MoonPhase() );
if ( (hour() >=10) && (hour() <21) ) 
ReefAngel.PWM.SetChannel( 5,(0) );
else
ReefAngel.PWM.SetChannel( 5, MoonPhase() );

//Over Flow Protection
if (ReefAngel.HighATO.IsActive())
ReefAngel.Relay.On(Port1);
else
ReefAngel.Relay.Off(Port1);

//ATO Protection
if (ReefAngel.LowATO.IsActive())
ReefAngel.Relay.On(Port4);
else
ReefAngel.Relay.Off(Port4);

//Kalk Dose 60sec @ 11pm-12pm (every 15min)
if (hour() >=23 || hour() < 12)
ReefAngel.Relay.Set(Port4, now()%900<60);
else
ReefAngel.Relay.Off(Port4);

//Kalk Stir 12pm-1pm
if (hour() >=12 & hour() < 13)
ReefAngel.Relay.On(Port5);
else
ReefAngel.Relay.Off(Port5);

ReefAngel.DCPump.UseMemory = true;
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = AntiSync;
////// Place your custom code below here

///// Place your custom code below here

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, TidalSwell, ShortPulse, LongPulse, NutrientTransport };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<900) { 
  // First 15 minutes after feeding mode stops. Return Pump is off
  ReefAngel.Relay.Off(Port1);
  // First 15 minutes after feeding mode stops. Smart_NTM
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()-feeding<4500) { // 15 minutes plus 1 hour
  // Continue NTM for the next 60 minutes (75 minutes total)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<30600 || now()%SECS_PER_DAY>=81000) { // 8:30am / 10:30pm
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=Constant;
  ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Right back at it of course...

Added else mode after hacking around with SaCohens code.
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: PaulTurner911 Code

Post by Sacohen »

lnevo wrote:Lol what was the issue that you couldnt set the % on the 2nd pump differently?
That was one issue, but the one that didn't get resolved is that the portal shows every option available to the RA when it is in Else Mode.

I started a new thread so we don't fill up Paul's thread with this issue,

http://forum.reefangel.com/viewtopic.php?f=12&t=4696
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Code: Select all

if (rmode==Else) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Mode=Constant;
    ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),25,true );    // ElseMode on sync mode, Portal Speed Setting +/- 20%
  } else {
Should this call "else" when "constant" is selected?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: PaulTurner911 Code

Post by lnevo »

Its constant because we want the pump set at the speed that elsemode calculates. We could also put it in Custom mode here but then you would have to call the pwm commands directly.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

OK, I was trying to replicate his portal issue showing EVERYTHING, since I am running pretty much the same code.

Lee, If you get a min, please glance over my code and tell me if you see any issues in the stuff I cut and pasted from Sacohens code. Like I said, it uploaded :) Ive run feedmode and all seemed well.

Ill keep an eye out for else mode and wonky portal display. Is it only the day (in my case) that random calls ELSEMODE that the portal shows this?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: PaulTurner911 Code

Post by lnevo »

Where is it?
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

lnevo wrote:Where is it?
Sorry Lee, I must have neglected to attach it. Ill plug it in later this evening.
Everything seems ok, I just took my old code and added a few things I saw in Sacohens code that seemed like it was needed for Else mode.

Just kept clicking away and reading bits and pieces of threads.

Thanks!
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

This is current:

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>

////// 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 = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port2Bit | Port3Bit | Port7Bit | Port8Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit | Port6Bit | Port7Bit | Port8Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;

// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;


// Ports that are always on

////// Place additional initialization code below here


////// Place additional initialization code above here
}

void loop()
{
ReefAngel.DayLights( Port1 ); // Return Pump
ReefAngel.StandardFan( Port2 ); // Canopy Fans
ReefAngel.ActinicLights( Port3 ); // Actinic LEDS
//Port4 Kalk/ATO
//Port5 Kalk Stir
ReefAngel.DayLights( Port6 );//Port 6 Skimmer
ReefAngel.DayLights( Port7 ); // MH 1
ReefAngel.DayLights( Port8 ); //MH 2
//Moonlight Phase 9pm-10am (CH4-CH5)
if ( (hour() >=10) && (hour() <21) ) 
ReefAngel.PWM.SetChannel( 4,(0) );
else 
ReefAngel.PWM.SetChannel( 4, MoonPhase() );
if ( (hour() >=10) && (hour() <21) ) 
ReefAngel.PWM.SetChannel( 5,(0) );
else
ReefAngel.PWM.SetChannel( 5, MoonPhase() );

//Over Flow Protection
if (ReefAngel.HighATO.IsActive())
ReefAngel.Relay.On(Port1);
else
ReefAngel.Relay.Off(Port1);

//ATO Protection
if (ReefAngel.LowATO.IsActive())
ReefAngel.Relay.On(Port4);
else
ReefAngel.Relay.Off(Port4);

//Kalk Dose 60sec @ 11pm-12pm (every 15min)
if (hour() >=23 || hour() < 12)
ReefAngel.Relay.Set(Port4, now()%900<60);
else
ReefAngel.Relay.Off(Port4);

//Kalk Stir 12pm-1pm
if (hour() >=12 & hour() < 13)
ReefAngel.Relay.On(Port5);
else
ReefAngel.Relay.Off(Port5);

ReefAngel.DCPump.UseMemory = true;
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = AntiSync;
////// Place your custom code below here

///// Place your custom code below here

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// Add Else Mode definition..
const int Else=16;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { Lagoon, Else, ReefCrest, TidalSwell, ShortPulse, LongPulse, NutrientTransport };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<900) { 
  // First 15 minutes after feeding mode stops. Return Pump is off
  ReefAngel.Relay.Off(Port1);
  // First 15 minutes after feeding mode stops. Smart_NTM
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()-feeding<4500) { // 15 minutes plus 1 hour
  // Continue NTM for the next 60 minutes (75 minutes total)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<30600 || now()%SECS_PER_DAY>=81000) { // 8:30am / 10:30pm
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=Constant;
  ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  if (rmode==Else) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Mode=Constant;
    ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),25,true );    // ElseMode on sync mode, Portal Speed Setting +/- 25%
  } else {
    ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
  }
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}

////// Place your custom code above here

// This should always be the last line
ReefAngel.Portal( "paulturner911" );
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, 43, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 43, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();

// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 84, TempRelay );
pingSerial();

// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}

void DrawCustomGraph()
{
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis();        // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000);           // Set the initial delay
  static int NewSpeed = MidPoint;                  // Set the initial speed
  static int AntiSpeed = MidPoint;                 // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay)               // Check if the delay has elapsed
  {
    Delay=random(500,5000);                        // If so, come up with a new delay
    int ChangeUp = random(Offset);                 // Amount to go up or down
    if (random(100)<50)                            // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis();                           // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: PaulTurner911 Code

Post by lnevo »

Change this line

Code: Select all

  if (rmode==Else) {
to

Code: Select all

  if (modes[rmode]==Else) {
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Thanks
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Current code below. I am having an issue with the 2 DC pumps, sometimes the screen on the controller shows values but the pumps arent working. Its random, maybe an issue with else mode?
How can I activate else mode to see?

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>

////// 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 = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port6Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port2Bit | Port3Bit | Port7Bit | Port8Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit | Port6Bit | Port7Bit | Port8Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;

// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;


// Ports that are always on

////// Place additional initialization code below here


////// Place additional initialization code above here
}

void loop()
{
ReefAngel.DayLights( Port1 ); // Return Pump
ReefAngel.StandardFan( Port2 ); // Canopy Fans
ReefAngel.ActinicLights( Port3 ); // Actinic LEDS
//Port4 Kalk/ATO
//Port5 Kalk Stir
ReefAngel.DayLights( Port6 );//Port 6 Skimmer
ReefAngel.DayLights( Port7 ); // MH 1
ReefAngel.DayLights( Port8 ); //MH 2
//Moonlight Phase 9pm-10am (CH4-CH5)
if ( (hour() >=10) && (hour() <21) ) 
ReefAngel.PWM.SetChannel( 4,(0) );
else 
ReefAngel.PWM.SetChannel( 4, MoonPhase() );
if ( (hour() >=10) && (hour() <21) ) 
ReefAngel.PWM.SetChannel( 5,(0) );
else
ReefAngel.PWM.SetChannel( 5, MoonPhase() );

//Over Flow Protection
if (ReefAngel.HighATO.IsActive())
ReefAngel.Relay.On(Port1);
else
ReefAngel.Relay.Off(Port1);

//ATO Protection
if (ReefAngel.LowATO.IsActive())
ReefAngel.Relay.On(Port4);
else
ReefAngel.Relay.Off(Port4);

//Kalk Dose 60sec @ 11pm-12pm (every 15min)
if (hour() >=23 || hour() < 12)
ReefAngel.Relay.Set(Port4, now()%900<60);
else
ReefAngel.Relay.Off(Port4);

//Kalk Stir 12pm-1pm
if (hour() >=12 & hour() < 13)
ReefAngel.Relay.On(Port5);
else
ReefAngel.Relay.Off(Port5);

ReefAngel.DCPump.UseMemory = true;
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = AntiSync;
////// Place your custom code below here

///// Place your custom code below here

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// Add Else Mode definition..
const int Else=16;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { Lagoon, Else, ReefCrest, TidalSwell, ShortPulse, LongPulse, NutrientTransport };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<900) { 
  // First 15 minutes after feeding mode stops. Return Pump is off
  ReefAngel.Relay.Off(Port1);
  // First 15 minutes after feeding mode stops. Smart_NTM
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()-feeding<4500) { // 15 minutes plus 1 hour
  // Continue NTM for the next 60 minutes (75 minutes total)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<30600 || now()%SECS_PER_DAY>=81000) { // 8:30am / 10:30pm
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Mode=Constant;
  ReefAngel.DCPump.Speed=30;
} else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  if (modes[rmode]==Else) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Mode=Constant;
    ReefAngel.DCPump.Speed=ElseMode(InternalMemory.DCPumpSpeed_read(),25,true );    // ElseMode on sync mode, Portal Speed Setting +/- 25%
  } else {
    ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
  }
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}

////// Place your custom code above here

// This should always be the last line
ReefAngel.Portal( "paulturner911" );
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, 43, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 43, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();

// Main Relay Box
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox( 12, 84, TempRelay );
pingSerial();

// Date and Time
ReefAngel.LCD.DrawDate( 6, 122 );
pingSerial();
}

void DrawCustomGraph()
{
}
byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis();        // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000);           // Set the initial delay
  static int NewSpeed = MidPoint;                  // Set the initial speed
  static int AntiSpeed = MidPoint;                 // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay)               // Check if the delay has elapsed
  {
    Delay=random(500,5000);                        // If so, come up with a new delay
    int ChangeUp = random(Offset);                 // Amount to go up or down
    if (random(100)<50)                            // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis();                           // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: PaulTurner911 Code

Post by Sacohen »

Remove everything else from the list of options except else mode and then that will be the one that it chooses.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

I'm not sure how to.
No way to call it from a memory location manually?

Ok, I think I understand.
Thanks
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: PaulTurner911 Code

Post by Sacohen »

Change this...

Code: Select all

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { Lagoon, Else, ReefCrest, TidalSwell, ShortPulse, LongPulse, NutrientTransport };

To this...

Code: Select all

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { Else };
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: PaulTurner911 Code

Post by lnevo »

+1
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Could someone refresh my memory on how to have Relay 6 run constant, unless Im in feed mode?

I didnt realize it but when I added the skimmer it runs on the same schedule as my MH lamps. I would like it to be on all of the time unless its in feed mode.
Any help is greatly apprerciated.

Thank you
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: PaulTurner911 Code

Post by Sacohen »

You need 2 things....

This in // Ports toggled in Feeding Mode

Code: Select all

ReefAngel.FeedingModePorts = Port6Bit;
And then in // Ports that are always on

Code: Select all

ReefAngel.Relay.On( Port6 );
If you want to delay the start after feeding mode by 10 min so your main pump gets up to speed and your water leve gets back to normal you can add this in the loop section...

Code: Select all

ReefAngel.Relay.DelayedOn( Port6,10 );
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Great! Thank you
Image
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

I HAVE PICKED UP A NEW TANK!!!
Im wondering if I should just run the wizard and start over, but cut and paste some "custom lines" ??? Please advise which would be easier.

Ditching a few things -
MH (port7&8)
FANS (port2)
ACTINIC (port3)

I have a few things that Id like to add-
3 Ecoray112DX whites/red (port7) Actinics (port8)
Chiller (port2) Should function similar to the fan settings? * NEEDS TO SHUT DOWN IN FEED/WATERCHANGE MODES
Skimmer (port3) ** Id like it off for 2 hours after feedmode activation

ANY AND ALL INPUT IS WELCOMED AND VERY APPRECIATED
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: PaulTurner911 Code

Post by Sacohen »

I would keep what you have and go in and manually cut out what you don't want.

Then use the wizard to create the code you want to add and paste it in to your existing code.
Paulturner911
Posts: 288
Joined: Wed Jan 23, 2013 12:36 pm

Re: PaulTurner911 Code

Post by Paulturner911 »

Ill give it a try!! thanks
Image
Post Reply