Slow down waves at night

Do you have a question on how to do something.
Ask in here.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Slow down waves at night

Post by jsclownfish »

I'm trying to figure out how to reduce wave flow at night. I wanted to switch from alternating 200 sec waves during the day to shorter bursts with a lull in between at night. I started with this from pieces of other code I found around here, but the seated "if" statements don't fly. Thanks for your help.
-Jon

Code: Select all

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

    ReefAngel.FeedingModePorts = B00110000;
    ReefAngel.WaterChangePorts = B10110000;
    ReefAngel.OverheatShutoffPorts = B00000111;
    ReefAngel.LightsOnPorts = B00001100;
    ReefAngel.Relay.On(Port5);
    ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
    ReefAngel.Timer[1].Start();
    // Ports that are always on
    ReefAngel.Relay.On(Port7);
}
void loop()
{
    // Specific functions
    //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
    ReefAngel.StandardHeater(Port1,788,792);
    ReefAngel.StandardHeater(Port2,770,792);
    ReefAngel.MHLights(Port3,10,0,20,0,5);
    ReefAngel.StandardLights(Port4,9,0,21,0);
    ReefAngel.StandardFan(Port8,792,820);
   // Wavemaker Code with night option
   if (ReefAngel.Timer[1].IsTriggered() )
   {
   if ( ((hour() >= 22) || (hour() <= 8)) //from 10p-8a  
   {
    ReefAngel.Timer[1].Start();
    ReefAngel.Timer[1].SetInterval(20);  //change interval to short bursts
    ReefAngel.Relay.Toggle(Port5);
    ReefAngel.DelayedOn(Port5,1);    //delay 1 minute between bursts
    ReefAngel.Relay.Toggle(Port6);
    ReefAngel.DelayedOn(Port6,1);   //delay 1 minute between bursts
   }
   else
   {
  //8a-10p normal wave settings
    ReefAngel.Timer[1].Start();
    ReefAngel.Relay.Toggle(Port5);
    ReefAngel.Relay.Toggle(Port6);
  }
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

I did not quite understand what you are trying to accomplish.
Correct me if I'm wrong.
During the day, which is from 9am to 10pm, you have a symmetric alternating cycle between 5 and 6 of 200s.
But you would like to have during the night, which is from 10pm to 9am, an asymmetric cycle, that would be 5 on for 20s, then 6 on for 20s then both off for 60s.
Is it correct?
If not, please clarify.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

That is close, but not quite the same. The daytime part is correct. Symmetric alternating powerheads on opposite sides of the tank for 200s.

During the night I want some water movement, but not the same level of back and forth. So I thought I would have the pumps alternate for 20s, but have a one minute delay between them.

Pump 5 on 20s
Pump 5 & 6 off 1 minute
Pump 6 on 20s
Pump 5 & 6 off 1 minute
Pump 5 on 20s
......
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Give this a try

Code: Select all

#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 = B00110000;
  ReefAngel.WaterChangePorts = B10110000;
  ReefAngel.OverheatShutoffPorts = B00000111;
  ReefAngel.LightsOnPorts = B00001100;
  ReefAngel.Relay.On(Port5);
  ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
  ReefAngel.Timer[1].Start();
  // Ports that are always on
  ReefAngel.Relay.On(Port7);
}
void loop()
{
  // Specific functions
  //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
  ReefAngel.StandardHeater(Port1,788,792);
  ReefAngel.StandardHeater(Port2,770,792);
  ReefAngel.MHLights(Port3,10,0,20,0,5);
  ReefAngel.StandardLights(Port4,9,0,21,0);
  ReefAngel.StandardFan(Port8,792,820);
  // Wavemaker Code with night option
  if (ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 22) || (hour() <= 8)) //from 10p-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(20);  // short wave
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-10p normal wave settings
      ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      ReefAngel.Relay.Toggle(Port6);
    }
  }
  ReefAngel.ShowInterface();
}

Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

Works great! Thanks! I can't tell you how much I enjoy the flexibility of this system and the great support.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

Oops, I spoke to soon. It works at 10PM to slow down the waves, but it didn't reset at 8 AM. Any ideas?

Here is my pde.

Code: Select all

