Random Wave Mode help

Do you have a question on how to do something.
Ask in here.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

Ok, added a couple things. Notices the pumps were running in sync, so added sync and anti sync in each profile and added duration for the modes that transition from and to night ( sine ) . seems to be working good so far. What unit of time is used for sine in the duration I set?

Code: Select all

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Sine, TidalSwell, LongPulse, Else, Sine, ReefCrest, Else };


if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<3600) {
  // after feed mode Continue NTM for the 60 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync;
} else if (now()%SECS_PER_DAY>=75600 || now()%SECS_PER_DAY<=32400) { // 9pm / 9am
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=Sine;
  ReefAngel.DCPump.Speed=35;
    ReefAngel.DCPump.Duration=600;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync;  
} else if (now()%SECS_PER_DAY>=32400 || now()%SECS_PER_DAY<=36000) { // 9am / 10am
  // Transition to random from Night  (go to Tidal Swell  100%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=Sine;
  ReefAngel.DCPump.Speed=100;
    ReefAngel.DCPump.Duration=400;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync;  
}else if (now()%SECS_PER_DAY>=68400 || now()%SECS_PER_DAY<=75600) { // 7pm / 9pm
  // Transition From random to night mode (go to Tidal Swell 100%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=Sine;
  ReefAngel.DCPump.Speed=100;
    ReefAngel.DCPump.Duration=400;
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync;  
}else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=100; 
  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync;  
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

You don't have to do the assignment if sync/antisync so many times. You can do it once before the if statement or even put it in setup.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

got ya. seems to be working. but has been coming up with reef crest everyday. should this work without connecting to it through the portal and set random everyday?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

I changed my randomizing frequency to every 6 hours because daily wasn't giving enough of a change :)
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

heres something I just noticed. ive tried two different variations of the code.

with this code it stays in tidal swell mode

Code: Select all

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Sine, TidalSwell, LongPulse, Else, Sine, ReefCrest, Else };


if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<3600) { //does it go to this after a feeding mode??
  // Continue NTM for the 60 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY>=75600 || now()%SECS_PER_DAY<=32400) { // 9pm / 9am
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=TidalSwell;
  ReefAngel.DCPump.Speed=35;
} else if (now()%SECS_PER_DAY>=32400 || now()%SECS_PER_DAY<=36000) { // 9am / 10am
  // Transition to random from Night  (go to Tidal Swell  100%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=TidalSwell;
  ReefAngel.DCPump.Speed=100;
}else if (now()%SECS_PER_DAY>=68400 || now()%SECS_PER_DAY<=75600) { // 7pm / 9pm
  // Transition From random to night mode (go to Tidal Swell 100%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=TidalSwell;
  ReefAngel.DCPump.Speed=100;
}else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=100; 
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
in this code it goes to random, but im trying to figure out how you stated above to change change rate to every 6 hours

Code: Select all

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Sine, TidalSwell, LongPulse, Else, Sine, ReefCrest, Else };


if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<3600) { //does it go to this after a feeding mode??
  // Continue NTM for the 60 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY>=75600 || now()%SECS_PER_DAY<=32400) { // 9pm / 9am
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=TidalSwell;
  ReefAngel.DCPump.Speed=35;
} else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=100; 
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

Are you seeding the random number generator? Otherwise it will pull the same random sequence every time you restart the controller
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

Thank you for such quick and helpful responses!

no im afraid with my lack of programming knowledge I wouldn't know how or where to do that.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

This is what I have in my setup() function.

randomSeed(now()/SECS_PER_DAY);

This gives it something to randomize against and since I'm doing it by day it will be the same if I reboot that day
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

any idea on why the code here would stay on sine instead of going to random ?

Code: Select all

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Sine, TidalSwell, LongPulse, Else, Sine, ReefCrest, Else };


if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<3600) { //does it go to this after a feeding mode??
  // Continue NTM for the 60 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY>=75600 || now()%SECS_PER_DAY<=32400) { // 9pm / 9am
  // Night mode (go to 30%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=TidalSwell;
  ReefAngel.DCPump.Speed=35;
} else if (now()%SECS_PER_DAY>=32400 || now()%SECS_PER_DAY<=36000) { // 9am / 10am
  // Transition to random from Night  (go to Tidal Swell  100%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=TidalSwell;
  ReefAngel.DCPump.Speed=100;
}else if (now()%SECS_PER_DAY>=68400 || now()%SECS_PER_DAY<=75600) { // 7pm / 9pm
  // Transition From random to night mode (go to Tidal Swell 100%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=TidalSwell;
  ReefAngel.DCPump.Speed=100;
}else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=100; 
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

Well there's only a 1 in 4 chance of it and second, it's going to be the same all day. Did you add the randomseed function. You can take out the / seconds per day part and it should be more random. Also know that the portal only updates every 5 minutes
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

Yes I added it in the void setup() area.

Currently I don't have access to the portal. I have not ordered my WiFi unit yet. Will that cause issues?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

No it won't cause issues. Just wasn't sure how you were monitoring the mode.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

Oh. I look on the screen when I remember.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

so in your thought theres no way to do what I was trying to do? which was

morning of sine 7am-9am
Afternoon of random 9am-8pm
evening of sine 7pm-9pm
and then nighttime mode 9pm-7am
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

Of course there is. We can do anything. Look at Steve's code (Sacohen) he's doing that I believe.
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

Haha. I love the confidence. that's one reason why I went with reefangel! this community is great.

Steve's seems to just go from night time to the random code. I tried it in my code, but it seems to just stay in sine mode.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

Ok...i also want to make sure it's changing for you or still staying sine
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

ok. I will keep an eye on it over the holidays and report back. heres the code im running. I change secs to hours. seems to be working right. Is this a reason for the time to be in seconds instead of hours?

Code: Select all

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;

// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { TidalSwell, ReefCrest, TidalSwell, Lagoon, Else, ReefCrest, Else, Lagoon };

  ReefAngel.DCPump.DaylightChannel = Sync;
  ReefAngel.DCPump.ActinicChannel = AntiSync; 
  
if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<1800) {
  // after feed mode Continue NTM for the 60 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;  

} 

else  if (hour()>=7 && hour()<9){ 
  //morning
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=300;
  ReefAngel.DCPump.Mode=Sine;
  ReefAngel.DCPump.Speed=100;
}
else if (hour()>=9 && hour()<19) { 
  //9am to 7pm
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=95; 
}
else  if (hour()>=19 && hour()<21){ 
  //7pm to 9pm
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=300;
  ReefAngel.DCPump.Mode=Sine;
  ReefAngel.DCPump.Speed=100;

}else  { // 9pm / 9am
  // Night mode 
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=500;
  ReefAngel.DCPump.Mode=Sine;
  ReefAngel.DCPump.Speed=40; 
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Random Wave Mode help

Post by lnevo »

You realize you hve the schedule all setup at the end. From 7pm to 9am you are forcing sine mode. The only time you are using the random mode is between 9am and 7pm
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

yes sir. I think that's what I was trying to do. just not sure if I did it right

this is how im seeing it in my mind :

7am-9am - sine wave (ramping up to the random mode)
9am-7pm - RANDOM
7pm-9pm - sine wave (ramping down from the random mode)
rest of the night sine wave at 40%
slm222
Posts: 105
Joined: Wed Nov 18, 2015 9:16 pm

Re: Random Wave Mode help

Post by slm222 »

everything seems to be working the way I want it to. they only thing I notice that's off is sometimes it doesn't display anything on the reef angel screen, as far as what wave mode its in, it just has asterisk or "x"s blinking across where the wave should be.
Post Reply