Skip to content

Commit 02fefa0

Browse files
Return value 'percentLit' is a real between 0-1.
1 parent 05d7205 commit 02fefa0

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

MoonPhase.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#include "MoonPhase.h"
22

3-
MoonPhase::moonData MoonPhase::getInfo( const int year, const int month, const int day, const double hour)
3+
MoonPhase::moonData MoonPhase::getInfo( const int year, const int month, const int day, const double hour )
44
{
5+
/*
6+
Calculates the phase of the moon at the given epoch.
7+
returns the moon percentage that is lit as a real number (0-1)
8+
*/
59
moonData returnValue;
610
double j = _Julian(year, month, (double)day + hour / 24.0) - 2444238.5;
711
double ls = _sun_position(j);
812
double lm = _moon_position(j, ls);
913
double t = lm - ls;
1014
if (t < 0) t += 360;
1115
returnValue.angle = t;
12-
returnValue.percentLit = 100 * (1.0 - cos((lm - ls) * DEG_TO_RAD)) / 2;
16+
returnValue.percentLit = (1.0 - cos((lm - ls) * DEG_TO_RAD)) / 2;
1317
return returnValue;
1418
}
1519

16-
double MoonPhase::_Julian( int year, int month, double day)
20+
double MoonPhase::_Julian( int year, int month, double day )
1721
{
1822
int b, c, e;
1923
b = 0;

examples/esp32/ILI9341/ILI9341.ino

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void setup()
7373
while ( !WiFi.isConnected() && millis() - timeout > 0 )
7474
{
7575
Serial.print( "." );
76+
delay( 500 );
7677
}
7778
Serial.println();
7879
Serial.println( "Connected." );
@@ -115,19 +116,7 @@ void loop()
115116
tft.setCursor( 20, 120 );
116117
tft.printf( "%i%c %s UTC", moon.angle, char(247), asctime( &timeinfo ) );
117118
tft.setCursor( 120, 105 );
118-
tft.printf( "%.4f%%", moon.percentLit );
119-
120-
121-
122-
ESP_LOGI( TAG, "%i", moon.angle );
123-
ESP_LOGI( TAG, "%04d/%02d/%02d %02d:%02d:%02d UTC - Moon is %.1f%% illuminated (%d)",
124-
1900 + timeinfo.tm_year,
125-
timeinfo.tm_mon + 1,
126-
timeinfo.tm_mday,
127-
timeinfo.tm_hour,
128-
timeinfo.tm_min,
129-
timeinfo.tm_sec,
130-
moon.percentLit );
119+
tft.printf( "%.4f%%", moon.percentLit * 100 );
131120

132121
delay( 1000 );
133122
}

examples/simple/simple.ino

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const int year = 2018;
44
const int month = 4;
5-
const int day = 4;
6-
const float hour = 22.5; /* 22:30 */
5+
const int day = 12;
6+
const float hour = 2.55; /* 22:30 */
77

88
MoonPhase MoonPhase; /* include a MoonPhase instance */
99

@@ -17,11 +17,10 @@ void setup() {
1717
moon = MoonPhase.getInfo( year, month, day, hour );
1818

1919
Serial.print( "Moon phase angle: " );
20-
Serial.print( moon.angle );
20+
Serial.print( moon.angle ); /* angle is a integer between 0-360 */
2121
Serial.println( " degrees." );
2222
Serial.print( "Moon surface lit: " );
23-
Serial.print( moon.percentLit );
24-
Serial.println( "%." );
23+
Serial.printf( "%.0f%%", moon.percentLit * 100 ); /* percentLit is a real between 0-1 */
2524
}
2625

2726
void loop() {

0 commit comments

Comments
 (0)