Page 1 of 1
PWMSlope
Posted: Wed Jul 04, 2012 11:14 am
by timmcq
Trying to set actinics to shut off at 1:30am, by using the following:
ReefAngel.PWM.SetActinic( PWMSlope(11,30,01,30,2,100,120,0) );
If I load that code in the afternoon, upon loading, my actinic driver is off.
If I load the following:
ReefAngel.PWM.SetActinic( PWMSlope(11,30,24,59,2,100,120,0) );
The actinic driver is on. This doesn't seem to make sense, as there isn't a 2459 (or 2430 for that matter)
So, what is the correct way to set ending times for early morning?
Re: PWMSlope
Posted: Wed Jul 04, 2012 2:07 pm
by rimai
The PWMSlope can't cross over to another day.
Try this:
http://forum.reefangel.com/viewtopic.ph ... 9&start=20
Re: PWMSlope
Posted: Wed Jul 04, 2012 7:57 pm
by timmcq
Looks complicated in order to turn off at 1:30
Re: PWMSlope
Posted: Thu Jul 05, 2012 2:48 pm
by timmcq
In the thread referenced, it looks like D0lph1n was trying to accomplish several things.
Is there a simple example of PWMSlope where lights are set ON before midnight and OFF after?
Thanks!
Re: PWMSlope
Posted: Thu Jul 05, 2012 3:06 pm
by timmcq
The Wizard can't handle this, correct?
Re: PWMSlope
Posted: Thu Jul 05, 2012 5:24 pm
by rimai
No, the wizard can't do that.
The PWMSlope function will not cross over to next day.
To do what you want, just use the function PWMSlopeOvernight() I posted in that thread.
Re: PWMSlope
Posted: Wed Jul 11, 2012 8:36 pm
by timmcq
I'm doing something wrong - Still turns off at midnight.
Does anyone have a simpler code example for use of PMWSlopeOvernight()?
Re: PWMSlope
Posted: Wed Jul 11, 2012 9:07 pm
by rimai
Not sure what you are doing.
It's just like the other one, except it is called PWMSlopeOvernight, instead of PWMSlope.
Code: Select all
ReefAngel.PWM.SetActinic( PWMSlopeOvernight(11,30,1,30,0,100,60,0) );
Re: PWMSlope
Posted: Thu Jul 12, 2012 5:42 pm
by timmcq
this is what i get:
sketch_12July:71: error: 'PWMSlopeOvernight' was not declared in this scope
Re: PWMSlope
Posted: Thu Jul 12, 2012 5:54 pm
by rimai
Oh, you have to add the function to the end of your code, just like the post in the above thread.
This is a non standard function.
Here is the function again:
Code: Select all
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+NumMins(startHour, startMinute);
unsigned long StartD = Start + Duration;
unsigned long End = nextMidnight(now())+NumMins(endHour, endMinute);
unsigned long StopD = End - Duration;
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: PWMSlope
Posted: Thu Jul 12, 2012 6:43 pm
by timmcq
i shouldnt need his If-Then-else logic though. i just loaded this code. did i get it right?
#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 <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 = Port5Bit | Port6Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 829 );
// Ports that are always on
ReefAngel.Relay.On( Port3 );
ReefAngel.Relay.On( Port4 );
ReefAngel.Relay.On( Port6 );
ReefAngel.Relay.On( Port8 );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.DosingPumpRepeat( Port1,0,60,10 );
ReefAngel.DosingPumpRepeat( Port2,5,60,10 );
ReefAngel.WavemakerRandom( Port5,60,100 );
ReefAngel.StandardLights( Port7,11,0,2,0 );
ReefAngel.PWM.SetDaylight( PWMSlope(12,30,23,30,0,100,90,0) );
ReefAngel.PWM.SetActinic( PWMSlopeOvernight(10,30,1,30,0,100,120,0) );
////// Place your custom code below here
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "name", "xxxx" );
ReefAngel.ShowInterface();
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+NumMins(startHour, startMinute);
unsigned long StartD = Start + Duration;
unsigned long End = nextMidnight(now())+NumMins(endHour, endMinute);
unsigned long StopD = End - Duration;
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: PWMSlope
Posted: Thu Jul 12, 2012 6:49 pm
by rimai
Exactly what I've been trying to say. Very simple.
I'm so sorry I didn't make it more clear

That looks good.
Try it out and let me know.
Re: PWMSlope
Posted: Thu Jul 12, 2012 9:02 pm
by timmcq
Well, it shut off at midnight again. I must be missing something.
Re: PWMSlope
Posted: Thu Jul 12, 2012 9:08 pm
by rimai
Let me look into it then.
Re: PWMSlope
Posted: Thu Jul 12, 2012 9:16 pm
by timmcq
Actinics turned off 0% at midnight, THEN 10-11 minutes later, came back on 100%.
I'm confused.
Re: PWMSlope
Posted: Fri Jul 13, 2012 10:09 am
by rimai
Sorry

I made a mistake... lol
In that post, there was a correction on the PWMSlopeOvernight function.
http://forum.reefangel.com/viewtopic.php?p=8905#p8905
So, use that code instead. I should've read the entire post.

Re: PWMSlope
Posted: Tue Jul 17, 2012 9:17 pm
by timmcq
Roberto,
Seems to work great now!
Tim
Re: PWMSlope
Posted: Tue Jul 17, 2012 9:20 pm
by rimai
Cool

PWMSlope
Posted: Thu Mar 21, 2013 4:55 am
by lnevo
Roberto,
I've modified the PWMSlopeOvernight function so it should work as a standard and overnight slope. Please take a look at the logic, if it's good perhaps you can make this the standard PWMSlope function
My moonrise/moon set times may be overnight and maybe standard, so to have one function to use simplifies a lot
Code: Select all
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte
endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+((unsigned long)NumMins(startHour, startMinute)*60);
unsigned long End = nextMidnight(now())+((unsigned long)NumMins(endHour, endMinute)*60);
boolean isOvernight=NumMins(startHour,startMinute)>NumMins(endHour,endMinute);
if (hour()<startHour && isOvernight) Start-=86400;
if (hour()<startHour || !isOvernight) End-=86400;
unsigned long StartD = Start + (Duration*60);
unsigned long StopD = End - (Duration*60);
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM,
endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM,
endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: PWMSlope
Posted: Thu Mar 21, 2013 7:46 am
by rimai
Awesome!!!
Does it work well?
Re: PWMSlope
Posted: Thu Mar 21, 2013 7:48 am
by rimai
Re: PWMSlope
Posted: Thu Mar 21, 2013 8:18 am
by lnevo
rimai wrote:Awesome!!!
Does it work well?
I don't know yet

It should...

PWMSlope
Posted: Fri Mar 22, 2013 5:19 am
by lnevo
Worked in overnight mode...

Re: PWMSlope
Posted: Fri Mar 22, 2013 4:10 pm
by lnevo
Regular usage worked. We now have a universal PWMSlope function... who wants to do the same for PWMParabola

Re: PWMSlope
Posted: Fri Mar 22, 2013 4:14 pm
by rimai
Awesome!!!

Re: PWMSlope
Posted: Mon Apr 01, 2013 1:02 pm
by lnevo