Page 1 of 2

Pump Schedule for WP-25

Posted: Sun Mar 30, 2014 5:42 pm
by howaboutme
I finally got my wp-25 started w/ the help of lnevo and now I am trying my hand at scheduling the pump modes. Lee helped me w/ my initial code here:

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
        ReefAngel.Use2014Screen();  // Let's use 2014 Screen
        // Ports toggled in Feeding Mode
        ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port6Bit;
        // Ports toggled in Water Change Mode
        ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port5Bit | Port6Bit | Port7Bit;
        // Ports toggled when Lights On / Off menu entry selected
        ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
        // 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;

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

        // Ports that are always on
        ReefAngel.Relay.On( Port2 );
        ReefAngel.Relay.On( Port5 );

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

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

    void loop()
    {
        ReefAngel.DayLights( Port3 );
        ReefAngel.ActinicLights( Port4 );
        ReefAngel.StandardHeater( Port7 );
        ReefAngel.DCPump.UseMemory = true;
        ReefAngel.DCPump.DaylightChannel = None;
        ReefAngel.DCPump.ActinicChannel = Sync;
        ////// Place your custom code below here
       
        if (ReefAngel.DCPump.Mode==Custom) {
          ReefAngel.PWM.SetActinic( ElseMode(ReefAngel.DCPump.Speed,ReefAngel.DCPump.Duration,true));                     // ElseMode on sync mode, 35 +/- 5%
        }
       
        ////// Place your custom code above here

        // This should always be the last line
        ReefAngel.Portal( "howaboutme" );
        ReefAngel.ShowInterface();
    }


    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;
      }
    }
Now I want to add a schedule to my pumps. I want to run constant mode of 30% between the hours of 10pm and 1pm. From 1pm to 10pm, I want to run the else mode code at 35% +/- 5%. Please note that the power for the pumps are preliminary and I will be adjusting them as I play and fine tune the pump for my setup.

For the code below, I have assumed that in order to run a schedule, the pump code has to be hard coded. The code Lee (or you if you're reading :D ) helped me w/ utilizes the portal settings to adjust the speed and the fluctuation of else mode. I am okay w/ this being hard coded in since once I have it tuned, I won't be messing with it anymore. Here's the code that I came up w/ thanks to some research and copy/pasting.

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
        ReefAngel.Use2014Screen();  // Let's use 2014 Screen
        // Ports toggled in Feeding Mode
        ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port6Bit;
        // Ports toggled in Water Change Mode
        ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port5Bit | Port6Bit | Port7Bit;
        // Ports toggled when Lights On / Off menu entry selected
        ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
        // 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;

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

        // Ports that are always on
        ReefAngel.Relay.On( Port2 );
        ReefAngel.Relay.On( Port5 );

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

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

    void loop()
    {
        ReefAngel.DayLights( Port3 );
        ReefAngel.ActinicLights( Port4 );
        ReefAngel.StandardHeater( Port7 );
        ReefAngel.DCPump.UseMemory = true;
        ReefAngel.DCPump.DaylightChannel = None;
        ReefAngel.DCPump.ActinicChannel = Sync;
        ////// Place your custom code below here
       
       if (hour()>=22 && hour()<13)
{
  ReefAngel.PWM.SetActinic( ConstantMode(30,true) ); // Constant at 30% on sync mode
}
      else if (hour()>=13 && hour()<22)
{
        ReefAngel.PWM.SetActinic( ElseMode(34,5,true));                     // ElseMode on sync mode, 35 +/- 5%
}      
        ////// Place your custom code above here

        // This should always be the last line
        ReefAngel.Portal( "howaboutme" );
        ReefAngel.ShowInterface();
    }


    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;
      }
    }
Am I close?

Re: Pump Schedule for WP-25

Posted: Sun Mar 30, 2014 6:09 pm
by lnevo
You still want to check if your in "custom mode" like i had so that you can override if you decide and also because you have UseMemory=true which will apply the memory settings if you are on a different mode.

Re: Pump Schedule for WP-25

Posted: Sun Mar 30, 2014 6:29 pm
by howaboutme
I thought that if I removed this line:

