Page 1 of 1

coding to memory for jebao pumps

Posted: Thu Apr 28, 2016 3:21 pm
by Civics14
How do I code to memory so I can test out different modes, but at the same time be able to revert back to my custom schedule?

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 <PAR.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.PHMin=511;
    ReefAngel.PHMax=760;
    InternalMemory.DCPumpThreshold_write(15);
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port4Bit | Port5Bit | Port6Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port2Bit | Port3Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port7Bit | Port8Bit;
    // Use T3 probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T2_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 835 );

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


    // Ports that are always on
    ReefAngel.Relay.On( Port2 ); //Dimming Module
    ReefAngel.Relay.On( Port4 ); //Jebao DP4
    ReefAngel.Relay.On( Port5 );
    ReefAngel.Relay.On( Port6 );

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

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

void loop()
{
    ReefAngel.StandardHeater( Port1,780,790 );
    ReefAngel.StandardLights( Port3,12,00,22,00 ); // Secondary Pump
    ReefAngel.StandardLights( Port7,0,30,10,30 ); // Fuge Lamp
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = None;
    ReefAngel.DCPump.ExpansionChannel[2] = None;
    ReefAngel.DCPump.ExpansionChannel[3] = None;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
    
    ////// Light Schedule Below
          //Set Channel 0 LED RED
          if (PWMSlope(13,15,22,45,5,85,120,5)<=6) 
          {
            ReefAngel.PWM.SetChannel( 0, 0);
            ReefAngel.PWM.SetChannel( 3, 0);
          }
          else
          {
            ReefAngel.PWM.SetChannel( 0, PWMSlope(13,15,22,45,5,85,120,5) );
            ReefAngel.PWM.SetChannel( 3, PWMSlope(13,15,22,45,5,85,120,5) );
          }
          
          //Set Channel 1 LED WHITE
          if (PWMSlope(13,30,22,30,5,80,120,5)<=6)
          {
            ReefAngel.PWM.SetChannel( 1, 0);
            ReefAngel.PWM.SetChannel( 4, 0);
          }
          else
          {
            ReefAngel.PWM.SetChannel( 1, PWMSlope(13,30,22,30,5,80,120,5) );
            ReefAngel.PWM.SetChannel( 4, PWMSlope(13,30,22,30,5,80,120,5) );
          }
          
          //Set Channel 2 LED BLUE
          if (PWMSlope(13,0,23,0,5,100,120,5)<=6)
          {
            ReefAngel.PWM.SetChannel( 2,0);
            ReefAngel.PWM.SetChannel( 5,0);
          }
          else
          {
            ReefAngel.PWM.SetChannel( 2, PWMSlope(13,0,23,0,5,100,120,5) );
            ReefAngel.PWM.SetChannel( 5, PWMSlope(13,0,23,0,5,100,120,5) );
          }
   ////// End of Light Schedule
      
  //Setting Jebao Pump Wave Patterns
  if (hour()>=12 && hour()<13 ) // Morning mode between 12pm and 1pm
  {
    ReefAngel.DCPump.SetMode(ReefCrest,40,20 );
  }
     else if (hour()>=13 && hour()<15) // Day mode between 1m and 3pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,50,25 );  
  }
     else if (hour()>=15 && hour()<20) // Day mode between 3pm and 8pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,75,25 );  
  }
     else if (hour()>=20 && hour()<21) // Evening mode between 8pm and 9pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,60,15 );
  }
     else if (hour()>=21 && hour()<23) //Calming beween 9pm and 11pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,40,20 );  
  }
     else
  {
    ReefAngel.DCPump.SetMode( ReefCrest,40,10 );  // Night Mode between 11pm and l2pm
  }
    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.DaylightChannel = Sync;
    ReefAngel.DCPump.ActinicChannel = AntiSync; //use None when inactivated
    
    ////// Place your custom code above here

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


Re: coding to memory for jebao pumps

Posted: Fri Apr 29, 2016 4:53 am
by cosmith71
Try this. Go to the portal and set it to "Custom" to run your schedule. Otherwise, it will run whatever mode you select.

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 <PAR.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.PHMin=511;
    ReefAngel.PHMax=760;
    InternalMemory.DCPumpThreshold_write(15);
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port4Bit | Port5Bit | Port6Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port2Bit | Port3Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port7Bit | Port8Bit;
    // Use T3 probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T2_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 835 );

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


    // Ports that are always on
    ReefAngel.Relay.On( Port2 ); //Dimming Module
    ReefAngel.Relay.On( Port4 ); //Jebao DP4
    ReefAngel.Relay.On( Port5 );
    ReefAngel.Relay.On( Port6 );

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

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

