Trouble with setting multiple times for WP40 modes

Do you have a question on how to do something.
Ask in here.
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Trouble with setting multiple times for WP40 modes

Post by markywmson »

Hi there

I've done some research and found something that mostly worked for me, and tried modding it to my needs, but I'm clearly missing something, as when I try to verify I get errors. Here is my code
    ////// Place your custom code below here
   {
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
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
else if (hour()>=15 && hour()<18)
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
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
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
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
    }    

    ////// Place your custom code above here
So what I'm trying to do is have from 6a-11a tidal swell, 11a-3p reefcrest, 3p-6p nutrient transport, 6p-8p reefcrest, 8p-11p tidal swell, and 11p-6a sine mode.

It says in the error, else without previous if. Does that mean all those need to be if instead of else if? The code I grabbed had else if.

Also can't figure out how to add if feeding mode ReefAngel.PWM.SetDaylight (20) and ReefAngel.PWM.SetActinic (20)

Thanks for any help!

-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 »

They need curly braces around each block...you can only leave off the curly braces if there is only one line after the if else...

Code: Select all

if (condition) {
  action1();
  action2(); 
} else if (condition) {
  action1();
  action2();
}
What you have works only without action2();

Also you seem to have a dangling } doing nothing...
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

So I would want it to look like this?
    ////// Place your custom code below here
   
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
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
else if (hour()>=15 && hour()<18) {
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
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
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
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
    }    

    ////// Place your custom code above here
It compiled so I assume it would be good. What (and where) would I put the if feedmode?
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 »

As the first condition at the beginning or a separate check afterwards.
jjdezek
Posts: 329
Joined: Fri May 17, 2013 1:35 pm

Re: Trouble with setting multiple times for WP40 modes

Post by jjdezek »

Not trying to hijack your thread but I was wondering if those modes can be made to where you can manually switch between them? Like right before a water change switch it to nutrient export?
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 »

Sure. I have a post in the long jaebo thread on using the vortech memory locations to switch the wave patterns. I use mp40s but you can look at my INO file. I have a custom menu and one of the items cycles through the modes with a button press.
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

So adding it above would look something like this? Do I need to change the second if to "else if"?
    ////// Place your custom code below here

if display=feeding mode etc... {
}
   
:?: else :?: 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
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
else if (hour()>=15 && hour()<18) {
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
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
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
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
    }    

    ////// Place your custom code above here
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 »

Yes. exactly!
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 will try it tonight (after the boys go to bed) and report back.
Image
markywmson
Posts: 51
Joined: Wed Feb 27, 2013 11:35 am

Re: Trouble with setting multiple times for WP40 modes

Post by markywmson »

So here is my full code. So far seems to work well. Haven't gotten around to implementing ATO, but that will need to be done in the next week, as I'll be out of town for 5 days at the end of June.

The Feeding Mode add worked as expected and something that I've found very awesome is being able to control relay 5 manually via my iphone app, thus negating the need for 3 hands while holding the hose from a pump to do water changes, plug it in, and not spray everything! (continuing after code)

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


////// 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     
if (ReefAngel.DisplayedMenu==FEEDING_MODE) {
  ReefAngel.PWM.SetDaylight(30); 
  ReefAngel.PWM.SetActinic(30);       
    }   
else 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
} 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
} else if (hour()>=15 && hour()<18) {
  ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,60,6000,true) );
  ReefAngel.PWM.SetActinic( NutrientTransportMode(30,60,6000,false) );
} 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
} 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
} 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
    }    

    ////// 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);
  pingSerial();
  ReefAngel.LCD.DrawMonitor(15, 68, ReefAngel.Params,
                            ReefAngel.PWM.GetDaylightValue(), 
                            ReefAngel.PWM.GetActinicValue());
  pingSerial();
  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);
}

So my next quest on the powerhead portion of this would be 2 things. 1) since I have all those modes 'timelined' to happen at different times, is there a way to display that on the RA controller? (I'm sure the iphone app isn't there yet... I can see the different modes in the graph though). 2) is there a way to make it follow this logic...

-Sine mode overnight
-Tidal Swell in AM
-Reefcrest in early afternoon
-NTM in mid afternoon
-Reefcrest in late afternoon
-Tidal swell in PM
-Sine mode overnight

--> FEEDING MODE interrupts this timeline and sets power at 30 constant. //up to here my code is fine
--> Following FEEDING MODE interrupt the timeline with NTM for 3 hours, then resume timeline.
-->caveat... if this happens before NTM hits in the timeline (3p-6p), could the RA skip that NTM and
continue Reefcrest?

Thanks for any help! I'm actually starting to (kinda, sorta) understand this. Still can't write the code, but can steal and modify :)

-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 »

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.
Post Reply