Moon rise/set implementation

Share you PDE file with our community
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Mar 23, 2013 8:01 am
17:13 to 5:29 for today's schedule...

looks good so far :)

Posts: 137
Joined: Sat Feb 16, 2013 7:44 am
PostPosted: Sun Mar 31, 2013 1:26 am
Not sure if you had updated the code attached. The isRise was true outside the rise to set time range. I tried to figure out what is going on, but I got lost quickly with the code as I could not figure out the meaning of the variables. So I went ahead and use a PMWParabola function with the rise and set times, which is working so far... Do you have an updated code file?
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Apr 01, 2013 7:01 am
The isRise variable I believe is only used during the test_moon() function. This is why I stopped using it also and did the same thing as you. The issue though, I don't know if the parabola works properly when spanning over midnight. I used a previously published PWMSlopeOvernight which I have modified to work either overnight or not overnight. It should end up in the libraries next update I believe. Is the parabola working properly for you?
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Apr 01, 2013 7:05 am
Btw, the last code I posted has been updated to the latest and is complete. I haven't done any work on it and it looks like it's working properly. The time is 3 hours off from the coordinates that I am testing with but it could be because we do not really do any time zone on the RA. and the place I have is -3 from GMT... anyway, please test and if you have improvements, I'm all for it. I don't know enough of what's going on and spent like 3 days reading the code to really start tinkering and changing it around. I now have a variable rise/set that matches a moon cylce so I'm happy :)

Posts: 137
Joined: Sat Feb 16, 2013 7:44 am
PostPosted: Mon Apr 01, 2013 11:26 am
I'd just like to understand the variable names and what it all means. I haven't seen the PWMSlopeOvernight function, but I wrote this to drive my moon lights.

Code: Select all
      byte moonPhase = MoonPhase();
      byte moonPWM = 0;
      if(moonPhase > 0)
        moonPWM = PWMParabola(Moon.riseH, Moon.riseM, Moon.setH, Moon.setM, 10, ((moonPhase / 10) + 11), 0);


My question is around MoonPhase and if I am using it right. It appears the value is an index or in this case 0 - 100, so when it returns 1, I should have the lowest value (dimmest light). Knowing that my MeanWell drivers don't turn on until a value of 11 is sent to them. I adjusted the index according (hence the adding of 11).
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Apr 01, 2013 11:30 am
Yeah. I just don't know that the PWMParabola function will work properly when PM -> AM versus AM->PM. There was an issue with this in the PWMSlope and so a PWMSlopeOVernight was written. Moving forward there will be one PWMSlope function, but again, not sure on the parabola.

You have the moonphase and params correct it looks like.

Posts: 137
Joined: Sat Feb 16, 2013 7:44 am
PostPosted: Mon Apr 01, 2013 12:50 pm
I think this should do it:

Code: Select all
byte PWMParabolaOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, 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);
       
        int Now = NumMins(hour(), minute());
        if (hour()<startHour && isOvernight) Start-=86400;
        if (hour()<startHour || !isOvernight) End-=86400;
       
        byte PWMDelta = endPWM-startPWM;
        byte ParabolaPhase=constrain(map(Now,Start,End,0,180),0,180);

        if ( Now <= Start || Now >= End)
               return oldValue;
        else
        {
               return startPWM+(PWMDelta*sin(radians(ParabolaPhase)));
        }
}


I'll let you know in a few days.
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Apr 01, 2013 12:58 pm
Let me find you the thread that I posted the overnight/non-overnight code. You should test with that because moonrise could be within the same day or be an overnight event...
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Mon Apr 01, 2013 1:01 pm
Original PWMSlopeOvernight
viewtopic.php?p=11781#p11781

My Modification to make it universal
viewtopic.php?p=22384#p22384


Lol nevermind... just read your code... looks like you got my changes :)

Roberto.. if this works, both fixes should go in together :)

Posts: 12327
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Mon Apr 01, 2013 1:24 pm
The slope one is already merged in the dev branch :)
I'll check out the parabola.
Roberto.
PreviousNext

Return to My PDE/INO file

Who is online

Users browsing this forum: No registered users and 1 guest

cron