Code: Select all

 if (ReefAngel.DCPump.Mode==Custom) {
          ReefAngel.PWM.SetActinic( ElseMode(ReefAngel.DCPump.Speed,ReefAngel.DCPump.Duration,true)
And replaced it with this line:

Code: Select all

ReefAngel.PWM.SetActinic( ElseMode(34,5,true)
That removed it from being in "custom" mode and disables my ability to change settings via the portal.

So it looks like I have removed this too in order to have my settings 100% hard coded in?

Code: Select all

ReefAngel.DCPump.UseMemory = true;
I am ok w/ not being able to mess w/ it via the portal but is that not recommended? Doesn't using the portal to override the internal memory defeat the fact that I want to set my pump according to time?

Thanks.

Re: Pump Schedule for WP-25

Posted: Sun Mar 30, 2014 7:08 pm
by lnevo
Just so you have the option :)

Re: Pump Schedule for WP-25

Posted: Mon Mar 31, 2014 4:30 am
by howaboutme
Ok Lee..you're right. Options are good. I mean, that's why we have a Reef Angel, right? In order to keep the option in the portal, will the code look like this?

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
            ReefAngel.Use2014Screen();  // Let's use 2014 Screen
            // Ports toggled in Feeding Mode
            ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port6Bit;
            // Ports toggled in Water Change Mode
            ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port5Bit | Port6Bit | Port7Bit;
            // Ports toggled when Lights On / Off menu entry selected
            ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
            // 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;

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

            // Ports that are always on
            ReefAngel.Relay.On( Port2 );
            ReefAngel.Relay.On( Port5 );

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

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

        void loop()
        {
            ReefAngel.DayLights( Port3 );
            ReefAngel.ActinicLights( Port4 );
            ReefAngel.StandardHeater( Port7 );
            ReefAngel.DCPump.UseMemory = true;
            ReefAngel.DCPump.DaylightChannel = None;
            ReefAngel.DCPump.ActinicChannel = Sync;
            ////// Place your custom code below here
           
if (ReefAngel.DCPump.Mode==Custom)
           if (hour()>=22 && hour()<13)
    {
      ReefAngel.PWM.SetActinic( ConstantMode(30,true) ); // Constant at 30% on sync mode
    }
          else if (hour()>=13 && hour()<22)
       {
          ReefAngel.PWM.SetActinic( ElseMode(ReefAngel.DCPump.Speed,ReefAngel.DCPump.Duration,true)
    }     
            ////// Place your custom code above here

            // This should always be the last line
            ReefAngel.Portal( "howaboutme" );
            ReefAngel.ShowInterface();
        }


        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;
          }
        }
My big question (amongst others I am not aware of..) is where to put this:

Code: Select all

if (ReefAngel.DCPump.Mode==Custom)
I put it above everything since I only want the schedule when I am in custom mode. Did I make the assumption correct?

Thanks!

Re: Pump Schedule for WP-25

Posted: Mon Mar 31, 2014 7:57 am
by lnevo
Yes, exactly, however you need { } around the entire thing your iffing with that statement.

Re: Pump Schedule for WP-25

Posted: Mon Mar 31, 2014 9:05 am
by howaboutme
Wow! I'm excited that I got close. :)

Another question, does the schedule have to be on the hour? I have only seen a few examples of this and all have been on the hour as opposed to on the half our or minutes.

How would I add minutes to this code?

Code: Select all

if (hour()>=22 && hour()<13)
Thanks!

Re: Pump Schedule for WP-25

Posted: Mon Mar 31, 2014 11:42 am
by lnevo
If you want to add minutes to your code, it's best to change the test to seconds...

Essentially to get the current time of the day in seconds you would do this

Code: Select all

now()%SECS_PER_DAY
So if you wanted to see if it were 10:30pm (22 hours * 60 minutes * 60 seconds + 30 minutes * 60 seconds) You would do this:

Code: Select all

if (now()%SECS_PER_DAY == (22*60*60)+(30*60)) 
which could be simplified to

Code: Select all

if (now()%SECS_PER_DAY == 81000)
if you wanted it to be between 10:30 and 10:45 let's say

Code: Select all

if ( (now()%SECS_PER_DAY >= 81000) && (now()%SECS_PER_DAY<= 81900) )

Re: Pump Schedule for WP-25

Posted: Mon Mar 31, 2014 12:36 pm
by howaboutme
Thanks! I will give it shot and report back.

Re: Pump Schedule for WP-25

Posted: Tue Apr 01, 2014 5:16 pm
by howaboutme
Ok, I tried to compile the code and it gave me an error. The error was "'ConstantMode' was not declared in this scope".

My code is:

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
        ReefAngel.Use2014Screen();  // Let's use 2014 Screen
        // Ports toggled in Feeding Mode
        ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port6Bit;
        // Ports toggled in Water Change Mode
        ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port5Bit | Port6Bit | Port7Bit;
        // Ports toggled when Lights On / Off menu entry selected
        ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
        // 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;

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

        // Ports that are always on
        ReefAngel.Relay.On( Port2 );
        ReefAngel.Relay.On( Port5 );

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

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

    void loop()
    {
        ReefAngel.DayLights( Port3 );
        ReefAngel.ActinicLights( Port4 );
        ReefAngel.StandardHeater( Port7 );
        ReefAngel.DCPump.UseMemory = true;
        ReefAngel.DCPump.DaylightChannel = None;
        ReefAngel.DCPump.ActinicChannel = Sync;
        ////// Place your custom code below here
      { 
           if ( (now()%SECS_PER_DAY >= 77400) && (now()%SECS_PER_DAY<= 48600) )
{
  ReefAngel.PWM.SetActinic( ConstantMode(30,true) ); // Constant at 30% on sync mode
}
      else if ( (now()%SECS_PER_DAY >= 48600) && (now()%SECS_PER_DAY<= 77400) )
{
        ReefAngel.PWM.SetActinic( ElseMode(36,6,true));                     // ElseMode on sync mode, 36 +/- 6%
}      
        ////// Place your custom code above here

        // This should always be the last line
        ReefAngel.Portal( "howaboutme" );
        ReefAngel.ShowInterface();
    }
    }

    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;
      }
    }