#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>
//Cloud & Lightning effects
byte ActinicPWMValue=0;
byte DaylightPWMValue=0;
byte wmport=Port5;
boolean wmdelay=false;

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

  ReefAngel.FeedingModePorts = B00110000;
  ReefAngel.WaterChangePorts = B10110000;
  ReefAngel.OverheatShutoffPorts = B00000111;
  ReefAngel.LightsOnPorts = B00001100;
  ReefAngel.Relay.On(Port5);
  ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
  ReefAngel.Timer[1].Start();
  // Ports that are always on
  ReefAngel.Relay.On(Port7);
}
void loop()
{
  // Specific functions
  //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
  ReefAngel.StandardHeater(Port1,788,792);
  ReefAngel.StandardHeater(Port2,770,792);
  ReefAngel.MHLights(Port3,10,0,20,0,5);
  ReefAngel.StandardLights(Port4,9,0,21,0);
  ReefAngel.StandardFan(Port8,792,820);
  // Wavemaker Code with night option
  if (ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 22) || (hour() <= 8)) //from 10p-8a  
    {
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(100);  // wm night delay 100 seconds between pulses
        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(50);  // waves of 50 seconds alternating
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-10p normal wave settings
      ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      ReefAngel.Relay.Toggle(Port6);
    }
  }
  //Using Daylight ATO high signal piezo buzzer when temp exceeds 83F
if (ReefAngel.Params.Temp1>830) 
  {
  pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,HIGH);
  }
  else
  {pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,LOW);
  }
    //Moonlight=byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
   ReefAngel.PWM.SetActinic(ActinicPWMValue);
   ActinicPWMValue=PWMSlope(7,00,22,0,0,100,60,ActinicPWMValue); 
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
   DaylightPWMValue=PWMSlope(7,00,22,0,0,100,60,DaylightPWMValue);

  ReefAngel.ShowInterface();
}
Last edited by jsclownfish on Mon Nov 14, 2011 8:55 am, edited 1 time in total.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Changes at 9
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

right, of course. ">=8" means at 9. I left for work before I could catch the change. THANKS!
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

So the next logical step for me on this little project would be to gradually slow the waves down and pick them up in a diurnal cycle. I worked up this idea off of Roberto's teachings to give it a try. The idea is that the code slowly increases the pause between decreasing and alternating powerhead bursts. Then the opposite will happen as we move towards morning. Do you think this will work? Thanks for the advice.

Code: Select all

#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>
//Actinic and Daylight PMW are on the LED moonlights
byte ActinicPWMValue=0;
byte DaylightPWMValue=0;
byte wmport=Port5;
boolean wmdelay=false;
#include <avr/pgmspace.h>
// Labels for the web banner
prog_char id_label[] PROGMEM = "jsclownfish";
prog_char probe1_label[] PROGMEM = "Tank";
prog_char probe2_label[] PROGMEM = "Room";
prog_char probe3_label[] PROGMEM = "Sump";
prog_char relay1_label[] PROGMEM = "Heater";
prog_char relay2_label[] PROGMEM = "Heater2";
prog_char relay3_label[] PROGMEM = "Halide";
prog_char relay4_label[] PROGMEM = "Actinic";
prog_char relay5_label[] PROGMEM = "WM1";
prog_char relay6_label[] PROGMEM = "WM2";
prog_char relay7_label[] PROGMEM = "Sump";
prog_char relay8_label[] PROGMEM = "Fan";
PROGMEM const char *webbanner_items[] = {
    id_label, probe1_label, probe2_label, probe3_label, relay1_label, relay2_label,
	relay3_label, relay4_label, relay5_label, relay6_label, relay7_label, relay8_label};
