Moon rise/set implementation

Share you PDE file with our community
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Moon rise/set implementation

Post by thekameleon »

So the function did not work. So I tweaked it to this:

Code: Select all

byte PWMParabolaOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte oldValue)
{
        int start = NumMins(startHour, startMinute);
        int end = NumMins(endHour, endMinute);
        if (start < end)
        {
          //Example: 2300hrs to 0200hrs
          if (hour() < endHour) start -= 1440; //past midnight
          if (hour() > startHour) end += 1440; //before midnight
        }
        
        int current = NumMins(hour(), minute());
        
        byte pwmDelta = endPWM - startPWM;
        byte parabolaPhase = constrain(map(current, start, end, 0, 180), 0, 180);

        if ( current <= start || current >= end)
          return oldValue;
        else
        {
          return startPWM + (pwmDelta * sin(radians(parabolaPhase)));
        }
}
This is outputting during a normal non-over midnight. I wish there was a good way to Unit Test Arduino to validate over midnight.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moon rise/set implementation

Post by rimai »

You can, but you will need to modify the libraries.
Would you like to do that?
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Moon rise/set implementation

Post by thekameleon »

I was thinking of using Visual Studio for Unit Testing and even building sketches. Visual Micro for Visual Studio actually allows for step through debugging via the serial port. I am not sure how tweaking the libraries would help here, I just want to run the code out side of the controller
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moon rise/set implementation

Post by rimai »

I used VS with RA just fine :)
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Moon rise/set implementation

Post by thekameleon »

Wow... That was easy.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Moon rise/set implementation

Post by thekameleon »

Here is the function PWMParabolaOvernight. I have been testing it for over a week and it seems to be behaving properly.

Code: Select all

byte PWMParabolaOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, 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());

  byte pwmDelta = endPWM - startPWM;
  byte parabolaPhase = constrain(map(current, start, end, 0, 180), 0, 180);

  if ( current <= start || current >= end)
    return oldValue;
  else
  {
    return startPWM + (pwmDelta * sin(radians(parabolaPhase)));
  }
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Moon rise/set implementation

Post by lnevo »

Awesome!
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moon rise/set implementation

Post by rimai »

