PWMSlope
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
PWMSlope
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?
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?
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: PWMSlope
The PWMSlope can't cross over to another day.
Try this:
http://forum.reefangel.com/viewtopic.ph ... 9&start=20
Try this:
http://forum.reefangel.com/viewtopic.ph ... 9&start=20
Roberto.
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
Looks complicated in order to turn off at 1:30
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
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!
Is there a simple example of PWMSlope where lights are set ON before midnight and OFF after?
Thanks!
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
The Wizard can't handle this, correct?
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: PWMSlope
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.
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.
Roberto.
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
I'm doing something wrong - Still turns off at midnight.
Does anyone have a simpler code example for use of PMWSlopeOvernight()?
Does anyone have a simpler code example for use of PMWSlopeOvernight()?
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: PWMSlope
Not sure what you are doing.
It's just like the other one, except it is called PWMSlopeOvernight, instead of PWMSlope.
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) );
Roberto.
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
this is what i get:
sketch_12July:71: error: 'PWMSlopeOvernight' was not declared in this scope
sketch_12July:71: error: 'PWMSlopeOvernight' was not declared in this scope
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: PWMSlope
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:
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;
}
Roberto.
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
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;
}
#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;
}
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: PWMSlope
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.
I'm so sorry I didn't make it more clear
That looks good.
Try it out and let me know.
Roberto.
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
Well, it shut off at midnight again. I must be missing something.
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
Actinics turned off 0% at midnight, THEN 10-11 minutes later, came back on 100%.
I'm confused.
I'm confused.
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: PWMSlope
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.
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.
Roberto.
-
timmcq
- Posts: 46
- Joined: Tue Jun 05, 2012 6:24 pm
Re: PWMSlope
Roberto,
Seems to work great now!
Tim
Seems to work great now!
Tim
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
PWMSlope
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
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;
}
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: PWMSlope
I don't know yetrimai wrote:Awesome!!!
Does it work well?
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: PWMSlope
Regular usage worked. We now have a universal PWMSlope function... who wants to do the same for PWMParabola 
- lnevo
- Posts: 5422
- Joined: Fri Jul 20, 2012 9:42 am
Re: PWMSlope
Thanks thekameleon for a PWMParabola version...
http://forum.reefangel.com/viewtopic.php?p=23120#p23120
http://forum.reefangel.com/viewtopic.php?p=23120#p23120