Did I miss something?

I just want constant mode to run from 9:30pm to 1:30pm. Every other time is the else mode as set from the portal.

Thank you.

Re: Pump Schedule for WP-25

Posted: Tue Apr 01, 2014 5:42 pm
by lnevo
There is no constantmode function...just set the pwm channel to the speed you want no function required...

ReefAngel.PWM.SetDaylight(30);

Re: Pump Schedule for WP-25

Posted: Tue Apr 01, 2014 5:53 pm
by howaboutme
Ah..duh! Sorry..Makes sense now. It compiled and uploaded fine. I will check reeftronics later on to see if it's following the schedule.

Thank you!...more to come. :)

Re: Pump Schedule for WP-25

Posted: Tue Apr 01, 2014 6:40 pm
by howaboutme
Ok, so I think the schedule did kick in but the power is at 39%, not the 30% I set the code at. Thoughts?

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
        ReefAngel.Use2014Screen();  // Let's use 2014 Screen
        // Ports toggled in Feeding Mode
        ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port6Bit;
        // Ports toggled in Water Change Mode
        ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port5Bit | Port6Bit | Port7Bit;
        // Ports toggled when Lights On / Off menu entry selected
        ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
        // 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;

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

        // Ports that are always on
        ReefAngel.Relay.On( Port2 );
        ReefAngel.Relay.On( Port5 );

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

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

    void loop()
    {
        ReefAngel.DayLights( Port3 );
        ReefAngel.ActinicLights( Port4 );
        ReefAngel.StandardHeater( Port7 );
        ReefAngel.DCPump.UseMemory = true;
        ReefAngel.DCPump.DaylightChannel = None;
        ReefAngel.DCPump.ActinicChannel = Sync;
        ////// Place your custom code below here
      { 
           if ( (now()%SECS_PER_DAY >= 77400) && (now()%SECS_PER_DAY<= 48600) )
{
  ReefAngel.PWM.SetActinic(30); // Constant at 30% on sync mode
}
      else if ( (now()%SECS_PER_DAY >= 48600) && (now()%SECS_PER_DAY<= 77400) )
{
        ReefAngel.PWM.SetActinic( ElseMode(36,6,true));                     // ElseMode on sync mode, 36 +/- 6%
}      
        ////// Place your custom code above here

        // This should always be the last line
        ReefAngel.Portal( "howaboutme" );
        ReefAngel.ShowInterface();
    }
    }

    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;
      }
    }

