Skip to content

Commit

Permalink
Merge pull request #13 from DavidArmstrong/MoonRiseSetFlags
Browse files Browse the repository at this point in the history
Add implementation of Moon valid rise/set flags
  • Loading branch information
DavidArmstrong authored Jan 4, 2025
2 parents 5fabda8 + b71ed97 commit 3c532ac
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 27 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2023 Dave Armstrong
Copyright (c) 2021-2025 Dave Armstrong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Sidereal Planets - A strangely named Arduino Library for various astronomy related functions

Version 1.4.0 - October 24, 2023
Version 1.5.0 - January 4, 2025

By David Armstrong
https://github.com/DavidArmstrong/SiderealPlanets
Expand Down Expand Up @@ -181,9 +181,15 @@ double getSunsetTime()<br>
boolean doMoonRiseSetTimes()<br>
Computes the local times for moonrise and moonset for the current date. The results are stored internally, and must be retrieved by calls to getMoonriseTime() and getMoonsetTime(). If a value of false is returned, the Moon never sets or rises on the current GMT date at this location on the earth.

boolean getMoonRiseValidFlag()<br>
Returns true value of the last computed Moon rise time is valid. A false value means that there is no valid Moon rise time for the computed date.

double getMoonriseTime()<br>
Returns the local time for moonrise for a previously specified date. The time is in hours since midnight.

boolean getMoonSetValidFlag()<br>
Returns true value of the last computed Moon set time is valid. A false value means that there is no valid Moon set time for the computed date.

double getMoonsetTime()<br>
Returns the local time for moonset for a previously specified date. The time is in hours since midnight.