void setup()
{
  ReefAngel.Init();  //Initialize controller

  ReefAngel.FeedingModePorts = B00110000;
  ReefAngel.WaterChangePorts = B10110000;
  ReefAngel.OverheatShutoffPorts = B00000111;
  ReefAngel.LightsOnPorts = B00001100;
  ReefAngel.Relay.On(Port5);
  ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
  ReefAngel.Timer[1].Start();
  // Ports that are always on
  ReefAngel.Relay.On(Port7);
}
void loop()
{
  // Specific functions
  //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
  ReefAngel.StandardHeater(Port1,788,792);
  ReefAngel.StandardHeater(Port2,770,792);
  ReefAngel.MHLights(Port3,10,0,20,0,5);
  ReefAngel.StandardLights(Port4,9,0,21,0);
  ReefAngel.StandardFan(Port8,792,820);
  // Wavemaker Code with night option
  if (ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 22) || (hour() <= 2)) //from 10p-2a 
    {
      if (wmdelay)
      {
        //totals about 5 hours gradual slow totals 18000 sec or 5 hrs.
        int WMcounter=0;
        for (WMcounter = 0; WMcounter < 89; WMcounter++);  //loop from 0 to 89 (slow increase delay)
        ReefAngel.Timer[1].SetInterval(WMcounter);  // wm night delay between pulses
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        if (wmport==Port5) wmport=Port6; else wmport=Port5;
        wmdelay=false;
      }
      else
      {
        int WMcounter2=200;
        for (WMcounter2 = 200; WMcounter2 > 111; WMcounter2--);  //loop from 200 to 111  (slow decrease in pulse time)     
        ReefAngel.Timer[1].SetInterval(WMcounter2);  // waves alternating
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else if ((hour() >= 3) || (hour() <= 7)) //from 3a-8a
    {
      if (wmdelay)
      {
        //totals about 5 hours gradual increase of waves
        int WMcounter=89;
        for (WMcounter = 89; WMcounter > 0; WMcounter--);  //loop from 0 to 89 (slow decrease delay)
        ReefAngel.Timer[1].SetInterval(WMcounter);  // wm night delay between pulses
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        if (wmport==Port5) wmport=Port6; else wmport=Port5;
        wmdelay=false;
      }
      else
      {
        int WMcounter2=111;
        for (WMcounter2 = 111; WMcounter2 < 200; WMcounter2++);  //loop from 200 to 111  (slow decrease in pulse time)     
        ReefAngel.Timer[1].SetInterval(WMcounter2);  // waves alternating
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
   else
   {
      //8a-10p normal wave settings
      ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      ReefAngel.Relay.Toggle(Port6);
    }
  }
  //Using Daylight ATO high signal piezo buzzer when temp exceeds 83F
if (ReefAngel.Params.Temp1>830) 
  {
  pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,HIGH);
  }
  else
  {pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,LOW);
  }
    //Moonlight=byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
   ReefAngel.PWM.SetActinic(ActinicPWMValue);
   ActinicPWMValue=PWMSlope(7,00,22,0,0,100,60,ActinicPWMValue); 
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
   DaylightPWMValue=PWMSlope(7,00,22,0,0,100,60,DaylightPWMValue);

// Web Banner stuff
    if(ReefAngel.Timer[4].IsTriggered())
    {
        ReefAngel.Timer[4].Start();
        ReefAngel.WebBanner();
    }


  ReefAngel.ShowInterface();
}
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

I don't think it will work.
The "for" statements are doing nothing for the counter that you need to use.
Let me soak the idea and think of another way.
Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Slow down waves at night

Post by binder »

those for loops are empty loops and will just do a rapid increase or decrease with end result being the final value. you will have to do something different if you want the intervals to change with each activation of them.

i will also take a look at this problem too and see if i can come up with something in addition to roberto.

curt
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

OK, thanks. I was trying to mimic the code used in this LED dimming example.

Code: Select all

// Example 04: Fade an LED in and out like on 
// a sleeping Apple computer 
//
// Copy and paste this example into an empty Arduino sketch

#define LED   9 // the pin for the LED
int i = 0;      // We’ll use this to count up and down

void setup() { 
  pinMode(LED, OUTPUT); // tell Arduino LED is an output 
} 

void loop(){ 

  for (i = 0; i < 255; i++) { // loop from 0 to 254 (fade in)
    analogWrite(LED, i);      // set the LED brightness
    
    delay(10); // Wait 10ms because analogWrite
               // is instantaneous and we would
               // not see any change
  }

  for (i = 255; i > 0; i--) { // loop from 255 to 1 (fade out)

    analogWrite(LED, i); // set the LED brightness
    delay(10);           // Wait 10ms
  }

} 
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

If I understand correctly and looking at the code, the only thing you want to change is this value, correct?

