Wave patterns

Related to the development libraries, released by Curt Binder
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: Wave patterns

Post by DrewPalmer04 »

Seedlessone wrote:So is reef crest just a slow ramp up and down to the predefined range?

Seems to slow for me. Would like it to change values up and down faster.

Are there any aggressive modes? I loved the else mode.

Change   if ((millis()-lastwavemillis) > 5000) to any value >5000 so 4000, 3000 etc

That'll speed you up on how often it checks for random -- else ++
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wave patterns

Post by rimai »

You can do short pulse mode with random range. Would that work?
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post by Smotz »

rimai wrote:You can do short pulse mode with random range. Would that work?

Can you give me an example of this code?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wave patterns

Post by rimai »

Code: Select all

ReefAngel.PWM.SetActinic(ShortPulseMode(0, 100, random(500,1500), true));
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post by Smotz »

As always, much appreciated.

I know the 0 to 100 means between 0 and 100% power - I would want to limit that to 70% max so I would make mine 70.

The 500,1500 is duration in milliseconds?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wave patterns

Post by rimai »

Correct :)
You can also change the duration to whatever range you prefer.
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post by Smotz »

So I set this code but it's not giving me the desired effect:

ReefAngel.PWM.SetDaylight( LongPulseMode(random(35,70),70,5,true));

what is does is quickly go through a bunch of random numbers, then it stays at 70% for 5 seconds.

What I wanted is for it to choose a random strength between 35 and 70% for 5 seconds.

Thoughts?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wave patterns

Post by rimai »

I see now that this solution will not work.
Try this:

Code: Select all

byte random_speed=35;
if (now()%5==1) random_speed=random(35,70);
ReefAngel.PWM.SetDaylight( LongPulseMode(random_speed,70,5,true)); 
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post by Smotz »

rimai wrote:I see now that this solution will not work.
Try this:

Code: Select all

byte random_speed=35;
if (now()%5==1) random_speed=random(35,70);
ReefAngel.PWM.SetDaylight( LongPulseMode(random_speed,70,5,true)); 

Any way to incorporate a pause (1 second) before the next pulse?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wave patterns

Post by rimai »

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 :roll: , but we can definitely do it... :mrgreen:
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post 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 :roll: , but we can definitely do it... :mrgreen:

I guess. I am just trying to (logically) figure out a wave pattern with just 1 pump (and the return pump)
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wave patterns

Post 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));
Roberto.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post 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;
}
}
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Wave patterns

Post 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.
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post 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.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Wave patterns

Post 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!
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post 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?
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Wave patterns

Post by binder »

that is correct.
User avatar
Robert1969
Posts: 33
Joined: Fri Mar 18, 2011 6:18 pm
Location: Redding Ca

Re: Wave patterns

Post 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
Image
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Wave patterns

Post by Smotz »

The definition (the latter part) is longer needed in the updated libraries
User avatar
Robert1969
Posts: 33
Joined: Fri Mar 18, 2011 6:18 pm
Location: Redding Ca

Re: Wave patterns

Post by Robert1969 »

Is the definition part everything between { } ?
Image
enigma32
Posts: 74
Joined: Fri Apr 26, 2013 11:48 am
Location: Los Angeles and NYC

Re: Wave patterns

Post 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);
}
Current setup:
60g 24" custom cube (fish and softies right now)
AI Sol Blue, Ecotech MP-10wES
Coralife skimmer
100% customer controller, transitioning to ReefAngel
User avatar
Robert1969
Posts: 33
Joined: Fri Mar 18, 2011 6:18 pm
Location: Redding Ca

Re: Wave patterns

Post by Robert1969 »

Ok I'm confused. What do I add then if I want the reef crest mode?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Wave patterns

Post 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
User avatar
Robert1969
Posts: 33
Joined: Fri Mar 18, 2011 6:18 pm
Location: Redding Ca

Re: Wave patterns

Post by Robert1969 »

What part is the function. Sorry for all the noob questions most of the time I feel so lost with this thing
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Wave patterns

Post 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.
User avatar
Robert1969
Posts: 33
Joined: Fri Mar 18, 2011 6:18 pm
Location: Redding Ca

Re: Wave patterns

Post by Robert1969 »

Oh ok. Thank you
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Wave patterns

Post 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?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Wave patterns

Post 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.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Wave patterns

Post by Sacohen »

That's what I thought.
45 is the % of speed.
What format is the time in, seconds or milliseconds?
Post Reply