Moon rise/set implementation

Share you PDE file with our community
User avatar
Posts: 5330
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Apr 16, 2013 8:35 am
Fantastic.. now both the slope and parabola functions will work am-pm or pm-am :)

Posts: 137
Joined: Sat Feb 16, 2013 7:44 am
PostPosted: Tue Apr 16, 2013 11:55 am
Here is the code for the slope. its based off of Parabola

Code: Select all
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
   int start = NumMins(startHour, startMinute);
   int end = NumMins(endHour, endMinute);
   if (start > end) //Start is greater than End so its over midnight
   {
      //Example: 2300hrs to 0200hrs
      if (hour() < endHour) start -= 1440; //past midnight
      if (hour() >= startHour) end += 1440; //before midnight
   }
   int current = NumMins(hour(), minute());
   int startD = start + Duration;
   int stopD = end - Duration;

   if ( current >= start && current <= startD )
      return constrain(map(current, start, startD, startPWM, endPWM),startPWM, endPWM);
   else if ( current >= stopD && current <= end )
   {
      byte v = constrain(map(current, stopD, end, startPWM, endPWM),startPWM, endPWM);
      return endPWM - v + startPWM;
   }
   else if ( current > startD && current < stopD )
      return endPWM;

    // lastly return the existing value
    return oldValue;
}
User avatar
Posts: 5330
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Apr 16, 2013 12:38 pm
Definitely looks cleaner then mine...

Posts: 11845
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Tue Apr 16, 2013 2:31 pm
Should I use thekameleon version instead then?
Roberto.
User avatar
Posts: 5330
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Apr 16, 2013 3:19 pm
If the logic works then yeah. This matches the parabola logic and looks more like the original code than the original overnight that I started from...
User avatar
Posts: 5330
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Apr 16, 2013 3:23 pm
The only con I see is the logic to add/subtract time only focuses on hours...if someone were to use it for a slope with less time or if someone wanted a slope/parabola from 11:55pm - 11:05pm...it might have an issue..maybe not... That would be the only point to check IMO.
User avatar
Posts: 5330
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Tue Apr 16, 2013 3:24 pm
I think actually it may be fine after reading it again...

Posts: 5
Joined: Fri Jun 07, 2013 8:45 pm
PostPosted: Fri Jun 07, 2013 9:04 pm
Hello
I just signed up for this forum today to seek help with the moon.h library.
and as I am apparently too new to send a PM I shall post here. Hopefully this thread is not dead yet.

I am attempting to implement my own arduino tank controller, nothing fancy tank wise just my little 29 planted tank.
I started to learn the arduino in November for this purpose and have come a long way in the short about of time I have been chugging along and learning a lot in the process. =)

So I stumbled across this thread and the moon.h library, and real moon times is something i would really like to implement.

This might sound pathetic... but i am stuck on step 2

I have put
Code: Select all
#included moon.h

and the ide recognizes that as a valid library
no complaints their

But when I put

Code: Select all
moon_init(21,-73);


into the program, is complains
Code: Select all
moon_test.ino: In function 'void loop()':
moon_test:26: error: 'moon_init' was not declared in this scope


I have tried putting it elsewhere in the setup loop, outside theloop, different places within the loop. going as far as to delete everything else, except the necessary libraries wire.h, time.h, DS1307RTC.h.

Do you guys have any ideas as to why this would not be working? I am at a complete loss.

I am appreciative of any assistance offered.
-Jay
User avatar
Posts: 5330
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Jun 08, 2013 3:06 am
Aemornion wrote:
I have put
Code: Select all
#included moon.h



Welcome and good luck. Try this instead..

Code: Select all
#include "moon.h"


Also make sure that line is in the global declarations not within setup() or loop()

Posts: 5
Joined: Fri Jun 07, 2013 8:45 pm
PostPosted: Sat Jun 08, 2013 10:20 am
Thanks for the reply and assistance lnevo. =)

Alrght, so I made an error in my above statement, When i was
doing
Code: Select all
#included moon.h


I was actually doing
Code: Select all
#included <moon.h>


Which is what i do with all my other libraries standard with no issue.

Last night I did run through other iterations, such as using "" as you suggest which are outlined below.

Doing
Code: Select all
#included moon.h

yields an error of
Code: Select all
moon_test.ino:5:10: error: #include expects "FILENAME" or <FILENAME>

(hence why i starting making <> standard a while ago)

and when i try
Code: Select all
#include "moon.h"

yields an error of
Code: Select all
moon_test.ino:5:18: error: moon.h: No such file or directory


However the moon library is available under the arduino ide, being in the contributed section of the
sketch->importlibrary drop down menu, and when i select it to re import it, it tells me that their is already an moon library.

I should also note that these errors were acquired with the
Code: Select all
moon_init(21,-73);

code removed.

Here is my total code with all the fat trimmed off.


Code: Select all
/////////moon.h test Program//////////
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <moon.h>

void setup() 
{
  //moon_init(21,-73);

  setSyncProvider(RTC.get);   // the function to get the time from the RTC

}

void loop()
{

  //moon_init(21,-73);

}


I left the RTC stuff in their because I am assuming that the moon.h library needs it at some point.

Thank you for any help,
=Jay
PreviousNext

Return to My PDE/INO file

Who is online

Users browsing this forum: No registered users and 2 guests