Page 1 of 1

glitch in slow down waves at night

Posted: Sun Nov 20, 2011 9:26 pm
by psyrob
I am trying to mimic jsclownfish's slowing down of the wave maker at night, but after initial success, the slow down is happening outside of what I thought was coded to make it slow down from 9 pm to 8 am...It is supposed to have random master/slave wavemaker function from 8 am to 9 pm, then from 9 pm to 8 am, I am trying to have it go 25 seconds pump 1, then both off for 60 secs, then 25 seconds on for pump 2, then both off for 60 seconds, etc. Right now, it is doing the slow down outside the 9 pm to 8 am...what do I have wrong here? Thanks
/* The following features are enabled for this PDE File: 
#define DisplayImages
#define DateTimeSetup
#define VersionMenu
#define wifi
#define SIMPLE_MENU
*/


#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>

byte wmport=Port5;
boolean wmdelay=false;

void setup()
{
    ReefAngel.Init();  //Initialize controller

    ReefAngel.FeedingModePorts = B00011000;
    ReefAngel.WaterChangePorts = B00011000;
    ReefAngel.OverheatShutoffPorts = B11000110;
    ReefAngel.LightsOnPorts = B10000110;
    randomSeed(analogRead(0));
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Timer[1].SetInterval(random(30,45));
    ReefAngel.Timer[1].Start(); 
    ReefAngel.Relay.On(Port5);
}

void loop()
{
    // Specific functions
    ReefAngel.StandardATO(Port1);
    ReefAngel.StandardLights(Port2);
    ReefAngel.MHLights(Port3);
    ReefAngel.StandardFan(Port4);
    //ReefAngel.Wavemaker1(Port5);
    //ReefAngel.Wavemaker2(Port6);
    ReefAngel.StandardHeater(Port7);
    ReefAngel.MHLights(Port8);

ReefAngel.ShowInterface();
if ( ReefAngel.Timer[1].IsTriggered() )
 {
   if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a
    {
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(60);  // wm night delay
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        if (wmport==Port5) wmport=Port6; else wmport=Port5;
        wmdelay=false;
      }
      else
      {
        ReefAngel.Timer[1].SetInterval(25);  // short wave
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-9p normal wave settings
            ReefAngel.Timer[1].SetInterval(random(30,45));
            ReefAngel.Timer[1].Start();
            ReefAngel.Relay.Toggle(Port5);
            ReefAngel.Relay.Toggle(Port6);
           }
 }
}

Re: glitch in slow down waves at night

Posted: Sun Nov 20, 2011 10:30 pm
by rimai
Looks ok to me.
Can I ask if both Port 5 and 6 are going on at the same time?
Maybe what you are seeing is Port 5 and 6 on and off simultaneously and you are thinking it is on the delay mode.
If this is the case, I know what happended.

Re: glitch in slow down waves at night

Posted: Mon Nov 21, 2011 5:56 am
by binder
you are calling reefangel.init() 2 times in setup(). you should remove the second one of it. that second one is clearing out all of your port toggles for the different modes. it's not affecting the wavemaker code though.

curt

Re: glitch in slow down waves at night

Posted: Mon Nov 21, 2011 9:59 am
by psyrob
Curt: thanks, I see that now..

Roberto: No, I'm sure both pumps were off, not both on simultaneously...It really seems as if the slowdown mode, the on pump on....both pumps off...then other pump on, is happening outside of the 9pm to 8 am time period...

Re: glitch in slow down waves at night

Posted: Mon Nov 21, 2011 10:34 pm
by psyrob
Roberto : I checked again and you were right, in the day time period, the pumps are running both on then both off... What do you think is happening? Thanks in advance...

Re: glitch in slow down waves at night

Posted: Mon Nov 21, 2011 10:55 pm
by psyrob
And P.S.... Night time mode is working as it should...

Re: glitch in slow down waves at night

Posted: Tue Nov 22, 2011 8:56 am
by rimai
Ok, so, let me explain what is happening and then I'll think of a solution.
The function Toggle() simply toggles the state of the relay and it doesn't really check whether port 5 and 6 are in-sync or out-of-sync.
So, if 9am comes and the night mode is in the period of both ports off, it would turn both ports on, causing what you are seeing.
If 9am comes and it happens to be in the period where one of the port is on, you would've been fine.
So, let me think of a solution for the problem.

Re: glitch in slow down waves at night

Posted: Tue Nov 22, 2011 11:43 am
by binder
it's like you need to check the status of the relays to know what to do with them. i know that doesn't help much but just my comment.

curt

Re: glitch in slow down waves at night

Posted: Tue Nov 22, 2011 12:17 pm
by rimai
Ok, replace this:

Code: Select all

            ReefAngel.Relay.Toggle(Port5);
            ReefAngel.Relay.Toggle(Port6);

with this:

Code: Select all

            ReefAngel.Relay.Toggle(Port5);
            if bitRead(ReefAngel.Relay.RelayData,Port5-1) ReefAngel.Relay.Off(Port6); else ReefAngel.Relay.On(Port6);

Re: glitch in slow down waves at night

Posted: Sat Nov 26, 2011 4:40 pm
by psyrob
I cut and pasted...it works great, thanks alot!