Code: Select all

        ReefAngel.Timer[1].SetInterval(60);  // wm night delay
If this value is 0, it would make the wm alternate on 20s cycle just like during the day.
So, at night, you want the interval to grow from 1 to 60 and back down to 1 between 10pm and 9am.
We can use the PWMSlope function, which is already created to do that if this is what you wanted. :)
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

Well, that's close. I wasn't sure if the PWMSlope function would work on a relay. I thought it might only work on the LED ports. Basically, I tried to code something like this and add the totals to make 10 hours (5 slowing down, 5 speeding up). I thought the flow would be like this : R right side powerhead, L left side powerhead, D delay (all in seconds)

200 R
0 D
199 L
1 D
198 R
2 D
197 L
3 D
196 R
....(5 hours)
Then reverse order for 5 hours back to 200 alternating, no delay.

Thanks,
Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Ah, ok.
So you are scratching the original 20s, pause, 20s and making the 20s also a variable.
Got it.
At the peak of 5 hours, you would have wm on for just 1 second and pause for 199 seconds, which at that point, the pause would start decreasing and the on time for powerhead increases, right?
Something doesn't add up though.
10hrs=36000 seconds.
Whatever I understood would create 200 steps of 200 seconds each=40000s just for sloping down and another 40000s for sloping up.
Maybe I'm missing something.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

Yes, that is correct. That is why I tried to cap the cycles at 89 and 111 as it totalled 10 hours. The loop would not reach a full cycle.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Now that I understand what you were trying to accomplish, would you prefer having a full 200s to 1s ramp, even though there would be steps of 2 or 3 seconds??
Or you prefer having steps of 1 sec and cap it at 89/111??
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

Honestly, haven't thought it through to that detail. I suppose I'd like to limit it down to about 30 sec on and 170 off, but either way would probably work. I wanted to run it for a couple weeks to see how the tank (coral) responds.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Give this a try:

Code: Select all

#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;
byte wmpulse=0;

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

  ReefAngel.FeedingModePorts = B00110000;
  ReefAngel.WaterChangePorts = B10110000;
  ReefAngel.OverheatShutoffPorts = B00000111;
  ReefAngel.LightsOnPorts = B00001100;
  ReefAngel.Relay.On(Port5);
  ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
  ReefAngel.Timer[1].Start();
  // Ports that are always on
  ReefAngel.Relay.On(Port7);
}
void loop()
{
  // Specific functions
  //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
  ReefAngel.StandardHeater(Port1,788,792);
  ReefAngel.StandardHeater(Port2,770,792);
  ReefAngel.MHLights(Port3,10,0,20,0,5);
  ReefAngel.StandardLights(Port4,9,0,21,0);
  ReefAngel.StandardFan(Port8,792,820);
  // Wavemaker Code with night option
  if (ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 22) || (hour() <= 8)) //from 10p-8a  
    {
      wmpulse=PWMSlope(22,0,8,0,30,170,255,30);
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(200-wmpulse);  // 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(wmpulse);  // short wave
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-10p normal wave settings
      ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      ReefAngel.Relay.Toggle(Port6);
    }
  }
  ReefAngel.ShowInterface();
}

Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Slow down waves at night

Post by binder »

Haven't come up with anything yet. Is that solution working for you?

curt
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

I loaded it today, I'll let you know soon. Thanks!
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

It's not quite there yet. I checked it at 11 pm and there was a delay between alternating power heads, but the pulse (powerhead on) was about 100sec with a >200sec delay (powerheads off). After only an hour I'd expect it to have pulses at about 180sec with a 20sec delay. The delay would increase for the first 5 hours and the pulses decrease. Then it would pick up again for the next 5 hours. Here is my full code in case I'm missing something else. As always, thanks for the help!

Code: Select all

#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>
//Actinic and Daylight PMW are on the LED moonlights
byte ActinicPWMValue=0;
byte DaylightPWMValue=0;
byte wmport=Port5;
boolean wmdelay=false;
byte wmpulse=0;
#include <avr/pgmspace.h>
// Labels for the web banner
prog_char id_label[] PROGMEM = "jsclownfish";
prog_char probe1_label[] PROGMEM = "Tank";
prog_char probe2_label[] PROGMEM = "Room";
prog_char probe3_label[] PROGMEM = "Sump";
prog_char relay1_label[] PROGMEM = "Heater";
prog_char relay2_label[] PROGMEM = "Heater2";
prog_char relay3_label[] PROGMEM = "Halide";
prog_char relay4_label[] PROGMEM = "Actinic";
prog_char relay5_label[] PROGMEM = "WM1";
prog_char relay6_label[] PROGMEM = "WM2";
prog_char relay7_label[] PROGMEM = "Sump";
prog_char relay8_label[] PROGMEM = "Fan";
PROGMEM const char *webbanner_items[] = {
    id_label, probe1_label, probe2_label, probe3_label, relay1_label, relay2_label,
	relay3_label, relay4_label, relay5_label, relay6_label, relay7_label, relay8_label};
void setup()
{
  ReefAngel.Init();  //Initialize controller and start web banner timer
  ReefAngel.LoadWebBanner(pgm_read_word(&(webbanner_items[0])), SIZE(webbanner_items));
  ReefAngel.Timer[4].SetInterval(180);  // set interval to 180 seconds
  ReefAngel.Timer[4].Start();
  
  ReefAngel.FeedingModePorts = B00110000;
  ReefAngel.WaterChangePorts = B10110000;
  ReefAngel.OverheatShutoffPorts = B00000111;
  ReefAngel.LightsOnPorts = B00001100;
  ReefAngel.Relay.On(Port5);
  ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
  ReefAngel.Timer[1].Start();
  // Ports that are always on
  ReefAngel.Relay.On(Port7);
}
void loop()
{
  // Specific functions
  //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
  ReefAngel.StandardHeater(Port1,788,792);
  ReefAngel.StandardHeater(Port2,770,792);
  ReefAngel.MHLights(Port3,10,0,20,0,5);
  ReefAngel.StandardLights(Port4,9,0,21,0);
  ReefAngel.StandardFan(Port8,792,820);
  // Wavemaker Code with night option
  if (ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 22) || (hour() <= 8)) //from 10p-8a 
    {
      wmpulse=PWMSlope(22,0,8,0,30,170,255,30);
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(200-wmpulse);  // 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(wmpulse);  // short wave
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-10p normal wave settings
      ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      ReefAngel.Relay.Toggle(Port6);
    }
  }
  //Using Daylight ATO high signal piezo buzzer when temp exceeds 83F
if (ReefAngel.Params.Temp1>830) 
  {
  pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,HIGH);
  }
  else
  {pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,LOW);
  }
    //Moonlight=byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
   ReefAngel.PWM.SetActinic(ActinicPWMValue);
   ActinicPWMValue=PWMSlope(7,00,22,0,0,100,60,ActinicPWMValue); 
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
   DaylightPWMValue=PWMSlope(7,00,22,0,0,100,60,DaylightPWMValue);

// Web Banner stuff
    if(ReefAngel.Timer[4].IsTriggered())
    {
        ReefAngel.Timer[4].Start();
        ReefAngel.WebBanner();
    }


  ReefAngel.ShowInterface();
}

-Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Let me look into it some more
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Ok, after reviewing the code, I realized I was doing the opposite.
I was increasing the pulse from 30 to 170 within 255 minutes.
The delay is just the result of 200 - pulse, which mean 170 to 30 withint 255 minutes.
Then, it would stay at pulse 170 and delay 30 for around 30 minutes and finally the opposite for the next 255 minutes.
The reason of the flat 30minutes with no change is because we can only slope a max of 255 minutes.
Both ramps sum up 510minutes, but the entire night period is 9 hours = 540 minutes.
If you want to do the opposite, which is pulse of 170 to 30 within 255 minutes, I can change the logic.
Let me know which way you prefer.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

So in the middle section when the slope 'down' has run it's course, does the pattern hold steady at 30(R)-170(OFF)-30(L) and then start the slope build 'up' (shorter delays & longer pulses) until morning? I think that would work fine.

Thanks,
Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

Yes.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

