Trouble with setting multiple times for WP40 modes

Do you have a question on how to do something.
Ask in here.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

In your if blocks set a variable to represent the "mode" you are in. Then use the variable to display it on the screen, I do the same thing for my mp40s. Take a look at my ino in the sig and search for vtMode
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Hi Lee

Just when I was thinking I kind of understood... hahaha

So looking at your ino, I think the section you are talking about is this
void NextRFMode() {
vtMode++;

if (vtMode > 12) {
vtMode=0;
vtSpeed=50; // Constant
} else if (vtMode == 1) {
vtSpeed=40; // Lagoon
} else if (vtMode == 2) {
vtSpeed=45; // Reef Crest
} else if (vtMode == 3) {
vtSpeed=55; vtDuration=10; // Short Pulse
} else if (vtMode == 4) {
vtSpeed=55; vtDuration=20; // Long Pulse
} else if (vtMode == 5) {
vtSpeed=InternalMemory.read(Mem_B_NTMSpeed);
vtDuration=InternalMemory.read(Mem_B_NTMDuration); // Smart_NTM
} else if (vtMode == 6) {
vtSpeed=50; vtDuration=10; // Smart_TSM
} else if (vtMode == 7) {
vtSpeed=InternalMemory.read(Mem_B_NightSpeed);
vtDuration=InternalMemory.read(Mem_B_NightDuration);
vtMode=9; // Night
} else if (vtMode == 10) {
vtSpeed=65; vtDuration=5; // Storm
} else if (vtMode == 11) {
vtSpeed=45; vtDuration=10; // Custom
}
but I'm not sure how to apply that to non-RF based WP-40 (just using the SetDaylight and SetActinic to define my modes). What I think I need to do (based on what you said) is during my 6-11a hours call that block (1), 11-3 call that block (2), 3-6 call that block (3), 6-8 call that block (4), 8-11 call that block (5), and 11p-6a call that block (6).

And then I can make those 'blocks' call up a certain name on my menu display? I think that's what I got from it. but not sure on how to implement it. Any chance you could help me with one so I can work off of that and do the rest? Again, I want to learn this... teach a man to fish and all... but I'm nowhere close to even a pond, let alone a lake ;)

Also is the other part of what I'd want to do possible?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

Look at the vortech mode section in the DrawStatus() function. But yes you've got the idea exactly. Don't sell yourself short, it's just learning syntax, you seem to be following the concepts perfectly. What was the other thing?
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Having it skip the 3-6 NTM if I use feeding mode earlier, let's say at 1... it interrupts Reefcrest mode, would like when feeding mode goes off, for NTM to kick in right then. And then if NTM hasn't happened (as scheduled) Reefcrest (or other current mode) would continue.

Seems very complex and not necessarily needed. Was more just wondering if it COULD be done. Would be cool.
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

Let me try and find some time tomorrow to mock it up for you. Everything is doable!
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Thanks Lee! I work at nights, so I'll be reading along with all the other threads too. Might be a bit before I could implement though :)
Image
bhazard
Posts: 79
Joined: Mon Mar 11, 2013 11:25 am

Re: Trouble with setting multiple times for WP40 modes

Post by bhazard »

This is very helpful. Following.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

Ok, try this:

What I have done is moved the FEEDING_MODE check till after the time scheedule. The time schedule will set the default mode. During feeding mode we set a timer to the current time.
The block of code after feeding mode checks when that timer starts and runs that block of code that does the Nutrient mode for 3 hours after the feeding timer stops moving.

Then in the time schedule section, in the Nutrient mode, I added a check to see if that timer is more than a day old. If it is, it runs, otherwise your if block will fall down to the last else where you have SineMode.

If you want a different mode instead, you can add another else if with the same time frame without the timer check after the current one.

Code: Select all

#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

////// Place global variable code below here
byte wpMode;

////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port3Bit | Port7Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port3Bit | Port6Bit | Port7Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port4Bit | Port5Bit | Port8Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 830 );


    // Ports that are always on
    ReefAngel.Relay.On( Port2 );
    ReefAngel.Relay.On( Port4 );
    ReefAngel.Relay.On( Port5 );
    ReefAngel.Relay.On( Port6 );

    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
}

