random wavemaker and overlap

Do you have a question on how to do something.
Ask in here.
Post Reply
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

random wavemaker and overlap

Post by psyrob »

I found another post that sort of addressed this, but I want to do something a little different....

Right now I have my wavemaker going left side one for 45 seconds or so, then the right one on for 45 seconds or so...then I have a night time mode where there is a 1 minute delay between them when neither is on at all...

What I was thinking of doing was during the daytime mode was every fifth time (or some interval) have both pumps on at the same time to really stir things up, and then back to one pump on, one pump off for the random interval....what would I need to insert in the code?

Thanks in advance...
This is the wavemaker section of code...

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
    }
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

With an interval is super easy.
Something like this:

Code: Select all

if (now()%300<50)
{
  ReefAngel.Relay.Off(WMRelay1);
  ReefAngel.Relay.Off(WMRelay2);
}
Place this as the last check in your function and it should have higher priority than the other checks.
It will turn both on every 300s for 50s. You can adjust it accordingly.
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

should this be "rely on" instead of relay off? I uploaded and both pumps went off...
And if I want this to only happen during the daytime cycle, (between 8 am and 9 pm), do I put this "if"statement in the if/else for the 9 am to 8 pm loop (I don't know the right terms to use in describing this) :

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
      if (now()%300<30)
        {
          ReefAngel.Relay.On(WMRelay1);
          ReefAngel.Relay.On(WMRelay2);
        }
    }
  }
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

yes... on not off. sorry.
You placed it in the correct spot for your daytime period :)
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

Ok, it is working, except the timer for when both are on doesn't seem to be using the <30, it seems to be using the random timer I set in the wizard of Random between 35 and 45 seconds...
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

Yeah, I see what the problem is now that you mentioned.
Try this:

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
    }
  }
  if (now()%300<30)
  {
    ReefAngel.Relay.On(WMRelay1);
    ReefAngel.Relay.On(WMRelay2);
  }
}
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

OK, thanks Roberto, but this code still has the "overlap" time going for the random times I set with the wizard, not the time set in this code, which is 20 seconds...

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
    }
  }
      if (now()%300<20)
        {
          ReefAngel.Relay.On(WMRelay1);
          ReefAngel.Relay.On(WMRelay2);//they are supposed to be on at the same time for 20 seconds
                                        //every 5 minutes
        }
    }
  
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

Let's try forcing the trigger.

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
    }
  }
  if (now()%300<20)
  {
    ReefAngel.Relay.On(WMRelay1);
    ReefAngel.Relay.On(WMRelay2);//they are supposed to be on at the same time for 20 seconds
    //every 5 minutes
    WMRTimer=now();
  }
}
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

Oh, and the overlap is happening during the night time mode as well, not just from 8 am to 9 pm, and it is using the 20 second time to be on at night, just like happens with the pumps when they are on one at a time during the 9 pm to 8 am time period...
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

Ok, so let's try this then:

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
      if (now()%300<20)
      {
        ReefAngel.Relay.On(WMRelay1);
        ReefAngel.Relay.On(WMRelay2);//they are supposed to be on at the same time for 20 seconds
        //every 5 minutes
        WMRTimer=now();
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
    }
  }
}
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

So far so good...just loaded it tonight, the night time mode is working so far...thanks
Image
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

Sorry Roberto, but this code isn't making the overlap happening during the day....
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

Damn... I read the code wrong...
I put it on the night time :(
Hopefully this is the one:

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
      if (now()%300<20)
      {
        ReefAngel.Relay.On(WMRelay1);
        ReefAngel.Relay.On(WMRelay2);//they are supposed to be on at the same time for 20 seconds
        //every 5 minutes
        WMRTimer=now();
      }    
    }
  }
}
Update: I just updated it right after I submitted. So, don't copy the one in the email. Use the one posted above.
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

Thanks Roberto...I will try it tomorrow during the daylight schedule... :)
Image
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

Sorry if this is a PITA, but it is not working during the day time :( ...the pumps are not coming on at the same time at all...
here is the code

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
      if (now()%300<20)
      {
        ReefAngel.Relay.On(WMRelay1);
        ReefAngel.Relay.On(WMRelay2);//they are supposed to be on at the same time for 20 seconds
        //every 5 minutes
        WMRTimer=now();
      }    
    }
  }
}
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

I just tested it and they did here.
It's programmed to come on at the first 20 seconds of every 5 minutes.
So, 15:00:00 to 15:00:20, 15:05:00 to 15:05:20, 15:10:00 to 15:10:05 and so on.
Can you double check?
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

Oh, you know what, I know it worked for me....
I use the timer which was less than the override.
Ok, I think this one will do:

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
    }
  }
  if ((hour() > 8) && (hour() < 21)) //from 9p-8a 
  {
    if (now()%300<20)
    {
      ReefAngel.Relay.On(WMRelay1);
      ReefAngel.Relay.On(WMRelay2);//they are supposed to be on at the same time for 20 seconds
      //every 5 minutes
    }    
  }  
}
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

OK, this is what is doing now: Every five minutes both pumps come on and the timer I have on the screen shows the countdown. Both pumps come on and the timer counts down from 10 secs to 0, then resets to 40 seconds down to zero, then both pumps go off. So both are on for 50 seconds every 5 minutes instead of 20. I don't understand the "double countdown" either...
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: random wavemaker and overlap

Post by rimai »

So, it's the timer that is messing up then...
Try this:

Code: Select all

void MyWavemakerRandom(byte WMRelay1, byte WMRelay2, int MinWMTimer, int MaxWMTimer)
{
  if (now()>WMRTimer)
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        WMRTimer=now()+60;
        ReefAngel.Relay.Off(WMRelay1);
        ReefAngel.Relay.Off(WMRelay2);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;        
        wmdelay=false;
      }
      else
      {
        WMRTimer=now()+20;
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      WMRTimer=now()+random(MinWMTimer, MaxWMTimer);
      ReefAngel.Relay.Toggle(WMRelay1);
      ReefAngel.Relay.Set(WMRelay2,!ReefAngel.Relay.Status(WMRelay1)); // Turn Port6 on/off on opposite cycle as Port 5
      // Port 5 and 6 are synchronized.
      // They work in opposing motion of each other at random times.
    }
  }
  if ((hour() > 8) && (hour() < 21)) //from 9p-8a 
  {
    if (now()%300==0)
    {
      WMRTimer=now()+20;
      ReefAngel.Relay.On(WMRelay1);
      ReefAngel.Relay.On(WMRelay2);//they are supposed to be on at the same time for 20 seconds
      //every 5 minutes
    }    
  }  
}
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: random wavemaker and overlap

Post by psyrob »

Just watched the first five minute cycle...it works!! I will keep an eye on it...nice detective work Roberto!! :mrgreen:
Image
Post Reply