Re: Pump Schedule for WP-25

Posted: Tue Apr 01, 2014 6:54 pm
by howaboutme
Ok, it might be working now. I think I had to force it to custom mode in the portal even though it was already set to custom. Will have to monitor and check on the other end to see if it goes into else mode tomorrow.

Pump Schedule for WP-25

Posted: Tue Apr 01, 2014 7:34 pm
by lnevo
Something is wrong with the braces and your missing the check if mode is custom

Im also on the phone so i may not be getting right data. Will take a look later.

Re: Pump Schedule for WP-25

Posted: Wed Apr 02, 2014 5:23 am
by howaboutme
lnevo wrote:Something is wrong with the braces and your missing the check if mode is custom

Im also on the phone so i may not be getting right data. Will take a look later.
Ok, thank you. Let me know what is wrong w/ the code.

As of now, it's on constant mode at 30% as it should. We'll see what will happen at 1:30pm. Like i said, I had to set it to custom mode via the portal to get it this way even though it was already in custom mode. The 39% is mysterious though. I see nothing mathematically that can tell the controller to run the pump at 39%.

Re: Pump Schedule for WP-25

Posted: Wed Apr 02, 2014 6:08 am
by lnevo
This is what the statement should look like

Code: Select all

        
       if (ReefAngel.DCPump.Mode==Custom) 
        { 
          if ( (now()%SECS_PER_DAY >= 77400) || (now()%SECS_PER_DAY<= 48600) )
          {
            ReefAngel.PWM.SetActinic(30); // Constant at 30% on sync mode
          }
          else if ( (now()%SECS_PER_DAY >= 48600) && (now()%SECS_PER_DAY<= 77400) )
          {
            ReefAngel.PWM.SetActinic( ElseMode(36,6,true));   // Else on sync mode, 36 +/- 6%
          }
        }      
I added back the check to make sure we are in custom mode and I changed the first statement from && to || (AND to OR). You cannot have a time that is both later than 9:30pm AND earlier than 1:30pm. The last brace was also surrounding the Portal and ShowInterface functions which could mess up a lot of stuff.

Here, try this full code

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
        ReefAngel.Use2014Screen();  // Let's use 2014 Screen
        // Ports toggled in Feeding Mode
        ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port6Bit;
        // Ports toggled in Water Change Mode
        ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port5Bit | Port6Bit | Port7Bit;
        // Ports toggled when Lights On / Off menu entry selected
        ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
        // 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;

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

        // Ports that are always on
        ReefAngel.Relay.On( Port2 );
        ReefAngel.Relay.On( Port5 );

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

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

    void loop()
    {
        ReefAngel.DayLights( Port3 );
        ReefAngel.ActinicLights( Port4 );
        ReefAngel.StandardHeater( Port7 );
        ReefAngel.DCPump.UseMemory = true;
        ReefAngel.DCPump.DaylightChannel = None;
        ReefAngel.DCPump.ActinicChannel = Sync;
        ////// Place your custom code below here
        if (ReefAngel.DCPump.Mode==Custom) 
        { 
          if ( (now()%SECS_PER_DAY >= 77400) || (now()%SECS_PER_DAY<= 48600) )
          {
            ReefAngel.PWM.SetActinic(30); // Constant at 30% on sync mode
          }
          else if ( (now()%SECS_PER_DAY >= 48600) && (now()%SECS_PER_DAY<= 77400) )
          {
            ReefAngel.PWM.SetActinic( ElseMode(36,6,true));   // Else on sync mode, 36 +/- 6%
          }
        }      
        ////// Place your custom code above here

        // This should always be the last line
        ReefAngel.Portal( "howaboutme" );
        ReefAngel.ShowInterface();
   }

    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;
      }
    }

Re: Pump Schedule for WP-25

Posted: Wed Apr 02, 2014 6:24 am
by howaboutme
Oh, I see. Thank you.

Question. What do you think will happen w/ the pump as it stands now? I can't modify the code until tonight so I am a bit concerned about what will happen at 1:30pm. Do you think it will do what is planned anyways? My setting for the dc pump is under custom, 36 speed, 6 duration, just like the code and it is currently in constant mode at 30.