void loop()
{
    ReefAngel.StandardHeater( Port1,790,800 );
    ReefAngel.Relay.DelayedOn( Port3,4 );
    ReefAngel.StandardATO( Port7,250 );
    ReefAngel.StandardHeater( Port8,770,790 );
    ////// Place your custom code below here     
time_t feeding;

// Time schedule first
if (hour()>=6 && hour()<11) {
  ReefAngel.PWM.SetDaylight( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  ReefAngel.PWM.SetActinic( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  wpMode=1;
} else if (hour()>=11 && hour()<15) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if ( (hour()>=15 && hour()<18) && (now()-feeding > SECS_PER_DAY) ) { // We haven't fed today
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
  wpMode=3;
} else if (hour()>=18 && hour()<20) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if (hour()>=20 && hour ()<23) {
  ReefAngel.PWM.SetDaylight( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  ReefAngel.PWM.SetActinic( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  wpMode=1;
} else {
  ReefAngel.PWM.SetDaylight(SineMode(15,40,30,true) ); //SineMode from 15% to 40% for 30 seconds on sync mode
  ReefAngel.PWM.SetActinic(SineMode(15,40,30,true) ); //SineMode from 15% to 40% for 30 seconds on sync mode
  wpMode=4;    
}    

// If we are feeding override the schedule
if (ReefAngel.DisplayedMenu==FEEDING_MODE) {
  ReefAngel.PWM.SetDaylight(30); 
  ReefAngel.PWM.SetActinic(30); 
  wpMode=0;
  feeding=now();  
}
// If we have finished feeding, start NTM for 3 hours
if (now()-feeding < 3*SECS_PER_HOUR) {
ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
  wpMode=3;
}  
    ////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "markywmson" );
    ReefAngel.ShowInterface();
}
void DrawCustomMain()
{
  // Change the 30 to adjust the horizontal position of the text on the screen, max 20-21 chars
  ReefAngel.LCD.DrawText(DefaultFGColor, DefaultBGColor, 30, 2, "Mark's Reef");
  ReefAngel.LCD.DrawDate(6, 118);
  ReefAngel.LCD.DrawMonitor(15, 68, ReefAngel.Params,
                            ReefAngel.PWM.GetDaylightValue(), 
                            ReefAngel.PWM.GetActinicValue());
  
  // WP40 Mode
  int x, y;
  ReefAngel.LCD.DrawText(0,255,x,y,"RF:"); 
  ReefAngel.LCD.Clear(DefaultBGColor,x,y,128-x,y+8);
  if (wpMode == 0) ReefAngel.LCD.DrawText(COLOR_GREEN,255,x,y,"Feeding");
  else if (wpMode == 1) ReefAngel.LCD.DrawText(COLOR_MAGENTA,255,x,y,"Tidal Swell");
  else if (wpMode == 2) ReefAngel.LCD.DrawText(COLOR_GOLD,255,x,y,"Reef Crest");
  else if (wpMode == 3) ReefAngel.LCD.DrawText(COLOR_RED,255,x,y,"Nutrient");
  else if (wpMode == 4) ReefAngel.LCD.DrawText(COLOR_BLUE,255,x,y,"Sine Wave");
  
  
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 101, TempRelay);
}

void DrawCustomGraph()
{
  ReefAngel.LCD.DrawGraph(5, 11);
}
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Lee,

This is SO awesome! I can't wait to give it a try!! The only part of the logic I'm not currently following (mostly because I am seeing some new code I don't know the meaning of) is what I've quoted.
lnevo wrote:Then in the time schedule section, in the Nutrient mode, I added a check to see if that timer is more than a day old. If it is, it runs, otherwise your if block will fall down to the last else where you have SineMode.

If you want a different mode instead, you can add another else if with the same time frame without the timer check after the current one.
What I read from this is that when Feeding mode runs, it creates a timer and a timestamp in that timer. Then when NTM runs on schedule it checks the timer to see if wpMode=3 has run today. Now here is where I get a bit hazy... if Feeding mode HAS run I don't understand what the next mode is that will go.

Example... at 10am I go into Feeding mode. What happens next? The way I read it is that Reefcrest will pick up at 1pm, and then at 3 Sine mode starts. I'm confused by the "if block falling to the last else".

Thanks so much for your work on this and helping me to understand it Lee!
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

You have to add another 1-3pm for what mode you want if it already did NTM...right now it will "fall down" through the if else's to the last else which is sine mode.

If you look at the current 1-3pm if statement I added an addition check that the NTM hasn't been run for 24 hours
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

At 10am you feed. At 10:15 you come out of it. NTM runs for 3 hours and then back to regularly scheduled program.
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Ok, cool, I think I understand it now. So regularly scheduled program (reefcrest at 1:15-3) then what happens? Sine mode the rest of the day/night?

I may be missing something obvious here... It's been a long day at work ;)
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

Whatever your time schedule is set for... except for if you already did ntm mode then the scheduled ntm time will do the sine mode at the bottom.
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Ohhhhhhhhhhhhkay! I get it. So if NTM is done already, then Sine mode will go during the "scheduled" NTM mode (3-6p). Is there somewhere I can change that to have Reefcrest continue (instead of going to Sine)?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

Just put another else if right after the current one with what you want. Put the same times as the current one. Make sure it comes after the current one and it will be used instead of sine mode..
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

I was going to make it easier for you and then I also saw I made a slight error... the time_t feeding variable needs to either be global or static in order for it to maintain the state, otherwise every loop it would get re-initialized... here's the fix for that and also I modified it to address your last issue.

Enjoy.

Code: Select all

   ////// Place your custom code below here     
static time_t feeding;

// Time schedule first
if (hour()>=6 && hour()<11) {
  ReefAngel.PWM.SetDaylight( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  ReefAngel.PWM.SetActinic( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  wpMode=1;
} else if (hour()>=11 && hour()<15) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if ( (hour()>=15 && hour()<18) && (now()-feeding > SECS_PER_DAY) ) { // We haven't fed today
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
  wpMode=3;
} else if (hour()>=15 && hour()<18) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if (hour()>=18 && hour()<20) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if (hour()>=20 && hour ()<23) {
  ReefAngel.PWM.SetDaylight( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  ReefAngel.PWM.SetActinic( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  wpMode=1;
} else {
  ReefAngel.PWM.SetDaylight(SineMode(15,40,30,true) ); //SineMode from 15% to 40% for 30 seconds on sync mode
  ReefAngel.PWM.SetActinic(SineMode(15,40,30,true) ); //SineMode from 15% to 40% for 30 seconds on sync mode
  wpMode=4;    
}    

// If we are feeding override the schedule
if (ReefAngel.DisplayedMenu==FEEDING_MODE) {
  ReefAngel.PWM.SetDaylight(30); 
  ReefAngel.PWM.SetActinic(30); 
  wpMode=0;
  feeding=now();  
}
// If we have finished feeding, start NTM for 3 hours
if (now()-feeding < 3*SECS_PER_HOUR) {
ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
  wpMode=3;
}  
    ////// Place your custom code above here
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Great! Thanks so much Lee

Just to make sure I understand how this is functioning (I really appreciate you taking your time to do this and explain it!)... In the "Schedule" area, it functions as normal if Feeding mode is never activated. We added the 2nd else if from 1500-1800 (reefcrest) for when Feeding mode IS activated. This will allow the logic set by this

Code: Select all

// If we are feeding override the schedule if (ReefAngel.DisplayedMenu==FEEDING_MODE) {
  ReefAngel.PWM.SetDaylight(30); 
  ReefAngel.PWM.SetActinic(30); 
  wpMode=0;
  feeding=now();  
}
// If we have finished feeding, start NTM for 3 hours
if (now()-feeding < 3*SECS_PER_HOUR) {
ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
  wpMode=3;
} 
and this

Code: Select all

 else if ( (hour()>=15 && hour()<18) && (now()-feeding > SECS_PER_DAY) ) { // We haven't fed today
to skip the first line that is set for 1500-1800 (NTM scheduled).

So what happens if Feeding mode ISN'T run and there are 2 modes scheduled at the same timeframe? Does it default to the first one automatically, and disregard the 2nd one?

Do I kind of have it right? Again, thank you SOOO much for helping me understand this.
Image
Smotz
Posts: 412
Joined: Sat Mar 30, 2013 5:02 pm
Location: CT, USA

Re: Trouble with setting multiple times for WP40 modes

Post by Smotz »

lnevo wrote:Yes. exactly!

Dumb question - are all off the "IF / ELSE" statements needed?

Wouldn't it check for the condition - if true, action, if not true go to the next line.

for example - my code (sorry but somewhat related to this thread..)

Code: Select all

 // WAVE PATTERNS 
  else {
 // ReefAngel.PWM.SetDaylight( ReefCrestMode(55,20,false) ); // ReefCrest at 55% +/- 20% on sync mode     (MAX) 
      
if ( (hour() >= 5) && (hour() < 8) )  // from 5a - 8a
ReefAngel.PWM.SetDaylight( ReefCrestMode(45,16,false) );   

if ( (hour() >= 8) && (hour() < 11) )  // from 8a - 11a
ReefAngel.PWM.SetDaylight( ReefCrestMode(50,17,false) );   

if ( (hour() >= 11) && (hour() < 14) )  // from 11a - 2pm
ReefAngel.PWM.SetDaylight( ReefCrestMode(55,18,false) );  
      
if ( (hour() >= 14) && (hour() < 17) )  // from 2pm - 5pm
ReefAngel.PWM.SetDaylight( ReefCrestMode(50,17,false) );  

if ( (hour() >= 17) && (hour() < 20) )  // from 5pm - 8pm
ReefAngel.PWM.SetDaylight( ReefCrestMode(45,16,false) );  

if ( (hour() >= 20) && (hour() < 23) )  // from 8pm - 11p
ReefAngel.PWM.SetDaylight( ReefCrestMode(50,18,false) );  

if ( (hour() >= 23) && (hour() < 2) )  // from 11pm - 2am
ReefAngel.PWM.SetDaylight( ReefCrestMode(55,17,false) );  

if ( (hour() >= 2) && (hour() < 5) )  // from 2am - 5am
ReefAngel.PWM.SetDaylight( ReefCrestMode(50,17,false) );  

      // IF not in feeding mode, AND IF in night mode    
    //else {
      ////ReefAngel.PWM.SetDaylight(50); 
    //  ReefAngel.PWM.SetDaylight( SineMode(30,40,90,false) );  // Slow wave night mode
      
    //}
  }
  //  Only turn on UV Sterilizer between 11pm and 5am
  if ( (hour() >= 5) && (hour() < 23) )  // from 5a - 11p
  {
    ReefAngel.Relay.Off(UVlight);
  } 
  else {
    ReefAngel.Relay.On(UVlight);
  }

  ////// Place your custom code above here
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

It could be written a few ways....the behavior will vary depending on how its written and where you put the override logic.

In your case if any other if statements lower down qualify they will be picked up and override any previous matches.

In an if/else once the first if matches it will break out and no more matches will be checked.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

Mark,

We found a bug in the code as-written from another user using the same code. You need to switch the Nutrient Transport Mode and Feeding Mode sections. Otherwise feeding mode will never be activated because Nutrient Transport will happen instead.
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Ok, thanks Lee

I haven't had time to get in and update these, hopefully Sunday night. Work and my 5 month old twins and wife are keeping me busy busy. As soon as I can try this (hopefully with a beer in hand) I will report back.

Thanks again!

-mark
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

Nice...keep us posted. I couldn't imagine dealing with twins...my one month old is enough work all on his own.
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Still waiting to try this... but had another question as I was looking at graphs on the iPhone app (can't wait for the new one btw!)

If I see it correctly... TidalSwellMode ramps up to 45% from some other number. This works perfectly in the morning, but is there a way to inverse this, so it ramps down in the evening? Maybe I misunderstand this mode... (a distinct possibility)
Image
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

Hey Lee (or anyone else)

With all that custom stuff that was written for my WP40, with the new libraries, is that all old and outdated? Will it still work? Or do I have to make big changes to it?

-mark
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

You could leave it as is for now, it should still work. I dont know yet exactly how the new libraries are working. My guess would be we would have to modify it and we will no longer have to run the set daylight and pick what function to use, we will use SetMode lime we can do with rf
clw143
Posts: 118
Joined: Fri Jun 21, 2013 8:20 pm
Location: Louisiana

Re: Trouble with setting multiple times for WP40 modes

Post by clw143 »

Is there a reason I can't do this:

Code: Select all

  if (hour()>=8 && hour()<12) wp40mode=6;
  else if (hour()>=12 && hour()<17) wp40mode=2;
  else if (hour()>=17 && hour()<18) wp40mode=5;
  else if (hour()>=18 && hour()<24) wp40mode=2;
  else wp40mode=4;


  if (wp40mode=6) ReefAngel.DCPump.SetMode( TidalSwell,80,10 ); // Tidal Swell at 80%
  if (wp40mode=5) ReefAngel.DCPump.SetMode( NutrientTransport,70,10 ); // Nutrient Transport at 70% with 10ms pulse
  if (wp40mode=4) ReefAngel.DCPump.SetMode( LongPulse,60,10 ); // Long pulse at 60% with 10s pulse
  if (wp40mode=3) ReefAngel.DCPump.SetMode( ShortPulse,50,10 ); //Short pulse at 50% with 10ms pulse
  if (wp40mode=2) ReefAngel.DCPump.SetMode( ReefCrest,40,10 ); // ReefCrest at 40%
  if (wp40mode=1) ReefAngel.DCPump.SetMode( Lagoon,30,10 ); // Lagoon at 30%
  if (wp40mode=0) ReefAngel.DCPump.SetMode( Constant,20,10 ); // Constant at 20%
Instead of this:

Code: Select all

if (hour()>=6 && hour()<11) {
  ReefAngel.PWM.SetDaylight( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  ReefAngel.PWM.SetActinic( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  wpMode=1;
} else if (hour()>=11 && hour()<15) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if ( (hour()>=15 && hour()<18) && (now()-feeding > SECS_PER_DAY) ) { // We haven't fed today
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
  wpMode=3;
} else if (hour()>=15 && hour()<18) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if (hour()>=18 && hour()<20) {
  ReefAngel.PWM.SetDaylight( ReefCrestMode(70,20,true) ); // ReefCrest at 70% +/- 20% on sync mode
  ReefAngel.PWM.SetActinic( ReefCrestMode(70,20,false) ); // ReefCrest at 70% +/- 20% on anti-sync mode
  wpMode=2;
} else if (hour()>=20 && hour ()<23) {
  ReefAngel.PWM.SetDaylight( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  ReefAngel.PWM.SetActinic( TidalSwellMode(45,true) ); // TidalSwell at 45% on sync mode
  wpMode=1;
} else {
  ReefAngel.PWM.SetDaylight(SineMode(15,40,30,true) ); //SineMode from 15% to 40% for 30 seconds on sync mode
  ReefAngel.PWM.SetActinic(SineMode(15,40,30,true) ); //SineMode from 15% to 40% for 30 seconds on sync mode
  wpMode=4;    
}    
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Trouble with setting multiple times for WP40 modes

Post by rimai »

I think either way works.
The only thing I need to point out is that the code if (wp40mode=6) is not a comparison, it's a assignment statement.
You should use if (wp40mode==6)
http://arduino.cc/en/Reference/If
http://arduino.cc/en/Reference/Assignment
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

If your going to use DCPump.SetMode you also need to set UseMemory=false; and you may want an option to break out and use the options in the portal in which case you would need a case where you can do UseMemory=true;

ReefAngel.DCPump.UseMemory=false;
clw143
Posts: 118
Joined: Fri Jun 21, 2013 8:20 pm
Location: Louisiana

Re: Trouble with setting multiple times for WP40 modes

Post by clw143 »

rimai wrote:I think either way works.
The only thing I need to point out is that the code if (wp40mode=6) is not a comparison, it's a assignment statement.
You should use if (wp40mode==6)
http://arduino.cc/en/Reference/If
http://arduino.cc/en/Reference/Assignment
I'm confused, it seems to me this would be the assignment statement

Code: Select all

if (hour()>=8 && hour()<12) wp40mode==6;
and this is a comparison

Code: Select all

if (wp40mode=6) ReefAngel.DCPump.SetMode( TidalSwell,80,10 ); // Tidal Swell at 80%
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Trouble with setting multiple times for WP40 modes

Post by lnevo »

== is comparison

= is assignment
Post Reply