I switched the code like you recommended and I think it works now. The Custom Main with the timer (I borrowed from another pde posted) has been really helpful in trying to 'time' the steps. However, when I try to change the clock to see how it behaves once the code is loaded, it goes way off and extends the time of the first step by as much as 10000sec. If I change the clock, then load the code it seems to work fine. Do I need something to reset it if I change the clock?
Thanks!
Jon

Code: Select all

#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>
#include <ReefAngel_Colors.h>
#include <ReefAngel_CustomColors.h>
//Actinic and Daylight PMW are on the LED moonlights
byte ActinicPWMValue=0;
byte DaylightPWMValue=0;
byte wmport=Port5;
boolean wmdelay=false;
byte wmpulse=0;
#include <avr/pgmspace.h>
// Labels for the web banner
prog_char id_label[] PROGMEM = "jsclownfish";
prog_char probe1_label[] PROGMEM = "Tank";
prog_char probe2_label[] PROGMEM = "Room";
prog_char probe3_label[] PROGMEM = "Sump";
prog_char relay1_label[] PROGMEM = "H1";
prog_char relay2_label[] PROGMEM = "H2";
prog_char relay3_label[] PROGMEM = "MH";
prog_char relay4_label[] PROGMEM = "Act";
prog_char relay5_label[] PROGMEM = "WM1";
prog_char relay6_label[] PROGMEM = "WM2";
prog_char relay7_label[] PROGMEM = "Main";
prog_char relay8_label[] PROGMEM = "Fan";
PROGMEM const char *webbanner_items[] = {
    id_label, probe1_label, probe2_label, probe3_label, relay1_label, relay2_label,
	relay3_label, relay4_label, relay5_label, relay6_label, relay7_label, relay8_label};
void DrawCustomMain()
{
// the graph is drawn/updated when we exit the main menu &
// when the parameters are saved
ReefAngel.LCD.DrawDate(6, 2);
ReefAngel.LCD.Clear(0, 1, 11, 132, 11);
pingSerial();
// Display the Tank temperature with color sensors
ReefAngel.LCD.DrawText(T1TempColor,DefaultBGColor,5,13,"TK:");
  if (ReefAngel.Params.Temp1>830) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp1, COLOR_RED, 23, 13, 10); 
  else if (ReefAngel.Params.Temp1>810) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp1, COLOR_ORANGE, 23, 13, 10); 
  else ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp1, COLOR_BLACK, 23, 13, 10);
// Display the Room temperature
ReefAngel.LCD.DrawText(T2TempColor,DefaultBGColor,5,23,"RM:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp2, 0, 23, 23, 10);
// Display the Sump temperature
ReefAngel.LCD.DrawText(T3TempColor,DefaultBGColor,5,33,"SP:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp3, 0, 23, 33, 10);
// Display the PH with color sensors
ReefAngel.LCD.DrawText(PHColor,DefaultBGColor, 64, 13,"PH:");
  if (ReefAngel.Params.PH>840 || ReefAngel.Params.PH<790) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_RED, 82, 13, 100);
  else if (ReefAngel.Params.PH>830 || ReefAngel.Params.PH<800) ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, COLOR_ORANGE, 82, 13, 100);
  else ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.PH, 0, 82, 13, 100);
