Moonphase calculation
-
- Posts: 69
- Joined: Thu Jun 02, 2011 1:58 pm
Re: Moonphase calculation
lol, yup simple, or so i think. lol. so plug the moonlight code into the pde at the bottom right? then just call that function in the loop? also what about comp. with the inverted pucks?
Re: Moonphase calculation
I did something similar to that, but I added in another PWMSlope to get it to fade down to the moonlight value. I think this should work.rimai wrote:Best way to do that and avoid the flickering is to use an if statement to check for time.
Something like this:The above code uses the MoonPhase calculation from 8pm to 9am and the PWMSlope otherwise.Code: Select all
if (hour()>20 && hour()<9) { ReefAngel.PWM.SetActinic(MoonPhase()/10); } else { ReefAngel.PWM.SetActinic(PWMSlope(9,0,20,0,15,100,60,ReefAngel.PWM.GetActinicValue())); }
The division by 10 would reduce the calculation by a factor of 10, which would cause full moon to drive the LEDs at 10%. You can choose your own value if 10% is too much.
Let me know if this works for you.
Code: Select all
if(hour() >= 18) {
ReefAngel.PWM.SetActinic(PWMSlope(11,0,18,0,70,(100-(MoonPhase()/10)),120,ReefAngel.PWM.GetActinicValue()));
} else {
ReefAngel.PWM.SetActinic(PWMSlope(11,0,20,0,100,70,120,ReefAngel.PWM.GetActinicValue()));
}
Re: Moonphase calculation
It is still wrong.
Both SetActinic Statement still has inverted slope values. You can't use start value of 100 and end value of 70.
In your case, you have to set the PWMSlope to go from 0 to 30%, just like any other meanwell user would do.
Then, use math to invert the values. Simply use 100 - PWM value to invert it.
So, you code should look something like this:
Let me know of this works.
Both SetActinic Statement still has inverted slope values. You can't use start value of 100 and end value of 70.
In your case, you have to set the PWMSlope to go from 0 to 30%, just like any other meanwell user would do.
Then, use math to invert the values. Simply use 100 - PWM value to invert it.
So, you code should look something like this:
Code: Select all
if(hour() >= 18) {
ReefAngel.PWM.SetActinic(100-PWMSlope(11,0,18,0,0,MoonPhase()/10,120,ReefAngel.PWM.GetActinicValue()));
} else {
ReefAngel.PWM.SetActinic(100-PWMSlope(11,0,20,0,0,30,120,ReefAngel.PWM.GetActinicValue()));
}
Roberto.
Re: Moonphase calculation
does this function need to be placed in the libraries to replace the existing function:
If so, it would be simple for me to remove the above function and then just add the Moonlight function (that is at the beginning of this post) to the libraries so it could be utilized.
curt
Code: Select all
void ReefAngelClass::MoonlightPWM(byte RelayID, bool ShowPWM)
curt
Re: Moonphase calculation
I think you can leave the old one in there and just add the new one. If not used, it won't get included in the compiled file anyway.
Although they seem to do same thing, they really don't. The new MoonPhase() doesn't do anything but the calculation of the %. Then, with this number, you can add it to whatever channel you have your moonlights on. The previous one was linked to one of the ATO pins and was watching for a relay status change, which was too complicated. I still use it though
Although they seem to do same thing, they really don't. The new MoonPhase() doesn't do anything but the calculation of the %. Then, with this number, you can add it to whatever channel you have your moonlights on. The previous one was linked to one of the ATO pins and was watching for a relay status change, which was too complicated. I still use it though
Roberto.
Re: Moonphase calculation
Ok cool. Then I'll plan on adding this one in to the globals file so it will be a generic function (which is appears to be).
curt
curt
Re: Moonphase calculation
This function has been added to the Globals file and will be a global function in the upcoming 0.8.5.17 release. You will be able to use it exactly like the examples are in this topic.
curt
curt
-
- Posts: 97
- Joined: Wed Jul 06, 2011 6:45 am
Re: Moonphase calculation
Could you elaborate on the programming for this? When I tried this, my moonlights didn't come on.
Does this basically start the % at 0, and then over the course of the month, ramp up to 100% than back down to 0%?
Here is my PDE:
// Autogenerated file by RAGen (v1.0.4.92), (09/09/2011 07:48)
// RA_090911_0748.pde
//
// This version designed for v0.8.5 Beta 12 or later
/* The following features are enabled for this PDE File:
#define DisplayImages
#define WavemakerSetup
#define DateTimeSetup
#define VersionMenu
#define MetalHalideSetup
#define DirectTempSensor
#define DisplayLEDPWM
#define StandardLightSetup
#define RelayExp
*/
#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>
byte MoonPhase()
{
int m,d,y;
int yy,mm;
long K1,K2,K3,J,V;
byte PWMvalue;
m=month();
d=day();
y=year();
yy=y-((12-m)/10);
mm=m+9;
if (mm>=12) mm-=12;
K1=365.25*(yy+4712);
K2=30.6*mm+.5;
K3=int(int((yy/100)+49)*.75)-38;
J=K1+K2+d+59-K3;
V=(J-2451550.1)/0.29530588853;
V-=int(V/100)*100;
V=abs(V-50);
PWMvalue=4*abs(50-V); // 5.12=100% 4=~80%
//pinMode(lowATOPin,OUTPUT);
return (PWMvalue*100)/255;
}
void setup()
{
ReefAngel.Init(); //Initialize controller
ReefAngel.FeedingModePorts = B00011000;
ReefAngel.WaterChangePorts = B00011000;
ReefAngel.WaterChangePortsE[0] = B11000000;
ReefAngel.OverheatShutoffPorts = B11000100;
ReefAngel.LightsOnPorts = B00000011;
// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Box1_Port1);
ReefAngel.Relay.On(Box1_Port4);
}
void loop()
{
ReefAngel.ShowInterface();
// Specific functions
ReefAngel.MHLights(Port1);
ReefAngel.MHLights(Port2);
ReefAngel.Wavemaker1(Port4);
ReefAngel.Wavemaker2(Port5);
ReefAngel.StandardHeater(Port6);
ReefAngel.StandardLights(Box1_Port3);
ReefAngel.DelayedOn(Box1_Port2, 2);
if (hour()>22 && hour()<9)
{
ReefAngel.PWM.SetActinic(MoonPhase());
ReefAngel.PWM.SetDaylight(MoonPhase());
}
}
Does this basically start the % at 0, and then over the course of the month, ramp up to 100% than back down to 0%?
Here is my PDE:
// Autogenerated file by RAGen (v1.0.4.92), (09/09/2011 07:48)
// RA_090911_0748.pde
//
// This version designed for v0.8.5 Beta 12 or later
/* The following features are enabled for this PDE File:
#define DisplayImages
#define WavemakerSetup
#define DateTimeSetup
#define VersionMenu
#define MetalHalideSetup
#define DirectTempSensor
#define DisplayLEDPWM
#define StandardLightSetup
#define RelayExp
*/
#include <ReefAngel_Features.h>
#include <ReefAngel_Globals.h>
#include <ReefAngel_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <ReefAngel_EEPROM.h>
#include <ReefAngel_NokiaLCD.h>
#include <ReefAngel_ATO.h>
#include <ReefAngel_Joystick.h>
#include <ReefAngel_LED.h>
#include <ReefAngel_TempSensor.h>
#include <ReefAngel_Relay.h>
#include <ReefAngel_PWM.h>
#include <ReefAngel_Timer.h>
#include <ReefAngel_Memory.h>
#include <ReefAngel.h>
byte MoonPhase()
{
int m,d,y;
int yy,mm;
long K1,K2,K3,J,V;
byte PWMvalue;
m=month();
d=day();
y=year();
yy=y-((12-m)/10);
mm=m+9;
if (mm>=12) mm-=12;
K1=365.25*(yy+4712);
K2=30.6*mm+.5;
K3=int(int((yy/100)+49)*.75)-38;
J=K1+K2+d+59-K3;
V=(J-2451550.1)/0.29530588853;
V-=int(V/100)*100;
V=abs(V-50);
PWMvalue=4*abs(50-V); // 5.12=100% 4=~80%
//pinMode(lowATOPin,OUTPUT);
return (PWMvalue*100)/255;
}
void setup()
{
ReefAngel.Init(); //Initialize controller
ReefAngel.FeedingModePorts = B00011000;
ReefAngel.WaterChangePorts = B00011000;
ReefAngel.WaterChangePortsE[0] = B11000000;
ReefAngel.OverheatShutoffPorts = B11000100;
ReefAngel.LightsOnPorts = B00000011;
// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Box1_Port1);
ReefAngel.Relay.On(Box1_Port4);
}
void loop()
{
ReefAngel.ShowInterface();
// Specific functions
ReefAngel.MHLights(Port1);
ReefAngel.MHLights(Port2);
ReefAngel.Wavemaker1(Port4);
ReefAngel.Wavemaker2(Port5);
ReefAngel.StandardHeater(Port6);
ReefAngel.StandardLights(Box1_Port3);
ReefAngel.DelayedOn(Box1_Port2, 2);
if (hour()>22 && hour()<9)
{
ReefAngel.PWM.SetActinic(MoonPhase());
ReefAngel.PWM.SetDaylight(MoonPhase());
}
}
Re: Moonphase calculation
Basically, this code will only turn moonlights on between 11pm and 8am.
Also, the moonphase is calculated according to the cycle of the moon. The cycle is somewhere around of 29days, where new moon would output 0% and full moon would output 100%.
In the code above, the % should be displayed in the RA screen too. Both AP and DP should show the % of intensity.
Also, the moonphase is calculated according to the cycle of the moon. The cycle is somewhere around of 29days, where new moon would output 0% and full moon would output 100%.
In the code above, the % should be displayed in the RA screen too. Both AP and DP should show the % of intensity.
Roberto.
Re: Moonphase calculation
I have found that this statement does not work as expected:
if (hour()>22 && hour()<9)
{
ReefAngel.PWM.SetActinic(MoonPhase());
ReefAngel.PWM.SetDaylight(MoonPhase());
}
My moonlights were on all the time.
To make my moonlights turn on at 7PM and turn off at 7AM I found:
Added this code to the setup to turn them off by default (power failure etc.):
// Set Actinic and Daylight off by default
ReefAngel.PWM.SetActinic(0);
ReefAngel.PWM.SetDaylight(0);
And then added this code to the loop function:
if ( hour() <= 6 || hour () >= 19 ) // Moonlights on from 7PM to 7AM
{
ReefAngel.PWM.SetActinic(MoonPhase());
ReefAngel.PWM.SetDaylight(MoonPhase());
}
else
{
ReefAngel.PWM.SetActinic(0);
ReefAngel.PWM.SetDaylight(0);
}
if (hour()>22 && hour()<9)
{
ReefAngel.PWM.SetActinic(MoonPhase());
ReefAngel.PWM.SetDaylight(MoonPhase());
}
My moonlights were on all the time.
To make my moonlights turn on at 7PM and turn off at 7AM I found:
Added this code to the setup to turn them off by default (power failure etc.):
// Set Actinic and Daylight off by default
ReefAngel.PWM.SetActinic(0);
ReefAngel.PWM.SetDaylight(0);
And then added this code to the loop function:
if ( hour() <= 6 || hour () >= 19 ) // Moonlights on from 7PM to 7AM
{
ReefAngel.PWM.SetActinic(MoonPhase());
ReefAngel.PWM.SetDaylight(MoonPhase());
}
else
{
ReefAngel.PWM.SetActinic(0);
ReefAngel.PWM.SetDaylight(0);
}
_____
Jim
Jim
Re: Moonphase calculation
Yes, it was a typo that I made. I fixed it on my previous post too.
Thanks for your help!!!
Thanks for your help!!!
Roberto.