Page 1 of 1

random wavemaker and overlap

Posted: Fri Sep 14, 2012 7:43 pm
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.
    }

Re: random wavemaker and overlap

Posted: Sat Sep 15, 2012 8:44 am
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.

Re: random wavemaker and overlap

Posted: Sun Sep 16, 2012 4:48 pm
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);
        }
    }
  }

Re: random wavemaker and overlap

Posted: Sun Sep 16, 2012 5:14 pm
by rimai
yes... on not off. sorry.
You placed it in the correct spot for your daytime period :)

Re: random wavemaker and overlap

Posted: Sun Sep 16, 2012 8:52 pm
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...

Re: random wavemaker and overlap

Posted: Sun Sep 16, 2012 9:02 pm
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);
  }
}

Re: random wavemaker and overlap

Posted: Mon Sep 17, 2012 8:48 pm
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
        }
    }
  

Re: random wavemaker and overlap

Posted: Mon Sep 17, 2012 8:59 pm
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();
  }
}

Re: random wavemaker and overlap

Posted: Mon Sep 17, 2012 9:36 pm
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...

Re: random wavemaker and overlap

Posted: Mon Sep 17, 2012 10:01 pm
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.
    }
  }
}

Re: random wavemaker and overlap

Posted: Tue Sep 18, 2012 9:58 pm
by psyrob
So far so good...just loaded it tonight, the night time mode is working so far...thanks

Re: random wavemaker and overlap

Posted: Wed Sep 19, 2012 9:27 pm
by psyrob
Sorry Roberto, but this code isn't making the overlap happening during the day....

Re: random wavemaker and overlap

Posted: Wed Sep 19, 2012 9:31 pm
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.

Re: random wavemaker and overlap

Posted: Wed Sep 19, 2012 10:30 pm
by psyrob
Thanks Roberto...I will try it tomorrow during the daylight schedule... :)

Re: random wavemaker and overlap

Posted: Thu Sep 20, 2012 3:12 pm
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();
      }    
    }
  }
}

Re: random wavemaker and overlap

Posted: Thu Sep 20, 2012 3:41 pm
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?

Re: random wavemaker and overlap

Posted: Thu Sep 20, 2012 3:43 pm
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
    }    
  }  
}

Re: random wavemaker and overlap

Posted: Thu Sep 20, 2012 4:41 pm
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...

Re: random wavemaker and overlap

Posted: Thu Sep 20, 2012 6:08 pm
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
    }    
  }  
}

Re: random wavemaker and overlap

Posted: Thu Sep 20, 2012 6:54 pm
by psyrob
Just watched the first five minute cycle...it works!! I will keep an eye on it...nice detective work Roberto!! :mrgreen: