Pump Schedule for WP-25

Do you have a question on how to do something.
Ask in here.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Pump Schedule for WP-25

Post 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?
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post 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.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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.
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post by lnevo »

Just so you have the option :)
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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!
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post by lnevo »

Yes, exactly, however you need { } around the entire thing your iffing with that statement.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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!
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post 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) )
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post by howaboutme »

Thanks! I will give it shot and report back.
Jack
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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.
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post by lnevo »

There is no constantmode function...just set the pwm channel to the speed you want no function required...

ReefAngel.PWM.SetDaylight(30);
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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. :)
Jack
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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;
      }
    }
Jack
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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.
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Pump Schedule for WP-25

Post 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.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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%.
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post 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;
      }
    }
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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!
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post by lnevo »

You can do that but i think it will run the elsemode at 1:30
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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!
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post 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.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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!
Jack
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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!
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post by lnevo »

Yep worked great. Keep in mind the ifs if will choose the first match.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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.
Jack
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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?
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post 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.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post by howaboutme »

Ok, thanks! I finally understand. I will adjust and re-upload tonight.
Jack
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Pump Schedule for WP-25

Post 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 :)
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Pump Schedule for WP-25

Post 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!
Jack
Post Reply