// Display the % Moonlight
ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 64, 23,"MN:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(), 0, 82, 23, 1);
// Display arrows for Wavemaker
ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 64, 33,"WV:");
  if (bitRead(ReefAngel.Relay.RelayData,Port5)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 82, 33,"-->"); //port 5 on
  else if (bitRead(ReefAngel.Relay.RelayData,Port6)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 82, 33,"<--");  //port 6 on
  else ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 82, 33," O "); //port5 and port 6 off, wavemaker delay
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 45, TempRelay);
//#ifdef RelayExp
// draw 1st expansion relay
//TempRelay = ReefAngel.Relay.RelayDataE[0];
//TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
//TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
//ReefAngel.LCD.DrawOutletBox(12, 55, TempRelay);
//#endif // RelayExp
    int t=ReefAngel.Timer[1].Trigger-now();
    if (t>=0)
      ReefAngel.LCD.Clear(255,105,33,135,43);
      ReefAngel.LCD.DrawText(0, DefaultBGColor,105,33,t);
}
void DrawCustomGraph()
{
ReefAngel.LCD.DrawGraph(1, 75);
}
void setup()
{
  ReefAngel.Init();  //Initialize controller and start web banner timer
  ReefAngel.LoadWebBanner(pgm_read_word(&(webbanner_items[0])), SIZE(webbanner_items));
  ReefAngel.Timer[4].SetInterval(180);  // set interval to 180 seconds
  ReefAngel.Timer[4].Start();
  
  ReefAngel.FeedingModePorts = B00110000;
  ReefAngel.WaterChangePorts = B10110000;
  ReefAngel.OverheatShutoffPorts = B00000111;
  ReefAngel.LightsOnPorts = B00001100;
  ReefAngel.Relay.On(Port5);
  ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
  ReefAngel.Timer[1].Start();
  // Ports that are always on
  ReefAngel.Relay.On(Port7);
}
void loop()
{
  // Specific functions
  //1st Heater at 78.8, 2nd Heater at 77.0, MH on at 10AM off at 8PM, Actinics on at 9AM off at 9PM, Fan kicks on at 82.0
  ReefAngel.StandardHeater(Port1,788,792);
  ReefAngel.StandardHeater(Port2,770,792);
  ReefAngel.MHLights(Port3,10,0,20,0,5);
  ReefAngel.StandardLights(Port4,9,0,21,0);
  ReefAngel.StandardFan(Port8,792,820);
  // Wavemaker Code with night option
  if (ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 22) || (hour() <= 8)) //from 10p-9a 
    {  //PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, 
       // byte endPWM, byte Duration, byte oldValue)
      wmpulse=PWMSlope(22,0,8,0,30,170,255,30);
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(wmpulse);  // WM delay function from 30-170 sec.
        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(200-wmpulse);  // WM bursts timing from 170-30 sec.
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-10p normal wave settings
      ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      ReefAngel.Relay.Toggle(Port6);
    }
  }
  //Using Daylight ATO high signal piezo buzzer when temp exceeds 83F
  //other options are lowATOpin or the LED pins as ReefAngel.PWM.SetDaylight(100); else ReefAngel.PWM.SetDaylight(0); 
if (ReefAngel.Params.Temp1>830) 
  {
  pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,HIGH);
  }
  else
  {pinMode(highATOPin,OUTPUT);
  digitalWrite(highATOPin,LOW);
  }
    //Moonlight=byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
   ReefAngel.PWM.SetActinic(ActinicPWMValue);
   ActinicPWMValue=PWMSlope(7,00,22,0,0,100,60,ActinicPWMValue); 
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
   DaylightPWMValue=PWMSlope(7,00,22,0,0,100,60,DaylightPWMValue);
// Web Banner stuff
    if(ReefAngel.Timer[4].IsTriggered())
    {
        ReefAngel.Timer[4].Start();
        ReefAngel.WebBanner();
    }
  ReefAngel.ShowInterface();
}
Last edited by jsclownfish on Mon Nov 28, 2011 11:02 pm, edited 1 time in total.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

On your DrawCustomMain() function, you have this:

Code: Select all

    int t=ReefAngel.Timer[1].Trigger-now();
    if (t>=0)
      ReefAngel.LCD.Clear(255,105,33,135,43);
      ReefAngel.LCD.DrawText(0, DefaultBGColor,105,33,t);
Change it to this:

Code: Select all

    int t=ReefAngel.Timer[1].Trigger-now();
    if (t>=0)
    {
      ReefAngel.LCD.Clear(255,105,33,135,43);
      ReefAngel.LCD.DrawText(0, DefaultBGColor,105,33,t);
    }
    if (t>=300) ReefAngel.Timer[4].ForceTrigger();
That should force the timer to reset if it is greater than 300 sec.
Let me know if this works.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Slow down waves at night

Post by jsclownfish »

Thanks. That fixed the timer after changing the clock so I could get a better look at things. However, it seems to work fine until it reaches 00:00 (midnight). At that point the wave cycle resets to 170(R)-30(OFF)-170(L), up until that point it is making a gradual increase of the delay to about 93 sec and 77 sec pulses. The build side seems to work fine.

-Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Slow down waves at night

Post by rimai »

I guess I never thought of the PWM ramp crossing over from one day to another.
Let me think about a solution.
Roberto.
Post Reply