void loop()
{
    ReefAngel.StandardHeater( Port1,780,790 );
    ReefAngel.StandardLights( Port3,12,00,22,00 ); // Secondary Pump
    ReefAngel.StandardLights( Port7,0,30,10,30 ); // Fuge Lamp
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = None;
    ReefAngel.DCPump.ExpansionChannel[2] = None;
    ReefAngel.DCPump.ExpansionChannel[3] = None;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
    
    ////// Light Schedule Below
          //Set Channel 0 LED RED
          if (PWMSlope(13,15,22,45,5,85,120,5)<=6) 
          {
            ReefAngel.PWM.SetChannel( 0, 0);
            ReefAngel.PWM.SetChannel( 3, 0);
          }
          else
          {
            ReefAngel.PWM.SetChannel( 0, PWMSlope(13,15,22,45,5,85,120,5) );
            ReefAngel.PWM.SetChannel( 3, PWMSlope(13,15,22,45,5,85,120,5) );
          }
          
          //Set Channel 1 LED WHITE
          if (PWMSlope(13,30,22,30,5,80,120,5)<=6)
          {
            ReefAngel.PWM.SetChannel( 1, 0);
            ReefAngel.PWM.SetChannel( 4, 0);
          }
          else
          {
            ReefAngel.PWM.SetChannel( 1, PWMSlope(13,30,22,30,5,80,120,5) );
            ReefAngel.PWM.SetChannel( 4, PWMSlope(13,30,22,30,5,80,120,5) );
          }
          
          //Set Channel 2 LED BLUE
          if (PWMSlope(13,0,23,0,5,100,120,5)<=6)
          {
            ReefAngel.PWM.SetChannel( 2,0);
            ReefAngel.PWM.SetChannel( 5,0);
          }
          else
          {
            ReefAngel.PWM.SetChannel( 2, PWMSlope(13,0,23,0,5,100,120,5) );
            ReefAngel.PWM.SetChannel( 5, PWMSlope(13,0,23,0,5,100,120,5) );
          }
   ////// End of Light Schedule
      
  //Setting Jebao Pump Wave Patterns
  if (InternalMemory.DCPumpMode_read()==11)   // If custom mode on Portal
{
  ReefAngel.DCPump.UseMemory = false;
  if (hour()>=12 && hour()<13 ) // Morning mode between 12pm and 1pm
  {
    ReefAngel.DCPump.SetMode(ReefCrest,40,20 );
  }
     else if (hour()>=13 && hour()<15) // Day mode between 1m and 3pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,50,25 );  
  }
     else if (hour()>=15 && hour()<20) // Day mode between 3pm and 8pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,75,25 );  
  }
     else if (hour()>=20 && hour()<21) // Evening mode between 8pm and 9pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,60,15 );
  }
     else if (hour()>=21 && hour()<23) //Calming beween 9pm and 11pm
  {
    ReefAngel.DCPump.SetMode( ReefCrest,40,20 );  
  }
     else
  {
    ReefAngel.DCPump.SetMode( ReefCrest,40,10 );  // Night Mode between 11pm and l2pm
  }
}  
  else ReefAngel.DCPump.UseMemory = true;    //  If it's not custom mode on the portal, then do what mode the portal says.

    ReefAngel.DCPump.DaylightChannel = Sync;
    ReefAngel.DCPump.ActinicChannel = AntiSync; //use None when inactivated
    
    ////// Place your custom code above here

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

Re: coding to memory for jebao pumps

Posted: Fri Apr 29, 2016 6:01 am
by Civics14
I'll try when I get home. Thanks as always.

Re: coding to memory for jebao pumps

Posted: Sat Apr 30, 2016 5:53 am
by Civics14
That didn't work, any other suggestions? It stayed on internal memory

Re: coding to memory for jebao pumps

Posted: Sat Apr 30, 2016 5:56 am
by cosmith71
Oops, forgot a line. I edited the post above. It should work now.

Re: coding to memory for jebao pumps

Posted: Sat Apr 30, 2016 6:01 am
by cosmith71
Here's the exact code I use, for future reference.

Code: Select all

void PumpControl()
{
  // *******************  Pump Control *******************

  if (InternalMemory.DCPumpMode_read()==11)   // If custom mode on Portal
  {
    ReefAngel.DCPump.UseMemory = false;    // Turn off memory control
    ReefAngel.DCPump.SetMode(Else,60,30);  // If nothing changes it in the next few lines, this is what runs.
    ReefAngel.DCPump.Threshold=20;  
    if (hour()>=22 || hour()<9) ReefAngel.DCPump.SetMode(Gyre,80,30,50);  // Gyre max, duration, minimum
    if (hour()>=9 && hour()<10) ReefAngel.DCPump.SetMode(Gyre,90,30,60);  // Gyre max, duration, minimum
    if (hour()>=10 && hour()<11)
    {
      ReefAngel.DCPump.Threshold=20;
      ReefAngel.DCPump.SetMode(Else,40,20);    // Else mode from 1000 to 1100.  Wake up!
    }
  }
  else ReefAngel.DCPump.UseMemory = true;    //  If it's not custom mode on the portal, then do what mode the portal says.
}

Re: coding to memory for jebao pumps

Posted: Sat Apr 30, 2016 7:50 am
by Civics14
i think that did the trick. just to confirm, when i select custom, i'm assuming after it goes through the loop, it changes the selection based on the programming and it no longer is "custom" per say.

Re: coding to memory for jebao pumps

Posted: Sat Apr 30, 2016 4:52 pm
by cosmith71
It will run whatever mode is selected on the portal. If you set it to "custom" on the portal then it will run what is programmed in your code. So, for everyday use, leave it on custom. If you want to try a different waveform, then set it to whatever wave you want.

Re: coding to memory for jebao pumps

Posted: Sun May 01, 2016 9:40 am
by Civics14
Thank you very much. Every thing works!!

Re: coding to memory for jebao pumps

Posted: Sun May 01, 2016 9:47 am
by cosmith71
You're welcome!

Re: coding to memory for jebao pumps

Posted: Sun May 01, 2016 11:21 am
by saf1
Cosmith71 - Is that a standard feature of using ReefAngel.DCPump.UseMemory = true or your custom code block?

If that is a feature of setting use memory to true that is slick.

Re: coding to memory for jebao pumps

Posted: Sun May 01, 2016 12:16 pm
by cosmith71
Yep, assuming you have your ports set to sync or antisync, then setting UseMemory to true will do what the portal (or the app) tells it to.