DC wavemaker code check

Basic / Standard Reef Angel hardware
Post Reply
Docstach
Posts: 13
Joined: Sat May 17, 2014 9:52 pm

DC wavemaker code check

Post by Docstach »

Hello, After using the RA+ wizard, I have my two WP40s working pretty well. However, I really want to be able to change programs throughout the day. After reading several threads and using the wizard to generate the bulk of the code I have came up with this. Does it look ok? I wasn't sure if you can have a { inside another { or if I should add a } just before the "////// Place your custom code below here" . Thanks!!! Matt

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


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

void loop()
{
ReefAngel.StandardATO( Port1,7200 );
ReefAngel.StandardLights( Port2,22,0,10,0 );
ReefAngel.StandardLights( Port3,11,0,22,15 );
ReefAngel.StandardLights( Port4,12,0,22,0 );
ReefAngel.StandardHeater( Port7,770,780 );
ReefAngel.DCPump.UseMemory = false;

////// Place your custom code below here
if (hour()>=0 && hour()<10)
{
ReefAngel.PWM.SetDaylight( ElseMode(50,30,true) ); // Else on sync mode
ReefAngel.PWM.SetActinic( ElseMode(50,30,true) ); // Else on sync mode
}
else if (hour()>=10 && hour()<13
{
ReefAngel.PWM.SetDaylight( NutrientTransportMode(77,90,3000,true) ); // Nutrient Transport on sync mode
ReefAngel.PWM.SetActinic( NutrientTransportMode(77,90,3000,true) ); // Nutrient Transport on sync mode
}
else if (hour()>=13 && hour()<22
{
ReefAngel.PWM.SetDaylight( ShortPulseMode(0,80,800,true) ); // Short pulse at 80% with 800ms pulse on sync mode
ReefAngel.PWM.SetActinic( ShortPulseMode(0,80,800,true) ); // Short pulse at 80% with 800ms pulse on sync mode
}
else
{
ReefAngel.DCPump.SetMode( Lagoon,40,70 ); // lagoon at 40% hours 22-24 on sync generated by wizard
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = Sync;
}
////// Place your custom code above here

// This should always be the last line
ReefAngel.ShowInterface();
}
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: DC wavemaker code check

Post by binder »

These 2 lines are missing the closing ).

else if (hour()>=10 && hour()<13
else if (hour()>=13 && hour()<22

You can have nested { (curly braces). You just need to close everything up properly and pair up the left braces or parenthesis with right braces or parenthesis.
The above statements should be closed off like this:
else if (hour()>=10 && hour()<13)
else if (hour()>=13 && hour()<22)

Your code should be:

Code: Select all

void loop()
{
ReefAngel.StandardATO( Port1,7200 );
ReefAngel.StandardLights( Port2,22,0,10,0 );
ReefAngel.StandardLights( Port3,11,0,22,15 );
ReefAngel.StandardLights( Port4,12,0,22,0 );
ReefAngel.StandardHeater( Port7,770,780 );
ReefAngel.DCPump.UseMemory = false;

////// Place your custom code below here
if (hour()>=0 && hour()<10)
{
ReefAngel.PWM.SetDaylight( ElseMode(50,30,true) ); // Else on sync mode
ReefAngel.PWM.SetActinic( ElseMode(50,30,true) ); // Else on sync mode
}
else if (hour()>=10 && hour()<13)
{
ReefAngel.PWM.SetDaylight( NutrientTransportMode(77,90,3000,true) ); // Nutrient Transport on sync mode
ReefAngel.PWM.SetActinic( NutrientTransportMode(77,90,3000,true) ); // Nutrient Transport on sync mode
}
else if (hour()>=13 && hour()<22)
{
ReefAngel.PWM.SetDaylight( ShortPulseMode(0,80,800,true) ); // Short pulse at 80% with 800ms pulse on sync mode
ReefAngel.PWM.SetActinic( ShortPulseMode(0,80,800,true) ); // Short pulse at 80% with 800ms pulse on sync mode
}
else
{
ReefAngel.DCPump.SetMode( Lagoon,40,70 ); // lagoon at 40% hours 22-24 on sync generated by wizard
ReefAngel.DCPump.DaylightChannel = Sync;
ReefAngel.DCPump.ActinicChannel = Sync;
}
////// Place your custom code above here

// This should always be the last line
ReefAngel.ShowInterface();
}
I read the code as from midnight to 10a, do one thing, then from 10a to 1p, do another thing, then from 1p to 10p, do another thing and then from 10p to midnight, do something else.
I did not confirm the commands for the daylight but everything looks syntactically correct. Maybe others will chime in on the correctness of the code.
Otherwise, it looks like you are on the right start except for those 2 missing right parenthesis that I corrected for you.
Docstach
Posts: 13
Joined: Sat May 17, 2014 9:52 pm

Re: DC wavemaker code check

Post by Docstach »

Thanks! You read it how I was hoping it would go. The pumps are moving. I don't know if they are doing what I want them to but they are moving :)

Matt
Docstach
Posts: 13
Joined: Sat May 17, 2014 9:52 pm

Re: DC wavemaker code check

Post by Docstach »

OK, so after I uploaded the program is seemed to run through everything great the first day, but then just seemed to stay on the last stage and not start over again the next day. Any Idea? Instead of just an else at the end to I need to specify the specific time? Here is the full code I used.

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.AddStandardMenu();  // Add Standard Menu

    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port5Bit | Port6Bit | Port8Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port2Bit | Port3Bit | Port4Bit | Port7Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 850 );

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


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

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

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

void loop()
{
    ReefAngel.StandardATO( Port1,7200 );
    ReefAngel.StandardLights( Port2,22,0,10,0 );
    ReefAngel.StandardLights( Port3,11,0,22,15 );
    ReefAngel.StandardLights( Port4,12,0,22,0 );
    ReefAngel.StandardHeater( Port7,770,780 );
    ReefAngel.DCPump.UseMemory = false;
    
    ////// Place your custom code below here
    
    if (hour()>=0 && hour()<5)
{
  ReefAngel.PWM.SetDaylight( ElseMode(40,20,true) ); // Else on sync mode
  ReefAngel.PWM.SetActinic( ElseMode(40,20,false) ); // Else on anti-sync mode
}
else if (hour()>=5 && hour()<10)
{
  ReefAngel.PWM.SetDaylight( ElseMode(50,30,true) ); // Else on sync mode
  ReefAngel.PWM.SetActinic( ElseMode(50,30,false) ); // Else on anti-sync mode
}
else if (hour()>=10 && hour()<13)
{
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(77,90,3000,true) ); // Nutrient Transport on sync mode
  ReefAngel.PWM.SetActinic( NutrientTransportMode(77,90,3000,true) ); //   Nutrient Transport on sync mode
}
else if (hour()>=13 && hour()<22)
{
  ReefAngel.PWM.SetDaylight( ShortPulseMode(0,90,800,true) ); // Short pulse at 90% with 800ms pulse on sync mode
  ReefAngel.PWM.SetActinic( ShortPulseMode(0,90,800,true) ); // Short pulse at 90% with 800ms pulse on sync mode
}
else
{
  ReefAngel.DCPump.SetMode( Lagoon,40,70 ); // lagoon at 40% hours 22-24 on sync
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = Sync;
}


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

    // This should always be the last line
    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;
  }
}
    
Docstach
Posts: 13
Joined: Sat May 17, 2014 9:52 pm

Re: DC wavemaker code check

Post by Docstach »

Still can't get it figured out. It will run through the program but not repeat the next day. Any one have any ideas. Thanks!
howaboutme
Posts: 245
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: DC wavemaker code check

Post by howaboutme »

Try changing this:

Code: Select all

if (hour()>=0 && hour()<5)
to this:

Code: Select all

if (hour()>=0 || hour()<5)
I have similar code if you click on my link below.
Jack
Post Reply