Page 1 of 1

Wavemaker coding question

Posted: Sat Jun 23, 2012 12:26 am
by tpriscu
Hi guys,

So this is the example code for random timed wave makers working opposite of eachother

ReefAngel.WavemakerRandom(Port 25,60);
// Turn Port5 on/off random cycles that lasts from 25 to 60 secs
ReefAngel.Relay.Set(Port6,!ReefAngel.Relay.Status(Port5));
// Turn Port6 on/off on opposite cycle as Port 5

Would it be possible to make the Power heads overlap each other for lets say 5 seconds in between every "wave" , just to cause a little turbulence in the water?


Thanks

Re: Wavemaker coding question

Posted: Sat Jun 23, 2012 8:30 am
by rimai
We can do that, but not with that function.
Do you want it to be random and overlap too?
If so, the logic would be to calculate the random number and activate one port. Put the random number on a timer. When it is 5 seconds from expired timer, you turn the other powerhead and when the timer expires, turn the 1st powerhead. Repeat cycle again.
Does it make sense?

Re: Wavemaker coding question

Posted: Sat Jun 23, 2012 1:06 pm
by tpriscu
I do not need the overlap to be random, ill just stick with five seconds.
I think because im not really familiar with the functions available i cannot envision what this code would look like. Can you give me a hand with it?

Re: Wavemaker coding question

Posted: Sat Jun 23, 2012 8:39 pm
by rimai
I'll try to come up with something tomorrow.

Re: Wavemaker coding question

Posted: Mon Jun 25, 2012 2:13 pm
by rimai
Try this code:

Code: Select all

void MyCustomWM()
{
  static unsigned long nexttoggle=now();
  static boolean state=false;
  int cycle=nexttoggle-now();
  ReefAngel.Relay.Set(Port5,state);
  ReefAngel.Relay.Set(Port6,!ReefAngel.Relay.Status(Port5));
  if (cycle<0)
  {
    nexttoggle+=random(10,20);
    state=!state;
  }
  if (cycle<5)
  {
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
  }
}
You can change the paramenter on the random() function to increase or decrease the cycle.

Re: Wavemaker coding question

Posted: Mon Jun 25, 2012 2:18 pm
by tpriscu
I'll try it tonight.
Thanks Roberto!

Re: Wavemaker coding question

Posted: Thu Jun 28, 2012 6:18 pm
by reefermadness
Really interested in this code. Was just sitting down to see if I could figure something like this out. Does it work?

Re: Wavemaker coding question

Posted: Sun Jul 01, 2012 7:02 pm
by reefermadness
This code is working great. My corals really appreciate the turbulence.

One small problem is that it doesn't work when my tank returns from night mode.

