Moonrise/set

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Moonrise/set

Post by jsclownfish »

If I want to have the moon rise and set as the main lights cycle off, I tried this code to increase the moonlight signal up to the current moonphase at 10 pm, stay on over night at monphase levels and to fade away at 7 am. However, it must not be quite right, when I change the times it doesn't sync up. BTW, I have these moonlights connected to the actinic and daylight connections on the relay box.
-Jon

Code: Select all

//Moonlight=byte PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
   ReefAngel.PWM.SetActinic(ActinicPWMValue);
   ActinicPWMValue=PWMSlope(22,00,7,00,0,MoonPhase(),60,ActinicPWMValue); 
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
   DaylightPWMValue=PWMSlope(22,00,7,00,0,MoonPhase(),60,DaylightPWMValue);
Last edited by jsclownfish on Sun Mar 25, 2012 7:51 am, edited 1 time in total.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Moonrise/set

Post by binder »

First note, you will want to get the value before you set the PWM.

Code: Select all

   ActinicPWMValue=PWMSlope(22,00,7,00,0,MoonPhase(),60,ActinicPWMValue); 
   ReefAngel.PWM.SetActinic(ActinicPWMSlope);
   DaylightPWMValue=PWMSlope(22,00,7,00,0,MoonPhase(),60,DaylightPWMValue);
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
I'm not sure how well PWMSlope works crossing over midnight. It may have to be broken into 2 groups with an IF statement:

Code: Select all

if ( hour() >= 22 && hour() <= 23 )
{
   // from 22:00 to 23:59
   ActinicPWMValue=PWMSlope(22,0,23,59,0,MoonPhase(),0,ActinicPWMValue); 
   ReefAngel.PWM.SetActinic(ActinicPWMSlope);
   DaylightPWMValue=PWMSlope(22,0,23,59,0,MoonPhase(),0,DaylightPWMValue);
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
} else if ( hour() >= 0 && hour() < 7 )
{
   // from 00:00 to 6:59
   ActinicPWMValue=PWMSlope(0,0,7,0,0,MoonPhase(),0,ActinicPWMValue); 
   ReefAngel.PWM.SetActinic(ActinicPWMSlope);
   DaylightPWMValue=PWMSlope(0,0,7,0,0,MoonPhase(),0,DaylightPWMValue);
   ReefAngel.PWM.SetDaylight(DaylightPWMValue);
}
I took out the duration because I'm not quite sure how well it would work in those regards.

This is only a framework / start to solving the problem. More thought will need to be put into it. Bottom line, you will need to do the slope in 2 pieces....1 up to midnight and the other from midnight to your end time. The tricky part is to get the slope working. Maybe this will spark some ideas for you or others.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moonrise/set

Post by rimai »

How about this:
Above setup():

Code: Select all

byte MoonPWMValue;
Inside loop():

Code: Select all

  MoonPWMValue=MoonPhase();
  if (hour()==22 || hour()==6)
     MoonPWMValue=PWMSlope(22,00,7,00,0,MoonPhase(),60,0);
  if (ReefAngel.Relay.Status(Port1)) MoonPWMValue=0;
  ReefAngel.PWM.SetActinic(MoonPWMValue);
  ReefAngel.PWM.SetDaylight(MoonPWMValue);
Just chage the Port1 to whatever port you are using for your main lights.
Basically what the code does is assign MoonPhase() to the MoonPWMValue variable.
If it is time to slope, it will override with the PWMSlope() function.
It main lights are on, it will override with 0.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Moonrise/set

Post by jsclownfish »

Thanks! I'll give it a try. I remember now running into this with the idea of gradually slowing down the waves at night. I had problems then with crossing over midnight. http://forum.reefangel.com/viewtopic.ph ... 8&start=30 I think I just ended the slope before midnight. In this case, I thought that would work as well as long as the slope up and down (60 minutes) didn't cross over midnight.

I'll let you know how it goes...

-Jon
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Moonrise/set

Post by binder »

rimai wrote:How about this:
Above setup():

Code: Select all

byte MoonPWMValue;
Inside loop():

Code: Select all

  MoonPWMValue=MoonPhase();
  if (hour()==22 || hour()==6)
     MoonPWMValue=PWMSlope(22,00,7,00,0,MoonPhase(),60,0);
  if (ReefAngel.Relay.Status(Port1)) MoonPWMValue=0;
  ReefAngel.PWM.SetActinic(MoonPWMValue);
  ReefAngel.PWM.SetDaylight(MoonPWMValue);
Just chage the Port1 to whatever port you are using for your main lights.
Basically what the code does is assign MoonPhase() to the MoonPWMValue variable.
If it is time to slope, it will override with the PWMSlope() function.
It main lights are on, it will override with 0.
Nice. Very simple and concise. That should work great.
User avatar
JNieuwenhuizen
Posts: 96
Joined: Thu Feb 16, 2012 12:39 am
Location: South Africa

Re: Moonrise/set

Post by JNieuwenhuizen »

Nice little code Roberto.

I Have a question - if I have no lighs, only PWM channels, how would I change this?

I had this in mind :

Code: Select all

      MoonPWMValue=MoonPhase();
  if (hour()==22 || hour()==8)
     MoonPWMValue=PWMSlope(22,0,8,0,0,45,24,MoonPWMValue);
  if (ReefAngel.PWM.Expansion[LEDPWM0]) MoonPWMValue=0;
  ReefAngel.PWM.Expansion[LEDPWM0](MoonPWMValue);
  ReefAngel.PWM.Expansion[LEDPWM1](MoonPWMValue);
  ReefAngel.PWM.Expansion[LEDPWM2](MoonPWMValue);
  ReefAngel.PWM.Expansion[LEDPWM3](MoonPWMValue);
But it does not like - if (ReefAngel.PWM.Expansion[LEDPWM0]) MoonPWMValue=0;
LEDPWM0 will be main lights
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moonrise/set

Post by rimai »

Code: Select all

  MoonPWMValue=MoonPhase();
  if (hour()==22 || hour()==6)
     MoonPWMValue=PWMSlope(22,00,7,00,0,MoonPhase(),60,0);
  if (ReefAngel.PWM.ExpansionChannel[0]) MoonPWMValue=0;
  ReefAngel.PWM.SetChannel(4,MoonPWMValue);
Roberto.
Post Reply