I'm wondering if I should just change the settings to constant @ 30% instead of custom to be safe. Thanks!

Re: Pump Schedule for WP-25

Posted: Wed Apr 02, 2014 7:36 am
by lnevo
You can do that but i think it will run the elsemode at 1:30

Re: Pump Schedule for WP-25

Posted: Wed Apr 02, 2014 11:41 am
by howaboutme
You're right. It did go to else anyways so it does follow the schedule.

I will adjust the code tonight to get it right. Thanks!

Re: Pump Schedule for WP-25

Posted: Wed Apr 02, 2014 12:43 pm
by lnevo
So what happened was because your time check for the Constant mode was invalid, you would never enter that mode, so by exiting Custom mode and going back into it, you put the DCPump back to some setting and then disabled it again leaving it at whatever speed it got. In this case 39.

Re: Pump Schedule for WP-25

Posted: Wed Apr 02, 2014 5:30 pm
by howaboutme
lnevo wrote:So what happened was because your time check for the Constant mode was invalid, you would never enter that mode, so by exiting Custom mode and going back into it, you put the DCPump back to some setting and then disabled it again leaving it at whatever speed it got. In this case 39.
I see, that makes sense.

I just uploaded the updated code. Everything seems fine. I will wait until 9:30pm for the first schedule to start.

Thanks Lee!

Re: Pump Schedule for WP-25

Posted: Sun Apr 06, 2014 5:00 pm
by howaboutme
Still playing around w/ my wp-25 schedule. I've updated this part of the code to include an additional time frame. Did I do this right by adding the "else if" statement for the middle (the new one) schedule?

Code: Select all

 if (ReefAngel.DCPump.Mode==Custom)
            {
              if ( (now()%SECS_PER_DAY >= 77400) || (now()%SECS_PER_DAY<= 34200) )
              {
                ReefAngel.PWM.SetActinic(30); // Constant at 30% on sync mode
              }
              else if ( (now()%SECS_PER_DAY >= 34200) || (now()%SECS_PER_DAY<= 48600) )
              {
                ReefAngel.PWM.SetActinic(33); // Constant at 33% on sync mode
              }
              else if ( (now()%SECS_PER_DAY >= 48600) && (now()%SECS_PER_DAY<= 77400) )
              {
                ReefAngel.PWM.SetActinic( ElseMode(37,7,true));   // Else on sync mode, 37 +/- 7%
              }
            }  
Thanks in advance!

Re: Pump Schedule for WP-25

Posted: Sun Apr 06, 2014 5:30 pm
by lnevo
Yep worked great. Keep in mind the ifs if will choose the first match.

Re: Pump Schedule for WP-25

Posted: Mon Apr 07, 2014 11:05 am
by howaboutme
Ok, something must be messed up w/ the code I uploaded. The pump did not go into else mode at 1:30pm. Does this have to do w/ your comment above? If so, how do I solve that? Thanks.

Re: Pump Schedule for WP-25

Posted: Mon Apr 07, 2014 11:23 am
by howaboutme
I think I've narrowed it down to whether the last 2 "ifs" need "&&" or "||"....My first guess is that the middle "if" should have "&&" as opposed to what is there now, "||".

Am I close?

Re: Pump Schedule for WP-25

Posted: Mon Apr 07, 2014 11:25 am
by lnevo
Yes, the second one should be &&.

And yes, what I said about the first match applies. Since the second if is an OR statement and the time is greater than 34200 then the second condition is matching. It should an an AND since you want it between those bounds.

Re: Pump Schedule for WP-25

Posted: Mon Apr 07, 2014 11:37 am
by howaboutme
Ok, thanks! I finally understand. I will adjust and re-upload tonight.

Re: Pump Schedule for WP-25

Posted: Mon Apr 07, 2014 12:05 pm
by lnevo
Isn't it great that you have the option of picking reefcrest or another mode and setting your speed manually through the portal until you get home to reupload :)

Re: Pump Schedule for WP-25

Posted: Mon Apr 07, 2014 12:09 pm
by howaboutme
Haha. You're right! It's so great that I totally forgot I had that option. I was going to just let it run until I got home. I just switched to reef crest, which I guess is the closest to else mode.

Love it!