Expand Down
14 changes: 11 additions & 3 deletions examples/DogAndPonyShow/DogAndPonyShow.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Sidereal Planets Dog and Pony Show sketch
* Version 1.2.0 - February 17, 2023
* Version 1.5.0 - January 4, 2025
* Here we 'show off' the Sidereal Planets Library
*
* Requirement #1:
Expand Down Expand Up @@ -192,8 +192,16 @@ void loop() {
TERMxy(44,line); printDegMinSecs2(myAstro.getDeclinationDec());
TERMxy(55,line);
if (myAstro.doMoonRiseSetTimes()) {
printTime(myAstro.getMoonriseTime());
printTime(myAstro.getMoonsetTime());
if ( myAstro.getMoonRiseValidFlag() ) {
printTime(myAstro.getMoonriseTime());
} else {
Serial.print(" xxxx ");
}
if ( myAstro.getMoonSetValidFlag() ) {
printTime(myAstro.getMoonsetTime());
} else {
Serial.print(" xxxx ");
}
} else {
Serial.print("No rise/set times");
}
Expand Down
69 changes: 64 additions & 5 deletions examples/Example5_Moon/Example5_Moon.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Sidereal Planets Library - Moon functions
* Version 1.4.0 - October 24, 2023
* Version 1.5.0 - January 4, 2025
* Example5_Moon
*/

Expand Down Expand Up @@ -53,7 +53,8 @@ void setup() {
Serial.println("\n");

Serial.println("We can also calculate Moon Rise/Set times.");
Serial.println("We set: DST off, Time Zone = 0, Date: Jan 7,1984");
Serial.println("Example #1:");
Serial.println("We set: DST off, Time Zone = 0, Date: Jan 7, 1984");
Serial.println("Longitude = 0:0:0; Latitude = 30:0:0");

myAstro.rejectDST();
Expand All @@ -63,13 +64,71 @@ void setup() {
myAstro.doMoonRiseSetTimes();
Serial.println("\nOur results should be or are:");
Serial.print("Local MoonRise=9:58:1.46 ==> ");
myAstro.printDegMinSecs(myAstro.getMoonriseTime());
if ( myAstro.getMoonRiseValidFlag() ) {
myAstro.printDegMinSecs(myAstro.getMoonriseTime());
} else {
Serial.print("No valid Moon Rise time.");
}
Serial.println("");
Serial.print("Local MoonSet=21:8:59.44 ==> ");
myAstro.printDegMinSecs(myAstro.getMoonsetTime());
if ( myAstro.getMoonSetValidFlag() ) {
myAstro.printDegMinSecs(myAstro.getMoonsetTime());
} else {
Serial.print("No valid Moon Set time.");
}
Serial.println("\n");

Serial.println("Example #2:");
Serial.println("We set: DST off, Time Zone = 0, Date: Jan 11, 1984");
Serial.println("Longitude = 0:0:0; Latitude = 35:30:0");

myAstro.rejectDST();
myAstro.setTimeZone(0);
myAstro.setLatLong(myAstro.decimalDegrees(35,30,0), myAstro.decimalDegrees(0,0,0));
myAstro.setGMTdate(1984,1,11);
myAstro.doMoonRiseSetTimes();
Serial.println("\nOur results should be or are:");
Serial.print("Local MoonRise=11:52:1.46 ==> ");
if ( myAstro.getMoonRiseValidFlag() ) {
myAstro.printDegMinSecs(myAstro.getMoonriseTime());
} else {
Serial.print("No valid Moon Rise time.");
}
Serial.println("");
Serial.print("Local MoonSet=XX:XX:XX: ==> ");
if ( myAstro.getMoonSetValidFlag() ) {
myAstro.printDegMinSecs(myAstro.getMoonsetTime());
} else {
Serial.print("No valid Moon Set time.");
}
Serial.println("\n");

Serial.println("Example #3:");
Serial.println("We set: DST off, Time Zone = 0, Date: 2 Feb, 2024");
Serial.println("Longitude = -0:30:0; Latitude = 35:30:0");

myAstro.rejectDST();
myAstro.setTimeZone(0);
myAstro.setLatLong(myAstro.decimalDegrees(35,30,0), -myAstro.decimalDegrees(0,30,0));// (-) before is for negative coord
myAstro.setGMTdate(2024,2,2);
myAstro.doMoonRiseSetTimes();
Serial.println("\nOur results should be or are:");
Serial.print("Local MoonRise=XX:XX:XX ==> ");
if ( myAstro.getMoonRiseValidFlag() ) {
myAstro.printDegMinSecs(myAstro.getMoonriseTime());
} else {
Serial.print("No valid Moon Rise time.");
}
Serial.println("");
Serial.print("Local MoonSet=10:44:10: ==> ");
if ( myAstro.getMoonSetValidFlag() ) {
myAstro.printDegMinSecs(myAstro.getMoonsetTime());
} else {
Serial.print("No valid Moon Set time.");
}
Serial.println("\n");
}

void loop() {
while(1); //Freeze
}
}
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ doSunRiseSetTimes KEYWORD2
getSunriseTime KEYWORD2
getSunsetTime KEYWORD2
doMoonRiseSetTimes KEYWORD2
getMoonRiseValidFlag KEYWORD2
getMoonriseTime KEYWORD2
getMoonSetValidFlag KEYWORD2
getMoonsetTime KEYWORD2
doRiseSetTimes KEYWORD2
getRiseTime KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SiderealPlanets
version=1.4.0
version=1.5.0
author=David Armstrong <mamoru.tbreesama@gmail.com>
maintainer=David Armstrong <mamoru.tbreesama@gmail.com>
sentence=A library for providing basic astronomy related functions.
Expand Down
53 changes: 39 additions & 14 deletions src/SiderealPlanets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
SiderealPlanets.cpp
Sidereal Planets Arduino Library C++ source
David Armstrong
Version 1.4.0 - October 24, 2023
Version 1.5.0 - January 4, 2025
https://github.com/DavidArmstrong/SiderealPlanets
Resources:
Uses math.h for math function
Development environment specifics:
Arduino IDE 1.8.13
Arduino IDE 2.3.4
Teensy loader - untested
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Expand Down Expand Up @@ -1713,10 +1713,14 @@ double SiderealPlanets::getSunsetTime(void) {
}

boolean SiderealPlanets::doMoonRiseSetTimes(void) {
double DN_local, horizonVerticalDisplacement, A_local, TH_local, AA_local, AB_local, GU_local, GD_local;
double DN_local, horizonVerticalDisplacement, A_local, TH_local, AA_local, AB_local;
double GU_local = 0.;
double GD_local = 0.;
double G1_local = 0.;
double G2_local = 0.;
double tmpGMT = GMTtime;
GMTtime = (12.0 + (TimeZoneOffset + DSToffset)); //Set to local mid-day

//local rise-set routine
doMoon(); //Already does nutation too
TH_local = 2.7249e-1 * sin(moonHorizontalParallax);
Expand All @@ -1727,14 +1731,21 @@ boolean SiderealPlanets::doMoonRiseSetTimes(void) {
return false;
}

moonRiseValidFlag = true;
moonSetValidFlag = true;
double LA_local = localSiderealTimeRising; //localSiderealTime of rising - first guesstimate
double LB_local = localSiderealTimeSetting; //localSiderealTime of setting - first guesstimate
for(int K_local=1; K_local <= 3; K_local++) {

for (int K_local=1; K_local <= 3; K_local++) {
G1_local = GU_local;
// local sidereal time to local civil time
GU_local = doLST2GMT(LA_local);

G2_local = GD_local;
// local sidereal time to local civil time
GD_local = doLST2GMT(LB_local);
//find a better time of rising

//find a better time of rising
GMTtime = GU_local;
// find time
DN_local = mjd1900;
Expand All @@ -1746,10 +1757,10 @@ boolean SiderealPlanets::doMoonRiseSetTimes(void) {
TH_local = 2.7249e-1 * sin(moonHorizontalParallax);
horizonVerticalDisplacement = TH_local + 9.8902e-3 - moonHorizontalParallax;
if (doRiseSetTimes(rad2deg(horizonVerticalDisplacement)) == false) {
mjd1900=DN_local;
GMTtime = tmpGMT;
return false;
}
mjd1900 = DN_local;
GMTtime = tmpGMT;
return false;
}
mjd1900=DN_local;
//find a better time of setting
LA_local = localSiderealTimeRising;
Expand All @@ -1765,26 +1776,40 @@ boolean SiderealPlanets::doMoonRiseSetTimes(void) {
TH_local = 2.7249e-1 * sin(moonHorizontalParallax);
horizonVerticalDisplacement = TH_local + 9.8902e-3 - moonHorizontalParallax;
if (doRiseSetTimes(rad2deg(horizonVerticalDisplacement)) == false) {
mjd1900=DN_local;
GMTtime = tmpGMT;
return false;
}
mjd1900 = DN_local;
GMTtime = tmpGMT;
return false;
}
mjd1900=DN_local;
LB_local = localSiderealTimeSetting;
//AB_local = azimuthSetting;
}
//azimuthRising = AA_local;
//azimuthSetting = AB_local;
if ( fabs( GU_local - G1_local ) > 6.0 ) {
moonRiseValidFlag = false;
}
localSiderealTimeRising = LA_local;
if ( fabs( GD_local - G2_local ) > 6.0 ) {
moonSetValidFlag = false;
}
localSiderealTimeSetting = LB_local;
GMTtime = tmpGMT;
return true;
}

boolean SiderealPlanets::getMoonRiseValidFlag(void) {
return moonRiseValidFlag;
}

double SiderealPlanets::getMoonriseTime(void) {
return getRiseTime();
}

boolean SiderealPlanets::getMoonSetValidFlag(void) {
return moonSetValidFlag;
}

double SiderealPlanets::getMoonsetTime(void) {
return getSetTime();
}
Expand Down
7 changes: 5 additions & 2 deletions src/SiderealPlanets.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SiderealPlanets.h
Sidereal Planets Arduino Library Header File
David Armstrong
Version 1.4.0 - October 24, 2023
Version 1.5.0 - January 4, 2025
https://github.com/DavidArmstrong/SiderealPlanets
This file prototypes the SiderealPlanets class, as implemented in SiderealPlanets.cpp
Expand All @@ -11,7 +11,7 @@ This file prototypes the SiderealPlanets class, as implemented in SiderealPlanet
Uses math.h for math functions
Development environment specifics:
Arduino IDE 1.8.13
Arduino IDE 2.3.4
Teensy loader - untested
This code is released under the [MIT License](http://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -135,7 +135,9 @@ class SiderealPlanets {
double getSunriseTime(void);
double getSunsetTime(void);
boolean doMoonRiseSetTimes(void);
boolean getMoonRiseValidFlag(void);
double getMoonriseTime(void);
boolean getMoonSetValidFlag(void);
double getMoonsetTime(void);
void printDegMinSecs(double n);

Expand All @@ -155,6 +157,7 @@ class SiderealPlanets {
boolean obliquityDone, nutationDone, Ecl2RaDecDone, risetDone;
boolean doMoonDone; // Keep track if doMoon() has been called
boolean getLunarLuminanceDone; // Keep track if getLunarLuminance() has been called
boolean moonRiseValidFlag, moonSetValidFlag;
int GMTyear, GMTmonth, GMTday, GMTminute, GMThour;
float GMTseconds;
double julianCenturies1900, GMTtime, GMTsiderealTime, LocalSiderealTime;
Expand Down

0 comments on commit 3c532ac

Please sign in to comment.