Anybody know how I should fix my code?
    if ( (hour() >= 21) || (hour() <= 8) )
{
  ReefAngel.Relay.On(Port6);
  ReefAngel.Relay.Off(Port5);
}
else
    {
  static unsigned long nexttoggle=now();
  static boolean state=false;
  int cycle=nexttoggle-now();
  ReefAngel.Relay.Set(Port5,state);
  ReefAngel.Relay.Set(Port6,!ReefAngel.Relay.Status(Port5));
  if (cycle<0)
  {
    nexttoggle+=random(40,45);
    state=!state;
  }
  if (cycle<15)
  {
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
  }

Re: Wavemaker coding question

Posted: Sun Jul 01, 2012 7:11 pm
by rimai
Try this:

Code: Select all

    if ( (hour() >= 21) || (hour() <= 8) ) 
{
  ReefAngel.Relay.On(Port6);
  ReefAngel.Relay.Off(Port5);
  nexttoggle=now();
}
else
    {
  static unsigned long nexttoggle=now();
  static boolean state=false;
  int cycle=nexttoggle-now();
  ReefAngel.Relay.Set(Port5,state);
  ReefAngel.Relay.Set(Port6,!ReefAngel.Relay.Status(Port5));
  if (cycle<0)
  {
    nexttoggle+=random(40,45);
    state=!state;
  }
  if (cycle<15)
  {
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
  }

Re: Wavemaker coding question

Posted: Mon Jul 02, 2012 5:16 pm
by reefermadness
It doesn't appear to like that either.


RA06242012fixwave.cpp: In function 'void loop()':
RA06242012fixwave:56: error: 'nexttoggle' was not declared in this scope
RA06242012fixwave:86: error: expected `}' at end of input

Re: Wavemaker coding question

Posted: Mon Jul 02, 2012 6:11 pm
by rimai
You are probably missing one last bracket at the end.
I simply copied what you have posted and I can now see there is one closing bracket missing.

Re: Wavemaker coding question

Posted: Mon Jul 02, 2012 7:28 pm
by reefermadness
I'll try this tomorrow. I also had to change line 5.

Code: Select all

 if ( (hour() >= 21) || (hour() <= 8) ) 
{
  ReefAngel.Relay.On(Port6);
  ReefAngel.Relay.Off(Port5);
  static unsigned long nexttoggle=now();
}
else
    {
  static unsigned long nexttoggle=now();
  static boolean state=false;
  int cycle=nexttoggle-now();
  ReefAngel.Relay.Set(Port5,state);
  ReefAngel.Relay.Set(Port6,!ReefAngel.Relay.Status(Port5));
    
  if (cycle<0)
  {
    nexttoggle+=random(40,45);
    state=!state;
  }
  if (cycle<15)
  {
    ReefAngel.Relay.On(Port5);
    ReefAngel.Relay.On(Port6);
  }}

Re: Wavemaker coding question

Posted: Mon Jul 02, 2012 10:03 pm
by rimai
It won't work if you do like that.
You have to make sure to use the same structure in the 1st post I made.
The declaration of the variable was on top before the if statements.

Re: Wavemaker coding question

Posted: Sun Aug 05, 2012 11:43 am
by JoshSD
I'm trying to use some of this code for the wavemakers, and am finding that after my nighttime period, which is supposed to end at 8am, that port 5 is staying stuck ON. Not continuing to follow its overnight setting which is the WavemakerRandom at 25-30 seconds, but just staying on until I reset the RA somehow, which I am usually doing by disconnecting and reconnecting the wifi adapter.

What do I have wrong? thanks in advance.

// Autogenerated file by RAGen (v1.2.1.158), (03/23/2012 13:51)
// RA_032312_1351.ino
//
// This version designed for v0.9.0 or later

/* The following features are enabled for this File:
// #define DisplayImages
#define VersionMenu
#define DirectTempSensor
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/


#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 <ReefAngel.h>
#include <AI.h>

byte WhiteValue=0;
byte BlueValue=0;
byte RoyalBlueValue=0;

void setup()
{
ReefAngel.Init(); //Initialize controller

ReefAngel.AI.SetPort(highATOPin);

// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port4Bit | Port5Bit | Port6Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port8Bit;

// Ports that are always on
ReefAngel.Relay.On(Port4); //Return pump
ReefAngel.Relay.On(Port8); //Skimmer
ReefAngel.Relay.On(Port2); //AI Sol Blue
}

void loop()
{
// Specific functions


ReefAngel.StandardLights(Port3,20,0,6,0); //Refugium Light
ReefAngel.StandardHeater(Port1,765,775);
ReefAngel.StandardHeater(Port7,785,790);
ReefAngel.Portal("joshSD","*******");


if (hour()>=22 || hour()<=8)
{
ReefAngel.AI.SetChannel(White,0);
ReefAngel.AI.SetChannel(Blue,MoonPhase()*0.05);
ReefAngel.AI.SetChannel(RoyalBlue,MoonPhase()*0.05);
ReefAngel.WavemakerRandom(Port5,25,30);
ReefAngel.Relay.Off(Port6);

// ToDo: change wavemaker statement to
// alternate with random 10 - 20 sec cycle, then sleep 60 sec

}
else
{
ReefAngel.AI.SetChannel(White,PWMParabola(10,0,21,0,3,100,3));
ReefAngel.AI.SetChannel(Blue,PWMParabola(8,0,22,0,3,100,3));
ReefAngel.AI.SetChannel(RoyalBlue,PWMParabola(8,0,22,0,3,100,3));

// ReefAngel.WavemakerRandom(Port5,15,45);
// ReefAngel.WavemakerRandom1(Port6,15,45);
// change to have wavemakers alternate and overlap 5 seconds

{
static unsigned long nexttoggle=now();
static boolean state=false;
int cycle=nexttoggle-now();
ReefAngel.Relay.Set(Port5,state);
ReefAngel.Relay.Set(Port6,!ReefAngel.Relay.Status(Port5));
if (cycle<0)
{
nexttoggle+=random(45,60);
state=!state;
}
if (cycle<5)
{
ReefAngel.Relay.On(Port5);
ReefAngel.Relay.On(Port6);
}
}

}

// PWMParabola(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte oldValue)
// startHour - Hour of the start the slope
// startMinute - Minute of the start the slope
// endHour - Hour of the end of the slope
// endMinute - Minute of the end slope
// startPWM - Beginning PWM value
// endPWM - Ending PWM value
// oldValue - Should be the startPWM value or the existing/current PWM value (ReefAngel.PWM.GetActinicValue() or GetDaylightValue())


ReefAngel.ShowInterface();
}

Re: Wavemaker coding question

Posted: Sun Aug 05, 2012 4:29 pm
by rimai
I think you need nexttoggle=now(); in the night time period.

Re: Wavemaker coding question

Posted: Fri Aug 10, 2012 2:21 pm
by carlii
What do the numbers in :

nexttoggle+=random(40,45);

mean?

Re: Wavemaker coding question

Posted: Fri Aug 10, 2012 2:23 pm
by rimai
It means that the next toggle will be a random number between 40 and 45 seconds.

Re: Wavemaker coding question

Posted: Sun Aug 12, 2012 4:32 pm
by JoshSD
is there a simple way to add a "sleep" timer in between the toggles? So that I can do something like

Wavemaker 1 comes on for random time between X and Y seconds
When that time is complete, there is a delay of Z seconds
Wavemaker 2 comes on for random time between A and B seconds
when complete, delay of Z seconds
etc.

Thanks!

Re: Wavemaker coding question

Posted: Sun Aug 12, 2012 7:18 pm
by rimai
That's what this code was, but instead of having them off for Z seconds, they were on for Z seconds.
You can change the code to off instead of on.