glitch in slow down waves at night

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

glitch in slow down waves at night

Post 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);
           }
 }
}
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: glitch in slow down waves at night

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

Re: glitch in slow down waves at night

Post 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
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: glitch in slow down waves at night

Post 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...
Image
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: glitch in slow down waves at night

Post 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...
Last edited by psyrob on Mon Nov 21, 2011 10:56 pm, edited 1 time in total.
Image
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: glitch in slow down waves at night

Post by psyrob »

And P.S.... Night time mode is working as it should...
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: glitch in slow down waves at night

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

Re: glitch in slow down waves at night

Post 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
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: glitch in slow down waves at night

Post 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);
Roberto.
psyrob
Posts: 242
Joined: Thu Sep 01, 2011 8:44 pm

Re: glitch in slow down waves at night

Post by psyrob »

I cut and pasted...it works great, thanks alot!
Image
Post Reply