Thanks!!!
But it is not working :(
I tested PWMParabolaOvernight(23,0,8,0,10,90,5) and got this:

Code: Select all

23	0	5
23	1	5
23	2	5
23	3	5
23	4	5
23	5	5
23	6	5
23	7	5
23	8	5
23	9	5
23	10	5
23	11	5
23	12	5
23	13	5
23	14	5
23	15	5
23	16	5
23	17	5
23	18	5
23	19	5
23	20	5
23	21	5
23	22	5
23	23	5
23	24	5
23	25	5
23	26	5
23	27	5
23	28	5
23	29	5
23	30	5
23	31	5
23	32	5
23	33	5
23	34	5
23	35	5
23	36	5
23	37	5
23	38	5
23	39	5
23	40	5
23	41	5
23	42	5
23	43	5
23	44	5
23	45	5
23	46	5
23	47	5
23	48	5
23	49	5
23	50	5
23	51	5
23	52	5
23	53	5
23	54	5
23	55	5
23	56	5
23	57	5
23	58	5
23	59	5
0	0	37
0	1	37
0	2	37
0	3	38
0	4	38
0	5	38
0	6	39
0	7	39
0	8	39
0	9	41
0	10	41
0	11	41
0	12	42
0	13	42
0	14	42
0	15	43
0	16	43
0	17	43
0	18	45
0	19	45
0	20	45
0	21	46
0	22	46
0	23	46
0	24	47
0	25	47
0	26	47
0	27	48
0	28	48
0	29	48
0	30	50
0	31	50
0	32	50
0	33	51
0	34	51
0	35	51
0	36	52
0	37	52
0	38	52
0	39	53
0	40	53
0	41	53
0	42	54
0	43	54
0	44	54
0	45	55
0	46	55
0	47	55
0	48	57
0	49	57
0	50	57
0	51	58
0	52	58
0	53	58
0	54	59
0	55	59
0	56	59
0	57	60
0	58	60
0	59	60
then I went and tested PWMParabolaOvernight(22,0,8,0,10,90,5) and got this:

Code: Select all

22	0	5
22	1	5
22	2	5
22	3	5
22	4	5
22	5	5
22	6	5
22	7	5
22	8	5
22	9	5
22	10	5
22	11	5
22	12	5
22	13	5
22	14	5
22	15	5
22	16	5
22	17	5
22	18	5
22	19	5
22	20	5
22	21	5
22	22	5
22	23	5
22	24	5
22	25	5
22	26	5
22	27	5
22	28	5
22	29	5
22	30	5
22	31	5
22	32	5
22	33	5
22	34	5
22	35	5
22	36	5
22	37	5
22	38	5
22	39	5
22	40	5
22	41	5
22	42	5
22	43	5
22	44	5
22	45	5
22	46	5
22	47	5
22	48	5
22	49	5
22	50	5
22	51	5
22	52	5
22	53	5
22	54	5
22	55	5
22	56	5
22	57	5
22	58	5
22	59	5
23	0	34
23	1	34
23	2	34
23	3	34
23	4	36
23	5	36
23	6	36
23	7	37
23	8	37
23	9	37
23	10	38
23	11	38
23	12	38
23	13	38
23	14	39
23	15	39
23	16	39
23	17	41
23	18	41
23	19	41
23	20	42
23	21	42
23	22	42
23	23	42
23	24	43
23	25	43
23	26	43
23	27	45
23	28	45
23	29	45
23	30	46
23	31	46
23	32	46
23	33	46
23	34	47
23	35	47
23	36	47
23	37	48
23	38	48
23	39	48
23	40	50
23	41	50
23	42	50
23	43	50
23	44	51
23	45	51
23	46	51
23	47	52
23	48	52
23	49	52
23	50	53
23	51	53
23	52	53
23	53	53
23	54	54
23	55	54
23	56	54
23	57	55
23	58	55
23	59	55
0	0	57
0	1	57
0	2	57
0	3	57
0	4	58
0	5	58
0	6	58
0	7	59
0	8	59
0	9	59
0	10	60
0	11	60
0	12	60
0	13	60
0	14	61
0	15	61
0	16	61
0	17	62
0	18	62
0	19	62
0	20	63
0	21	63
0	22	63
0	23	63
0	24	64
0	25	64
0	26	64
0	27	65
0	28	65
0	29	65
0	30	66
0	31	66
0	32	66
0	33	66
0	34	67
0	35	67
0	36	67
0	37	68
0	38	68
0	39	68
0	40	69
0	41	69
0	42	69
0	43	69
0	44	70
0	45	70
0	46	70
0	47	71
0	48	71
0	49	71
0	50	72
0	51	72
0	52	72
0	53	72
0	54	73
0	55	73
0	56	73
0	57	73
0	58	73
0	59	73
Looks like it is missing the starting hour completely.
Here is the test code I used:

Code: Select all

#include <Salinity.h>
#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 <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

int test=0;
void setup()
{
  ReefAngel.Init();  
}

void loop()
{
  wdt_reset();
  adjustTime(60);
  Serial.print(hour());
  Serial.print("\t");
  Serial.print(minute());
  Serial.print("\t");
  Serial.println(PWMParabolaOvernight(22,0,8,0,10,90,5));
  delay(10);
  if (test++>2500)
  while(1) wdt_reset();
  
}

byte PWMParabolaOvernight(byte startHour, byte startMinute, byte endHour,
byte endMinute, byte startPWM, byte endPWM, 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());

  byte pwmDelta = endPWM - startPWM;
  byte parabolaPhase = constrain(map(current, start, end, 0, 180), 0, 180);

  if ( current <= start || current >= end)
    return oldValue;
  else
  {
    return startPWM + (pwmDelta * sin(radians(parabolaPhase)));
  }
}
The only thing is that you will need to change the libraries to perform this test.... :(
You need to change ReefAngel.cpp
From

Code: Select all

	setSyncInterval(SECS_PER_HOUR*6);  // Changed to sync every 6 hours.
To

Code: Select all

	setSyncInterval(SECS_PER_HOUR*6000);  // Changed to sync every 6 hours.
Or the clock will keep syncing with the RTC.
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Moon rise/set implementation

Post by thekameleon »

I was just testing if you were actually paying attention.... :D

I think my problem is this line:

Code: Select all

if (hour() > startHour) end += 1440; //before midnight
Change it to this

Code: Select all

if (hour() >= startHour) end += 1440; //before midnight
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moon rise/set implementation

Post by rimai »

Awesome!!!
I'll include in the next update :)
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

Fantastic.. now both the slope and parabola functions will work am-pm or pm-am :)
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Moon rise/set implementation

Post by thekameleon »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

Definitely looks cleaner then mine...
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Moon rise/set implementation

Post by rimai »

Should I use thekameleon version instead then?
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Moon rise/set implementation

Post by lnevo »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Moon rise/set implementation

Post by lnevo »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Moon rise/set implementation

Post by lnevo »

