Wavemaker coding question

Do you have a question on how to do something.
Ask in here.
Post Reply
tpriscu
Posts: 11
Joined: Fri Jun 01, 2012 7:59 am

Wavemaker coding question

Post 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
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post 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?
Roberto.
tpriscu
Posts: 11
Joined: Fri Jun 01, 2012 7:59 am

Re: Wavemaker coding question

Post 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?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post by rimai »

I'll try to come up with something tomorrow.
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post 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.
Roberto.
tpriscu
Posts: 11
Joined: Fri Jun 01, 2012 7:59 am

Re: Wavemaker coding question

Post by tpriscu »

I'll try it tonight.
Thanks Roberto!
reefermadness
Posts: 5
Joined: Fri Apr 13, 2012 5:41 pm

Re: Wavemaker coding question

Post by reefermadness »

Really interested in this code. Was just sitting down to see if I could figure something like this out. Does it work?
reefermadness
Posts: 5
Joined: Fri Apr 13, 2012 5:41 pm

Re: Wavemaker coding question

Post 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);
  }
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post 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);
  }
Roberto.
reefermadness
Posts: 5
Joined: Fri Apr 13, 2012 5:41 pm

Re: Wavemaker coding question

Post 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
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post 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.
Roberto.
reefermadness
Posts: 5
Joined: Fri Apr 13, 2012 5:41 pm

Re: Wavemaker coding question

Post 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);
  }}
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post 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.
Roberto.
JoshSD
Posts: 37
Joined: Sun Dec 04, 2011 3:19 pm

Re: Wavemaker coding question

Post 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();
}
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post by rimai »

I think you need nexttoggle=now(); in the night time period.
Roberto.
carlii
Posts: 84
Joined: Sat Mar 17, 2012 7:22 pm

Re: Wavemaker coding question

Post by carlii »

What do the numbers in :

nexttoggle+=random(40,45);

mean?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post by rimai »

It means that the next toggle will be a random number between 40 and 45 seconds.
Roberto.
JoshSD
Posts: 37
Joined: Sun Dec 04, 2011 3:19 pm

Re: Wavemaker coding question

Post 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!
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wavemaker coding question

Post 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.
Roberto.
Post Reply