Re: Moon rise/set implementation
Posted: Tue Apr 16, 2013 8:35 am
Fantastic.. now both the slope and parabola functions will work am-pm or pm-am
Community discussion about Reef Angel Controllers and reefing related subjects
http://forum.reefangel.com/
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;
}
Code: Select all
#included moon.h
Code: Select all
moon_init(21,-73);
Code: Select all
moon_test.ino: In function 'void loop()':
moon_test:26: error: 'moon_init' was not declared in this scope
Welcome and good luck. Try this instead..Aemornion wrote:
I have putCode: Select all
#included moon.h
Code: Select all
#include "moon.h"
Code: Select all
#included moon.h
Code: Select all
#included <moon.h>
Code: Select all
#included moon.h
Code: Select all
moon_test.ino:5:10: error: #include expects "FILENAME" or <FILENAME>
Code: Select all
#include "moon.h"
Code: Select all
moon_test.ino:5:18: error: moon.h: No such file or directory
Code: Select all
moon_init(21,-73);
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);
}
Code: Select all
#include <Moon.h>
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
Code: Select all
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
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
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;
}
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?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; }
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..
And then in your loop() function, add thisCode: Select all
#include Moon.h
You will then have access to the Moon struct which has the following definition:Code: Select all
moon_init(21,-73); // pass it lat / lon - it uses ints for the caclulation...
So you'll be able to do something like this:Code: Select all
struct moon_t { boolean isRise; boolean isSet; byte riseH; byte riseM; byte setH; byte setM; float riseAZ; float setAZ; }
or add this to your displayCode: Select all
if (Moon.isRise) { ReefAngel.PWM.SetDaylight(MoonPhase()); ReefAngel.PWM.SetActinic(MoonPhase()); } else { ReefAngel.PWM.SetDaylight(0); ReefAngel.PWM.SetActinic(0); }
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,"_");