I think actually it may be fine after reading it again...
Aemornion
Posts: 5
Joined: Fri Jun 07, 2013 8:45 pm

Re: Moon rise/set implementation

Post by Aemornion »

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
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

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()
Aemornion
Posts: 5
Joined: Fri Jun 07, 2013 8:45 pm

Re: Moon rise/set implementation

Post by Aemornion »

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
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

The use of "" or <> depends on where you put the library.

I guess in your case the <> is appropriate.

Scope should not be a problem here if its included properly.

Can you try again now. #included was incorrect so maybe now that its #include?
Aemornion
Posts: 5
Joined: Fri Jun 07, 2013 8:45 pm

Re: Moon rise/set implementation

Post by Aemornion »

Ah whoops, the "included" is an error on my part in the post, not in the actual program. It is most certainly include, not included in the ino

I noticed something else, I was using a lower case m rather than M in Moon.h

Now when i change it to a capital M

Code: Select all

#include <Moon.h>
I get a slew of new errors about things inside the library :?
at least I know it is actually reading the library...i guess...



Code: Select all

In file included from moon_test.ino:5:
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:35: error: 'boolean' does not name a type
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:36: error: 'boolean' does not name a type
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:37: error: 'byte' does not name a type
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:38: error: 'byte' does not name a type
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:39: error: 'byte' does not name a type
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:40: error: 'byte' does not name a type
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:51: error: 'PI' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h: In function 'float lst(int, int, float)':
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:63: error: 'floor' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h: In function 'void moon(float)':
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:78: error: 'floor' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:85: error: 'PI' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:92: error: 'sin' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:106: error: 'cos' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:129: error: 'sqrt' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:130: error: 'atan' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h: In function 'float test_moon(int, float, int, float)':
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:165: error: 'PI' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:173: error: 'sin' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:174: error: 'cos' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:196: error: 'sqrt' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:203: error: 'floor' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:209: error: 'atan2' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:214: error: 'struct moon_t' has no member named 'riseH'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:215: error: 'struct moon_t' has no member named 'riseM'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:217: error: 'struct moon_t' has no member named 'isRise'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:222: error: 'struct moon_t' has no member named 'setH'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:223: error: 'struct moon_t' has no member named 'setM'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:225: error: 'struct moon_t' has no member named 'isSet'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h: At global scope:
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:231: error: 'boolean' has not been declared
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h: In function 'void riseset(int, int, int)':
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:235: error: 'struct moon_t' has no member named 'riseH'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:236: error: 'struct moon_t' has no member named 'riseM'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:237: error: 'struct moon_t' has no member named 'setH'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:238: error: 'struct moon_t' has no member named 'setM'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:271: error: 'PI' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:274: error: 'PI' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:279: error: 'struct moon_t' has no member named 'isRise'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:280: error: 'struct moon_t' has no member named 'isSet'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h: In function 'void moon_init(int, int)':
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:303: error: 'boolean' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:303: error: expected `;' before 'moonUp'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:309: error: 'struct moon_t' has no member named 'isRise'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:310: error: 'struct moon_t' has no member named 'riseH'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:310: error: 'struct moon_t' has no member named 'riseM'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:310: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:312: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:315: error: 'struct moon_t' has no member named 'isSet'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:316: error: 'struct moon_t' has no member named 'setH'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:316: error: 'struct moon_t' has no member named 'setM'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:316: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:318: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:321: error: 'moonUp' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:331: error: 'struct moon_t' has no member named 'isSet'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:334: error: 'struct moon_t' has no member named 'setH'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:334: error: 'struct moon_t' has no member named 'setM'
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:334: error: 'ScheduleTime' was not declared in this scope
Aemornion
Posts: 5
Joined: Fri Jun 07, 2013 8:45 pm

Re: Moon rise/set implementation

Post by Aemornion »

Ok interesting,
I was able to knock out many errors by including

Code: Select all

#if ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif
in my header, I have no idea why its just something random i found online to try.

anyway, now my errors read as follows. All are based around the 'ScheduleTime' function within the library.
Strange indeed.

Code: Select all

In file included from moon_test.ino:13:
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h: In function 'void moon_init(int, int)':
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:310: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:312: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:316: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:318: error: 'ScheduleTime' was not declared in this scope
C:\Users\Jay\Documents\Arduino\libraries\Moon/Moon.h:334: error: 'ScheduleTime' was not declared in this scope
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

ScheduleTime is a function in the Time library. Not sure if that's a standard arduino function or exclusive in the RA library. Anyway, you'll need that package. I did some conversion from the original package I found to make it work with RA.

You may also want to try the original as that may be more based on just Arduino standard libs...
http://code.google.com/p/stilo/
Aemornion
Posts: 5
Joined: Fri Jun 07, 2013 8:45 pm

Re: Moon rise/set implementation

Post by Aemornion »

Hmmm, after much mullings
I removed

Code: Select all

if (Moon.isRise) {
    rise_time=ScheduleTime(Moon.riseH, Moon.riseM, 0);
  } else {
    rise_time=ScheduleTime(0, 0, 0);
  }

  if (Moon.isSet) {
    set_time=ScheduleTime(Moon.setH, Moon.setM, 0);
  } else {
    set_time=ScheduleTime(23, 59, 59);
  }

  moonUp = 0;
  if (rise_time < set_time) {
    if ((tnow >=rise_time) && (tnow < set_time)) {
     moonUp = 1;
    }
  } else if ((tnow >= rise_time) || (tnow < set_time)) {
    moonUp = 1;
  }

  if (moonUp) {
      if ( (!Moon.isSet) || ((rise_time > set_time)&&(tnow>=rise_time)) ) {      //calculate for next day
        riseset(latitude, longitude, 1);
      }
      set_time=ScheduleTime(Moon.setH, Moon.setM, 59)+SECS_PER_DAY;
  }
From the code. with the idea that from the looks of it that portion is not actually modifying the rise time and set time values, but rather sending those values elsewhere into your program.

and YAY it compiled!


Except the rise and set times are incorrect, so maybe that portion of code really does do something. sigh oh well ill figure it out eventually i suppose.

That you for all your help =)
-Jay
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

Yeah those times are used during moon_init. Schedule time function returns number of minutes for that time...if you look at the original link it doesn't use that function so it may be in your library.
bencollinz
Posts: 151
Joined: Wed Mar 13, 2013 5:36 pm

Re: Moon rise/set implementation

Post by bencollinz »

thekameleon wrote: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;
}
So, can you dumb this down for me, please? Am I putting values into somewhere or are they declared somewhere else? And I still need the moon.h file, etc?
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

You don't need that function anymore. The regular PWMSlope function now works during any timeframe.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Moon rise/set implementation

Post by lnevo »

Latest version 1.1.0 compatible
Attachments
Moon.zip
(3.29 KiB) Downloaded 707 times
Amos Poh
Posts: 107
Joined: Sun Jul 22, 2012 4:51 am
Location: Singapore

Re: Moon rise/set implementation

Post by Amos Poh »

lnevo wrote:Hey guys,

So, I found this other aquarium controller code at http://code.google.com/p/stilo/ that had ported a javascript implementation of a Moonrise/set calculator into Arduino. I have adapted it to the RA libraries and it looks like it's working great.

Anyway if you want to have your moonlights follow an actual rise/set calculated based on GPS location, then here's what you have to do..

Code: Select all

#include Moon.h
And then in your loop() function, add this

Code: Select all

moon_init(21,-73); // pass it lat / lon - it uses ints for the caclulation...
You will then have access to the Moon struct which has the following definition:

Code: Select all

struct moon_t
{
  boolean isRise;
  boolean isSet;
  byte riseH;
  byte riseM;
  byte setH;
  byte setM;
  float riseAZ;
  float setAZ;
}
So you'll be able to do something like this:

Code: Select all

  if (Moon.isRise) {
    ReefAngel.PWM.SetDaylight(MoonPhase());
    ReefAngel.PWM.SetActinic(MoonPhase());
  } else {
    ReefAngel.PWM.SetDaylight(0);
    ReefAngel.PWM.SetActinic(0);
  }
or add this to your display

Code: Select all

    sprintf(buf, "%02d:%02d", Moon.riseH, Moon.riseM);
    ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x,y,"MR:"); x+=21;
    ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,buf);
    sprintf(buf, "%02d:%02d", Moon.setH, Moon.setM); x+=36;
    ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x,y,"MS:"); x+=21;
    ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,buf); x+=36;
    if(Moon.isRise) ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,"@");
    else ReefAngel.LCD.DrawText(COLOR_RED,DefaultBGColor,x,y,"_");

Hi Lee thanks for sharing,

Just a few question hope you can assist me.
I am running 2 Rapid dimmable LED lightest, using analog dimming expansion.
the light set has 3 channels, 1 channel blue, 1 channel white and 1 channel UV red and green.

Currently iam running it to ramp up the different channels at different timing.
1)How can i use this code that you provided to fit into the different channel?
2)what should i do with the Moon.zip files?

Pardon my noob questions :)
Post Reply