Page 1 of 5
Re: Wave patterns
Posted: Mon Apr 15, 2013 5:33 pm
by Smotz
rimai wrote:Not with this function.
You will need to use another custom function with whatever wave pattern you want.
Let me see if I understand...
The wave is going to be random between 35% and 70% for 5 seconds, 70% for 5 seconds and 0% for 1 second?
Weird one

, but we can definitely do it...

I guess. I am just trying to (logically) figure out a wave pattern with just 1 pump (and the return pump)
Re: Wave patterns
Posted: Tue Apr 16, 2013 9:12 am
by rimai
Add this to the end of your code:
Code: Select all
byte MyCustomWave(byte maxspeed)
{
static byte randomspeed=0;
if (now()%11<5)
{
return randomspeed;
}
else if (now()%11>=5 && now()%11<10)
{
return maxspeed;
}
else
{
randomspeed=random(35,maxspeed);
return 0;
}
}
And call your function like this:
Code: Select all
ReefAngel.PWM.SetActinic(MyCustomWave(70));
Re: Wave patterns
Posted: Wed Apr 17, 2013 1:01 pm
by Smotz
rimai wrote:Add this to the end of your code:
Code: Select all
byte MyCustomWave(byte maxspeed)
{
static byte randomspeed=0;
if (now()%11<5)
{
return randomspeed;
}
else if (now()%11>=5 && now()%11<10)
{
return maxspeed;
}
else
{
randomspeed=random(35,maxspeed);
return 0;
}
}
And call your function like this:
Code: Select all
ReefAngel.PWM.SetActinic(MyCustomWave(70));
Wow man, Thanks!
Can I ask you to help me understand this a bit? - Teach a man to fish sort of thing?
Can you explain what the %11 is? I assume it's the variable for the duration but I don't understand how it got defined..?
How would I alter this to Random wave, pause for 1 sec, etc ?
would this do it? (but it looks to me like it waits for 5 seconds?)
byte MyCustomWave(byte maxspeed)
{
static byte randomspeed=0;
if (now()%11<5)
{
return randomspeed;
}
else
{
randomspeed=random(35,maxspeed);
return 0;
}
}
Re: Wave patterns
Posted: Wed Apr 17, 2013 4:05 pm
by binder
The %11 is a mathematical computation. The % is actually called modulus. It takes the remainder of the division operation. When he is using the %11, he is taking the number of seconds (now()) and breaking it down into 11 segments with each segment being 1 second. The first part of his code, now()%11<5 is checking for seconds 0-4 inclusive (which is 5 seconds). The second part, now()%11>=5 && now()%11<10, is checking for seconds 5-9 inclusive (which is 5 seconds) and then the last scenario is simply 1 second.
What ends up happening is the first IF runs for 5 seconds, the next IF runs for 5 seconds and the last IF runs for 1 second then the whole process repeats over and over again every 11 seconds no matter what time of day it is.
Your code you put down:
Code: Select all
if ( now()%11 < 5 )
{
return randomspeed;
} else {
randomspeed=random(35,maxspeed);
return 0;
}
Will run the first part for 5 seconds and the second part for 6 seconds. So run for 5 seconds, pause for 6 seconds, repeat.
Re: Wave patterns
Posted: Wed Apr 17, 2013 4:58 pm
by Smotz
thanks curt. Much appreciated. I kinda get it - doing will really teach me. I am so glad i went reef angel. I am learning a lot.
Wave patterns
Posted: Wed Apr 17, 2013 5:09 pm
by lnevo
Smotz wrote:thanks curt. Much appreciated. I kinda get it - doing will really teach me. I am so glad i went reef angel. I am learning a lot.
+1 try doing any of this with an apex! Not possible!
Re: Wave patterns
Posted: Thu Apr 18, 2013 4:26 am
by Smotz
binder wrote:The %11 is a mathematical computation. The % is actually called modulus. It takes the remainder of the division operation. When he is using the %11, he is taking the number of seconds (now()) and breaking it down into 11 segments with each segment being 1 second. The first part of his code, now()%11<5 is checking for seconds 0-4 inclusive (which is 5 seconds). The second part, now()%11>=5 && now()%11<10, is checking for seconds 5-9 inclusive (which is 5 seconds) and then the last scenario is simply 1 second.
What ends up happening is the first IF runs for 5 seconds, the next IF runs for 5 seconds and the last IF runs for 1 second then the whole process repeats over and over again every 11 seconds no matter what time of day it is.
Your code you put down:
Code: Select all
if ( now()%11 < 5 )
{
return randomspeed;
} else {
randomspeed=random(35,maxspeed);
return 0;
}
Will run the first part for 5 seconds and the second part for 6 seconds. So run for 5 seconds, pause for 6 seconds, repeat.
SOOO. If I change the 11 to a 7 - the first part will run for 5 seconds and the second for 2?
Re: Wave patterns
Posted: Thu Apr 18, 2013 4:14 pm
by binder
that is correct.
Re: Wave patterns
Posted: Wed May 01, 2013 11:45 pm
by Robert1969
ok Im a little lost. have had my WP40 cable for about a week and thought I would try to get my Jabao pump set up.
If I understand it correctly all I have to do is add a code from page 1, of this topic, between the lines "Place your custom code below/above here" on my sketch.
I can add this code from page 2 and it works fine:
byte random_speed=35;
if (now()%5==1) random_speed=random(35,70);
ReefAngel.PWM.SetDaylight( LongPulseMode(random_speed,70,5,true));
But if I add lets say the "Reefcrest" code from page 1:
byte ReefCrestMode(byte WaveSpeed, byte WaveOffset, boolean PulseSync)
{
static unsigned long lastwavemillis=millis();
static int newspeed=WaveSpeed;
if ((millis()-lastwavemillis) > 5000)
{
if (random(100)<50) newspeed--; else newspeed++;
newspeed=constrain(newspeed,WaveSpeed-WaveOffset,WaveSpeed+WaveOffset);
newspeed=constrain(newspeed,0,100);
lastwavemillis=millis();
}
if (PulseSync)
return newspeed;
else
return WaveSpeed-(newspeed-WaveSpeed);
}
I get the following error from Arduino: a function-definition is not allowed here before{token
Do I need to do something to the code before adding it to my sketch?
Thanks for any help
Re: Wave patterns
Posted: Thu May 02, 2013 3:59 am
by Smotz
The definition (the latter part) is longer needed in the updated libraries
Re: Wave patterns
Posted: Thu May 02, 2013 5:37 pm
by Robert1969
Is the definition part everything between { } ?
Re: Wave patterns
Posted: Thu May 02, 2013 5:42 pm
by enigma32
And the line above it.
He's saying the whole function no longer needs to be manually added in your code:
Code: Select all
byte ReefCrestMode(byte WaveSpeed, byte WaveOffset, boolean PulseSync)
{
static unsigned long lastwavemillis=millis();
static int newspeed=WaveSpeed;
if ((millis()-lastwavemillis) > 5000)
{
if (random(100)<50) newspeed--; else newspeed++;
newspeed=constrain(newspeed,WaveSpeed-WaveOffset,WaveSpeed+WaveOffset);
newspeed=constrain(newspeed,0,100);
lastwavemillis=millis();
}
if (PulseSync)
return newspeed;
else
return WaveSpeed-(newspeed-WaveSpeed);
}
Re: Wave patterns
Posted: Thu May 02, 2013 7:33 pm
by Robert1969
Ok I'm confused. What do I add then if I want the reef crest mode?
Wave patterns
Posted: Thu May 02, 2013 7:35 pm
by lnevo
You just use the function...you no longer need to have the whole section in your code that was in the last post
Re: Wave patterns
Posted: Thu May 02, 2013 7:51 pm
by Robert1969
What part is the function. Sorry for all the noob questions most of the time I feel so lost with this thing
Wave patterns
Posted: Thu May 02, 2013 8:13 pm
by lnevo
The function is part of the libraries.
You use it by setting the port connected to your pump with the result of the function like this...
ReefAngel.PWM.SetActinic( ReefCrestMode(45,10,true));
You put a line like that inside your loop section.
Re: Wave patterns
Posted: Thu May 02, 2013 8:32 pm
by Robert1969
Oh ok. Thank you
Re: Wave patterns
Posted: Fri May 10, 2013 12:42 pm
by Sacohen
So If I wanted a Long Pulse and my WP40 is plugged into my daylights i would do something like this...
ReefAngel.PWM.SetDaylight( LongPulseMode(45,10,true));
What is the 45,10 the pump speed and wave length?
Also what does the true do?
Wave patterns
Posted: Fri May 10, 2013 1:42 pm
by lnevo
45 is the % 10 is the time between pulses and true means sync.
If you had two pumps you could set one true and one false for an anti sync effect.
Re: Wave patterns
Posted: Fri May 10, 2013 1:53 pm
by Sacohen
That's what I thought.
45 is the % of speed.
What format is the time in, seconds or milliseconds?
Re: Wave patterns
Posted: Fri May 10, 2013 1:57 pm
by rimai
It's in the original post

Each function has a different unit. Short Pulse and NTM are milliseconds, but Long Pulse is seconds.
Also, your code is missing one parameter. It's supposed to be 4 total.
Check the original post.
Re: Wave patterns
Posted: Fri May 10, 2013 2:11 pm
by Sacohen
Sorry Roberto. Like I said I'm a complete noob to coding.
It looks like I left out the PulseMinSpeed or PulseMaxSpeed.
So would it be like this?
ReefAngel.PWM.SetDaylight( LongPulseMode(45,70,10,true));
Re: Wave patterns
Posted: Fri May 10, 2013 2:14 pm
by rimai
Yes

You got it

Re: Wave patterns
Posted: Fri May 10, 2013 3:33 pm
by Sacohen
Thanks for making me figure it out.
Again "Teach a man to fish".
Re: Wave patterns
Posted: Sat May 11, 2013 4:08 am
by SaltyGXP
So I've scanned throughout the last 5 or so pages and didn't see it. Is there ant way we can get Lagoon mode add to the wave patterns?
Thanks
Dustin
Re: Wave patterns
Posted: Sat May 11, 2013 8:52 am
by rimai
Well, Lagoon is nothing more than reefcrest with a very close min and max range.
Re: Wave patterns
Posted: Sun May 19, 2013 7:34 am
by Sacohen
Ok I got most everything setup last night.
There's only a couple of things I need to tackle still, but the first and what seems to be the easiest is hooking up and coding the WP40.
I know all the wave patterns are on the first page (Thank Roberto), but can someone equate them to the different modes on the WP40?
H: High, constant, non-variable flow (13,000 LPH)
L: Low, constant, non-variable flow at a third of the speed (4,300 LPH)
W1: Short pulses which, when timed correctly will create a back and forth motion and form a gentle standing wave in your tank. Adjust the controller to change the speed of the pulses and vary the size of the wave according to your tank.
W2 & W3: Pump gradually speeds up and slows down incrementally to create a varied flow pattern. Adjustable to form the wave best suited to your tank.
Else: Reef Stream Mode, a mixed, changing pattern that creates a random flow cycle similar to what you would find in a natural reef.
I currently use W1 on a slow speed 16-18V and a medium wave length.
Re: Wave patterns
Posted: Thu May 30, 2013 7:09 am
by coolbird
Could I just ask as I may be looking at this a bit to simplistically:
I have 2x wp40's that I want to connect to my light ports and for example I want a long pulse minimum power at 10% maximum at 50 lasting for 20 seconds each anti-sync I would enter the below into my loop?
ReefAngel.PWM.SetDaylight( LongPulseMode(10,50,20,true))
ReefAngel.PWM.SetActinic( LongPulseMode(10,50,20,false))
Thanks
Dave
Re: Wave patterns
Posted: Thu May 30, 2013 7:33 am
by Sacohen
I'm just getting into coding and by no means am an expert, but this looks correct.
The criteria for Long Pulse is...
Long Pulse
PulseMinSpeed - % for minimal speed
PulseMaxSpeed - % for maximum speed
PulseDuration - Duration (seconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will stay at maximum speed for PulseDuration.
PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
Re: Wave patterns
Posted: Thu May 30, 2013 7:39 am
by coolbird
Sacohen wrote:I'm just getting into coding and by no means am an expert, but this looks correct.
The criteria for Long Pulse is...
Long Pulse
PulseMinSpeed - % for minimal speed
PulseMaxSpeed - % for maximum speed
PulseDuration - Duration (seconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will stay at maximum speed for PulseDuration.
PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
Hi Sacohen
Its how I see it as well; I should thank you really as you have been asking all the questions I would have put
We will see what the masters of the "black art" say, I hope we are both not mistaken
Thanks again
Dave