Skip to content

Commit c99fac3

Browse files
Changed function names.
Updated 'keywords.txt'. Updated 'libary.properties'. Added 'esp32-sntp' example.
1 parent 98e2d8e commit c99fac3

File tree

5 files changed

+60
-19
lines changed

5 files changed

+60
-19
lines changed

examples/esp32-sntp/esp32-sntp.ino

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<WiFi.h>
2+
#include <moonPhase.h>
3+
4+
const char * wifissid = "networkname";
5+
const char * wifipsk = "password";
6+
7+
moonPhase moonPhase; // include a MoonPhase instance
8+
9+
void setup() {
10+
// put your setup code here, to run once:
11+
Serial.begin(115200);
12+
Serial.print( "Connecting to " );
13+
Serial.println( wifissid );
14+
WiFi.begin( wifissid, wifipsk );
15+
while ( !WiFi.isConnected() )
16+
delay(100);
17+
18+
Serial.println( " Connected. Getting time..." );
19+
20+
configTzTime( "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", "0.pool.ntp.org" ); //Amsterdam, Netherlands
21+
22+
struct tm timeinfo = {0};
23+
24+
while ( !getLocalTime( &timeinfo, 0 ) )
25+
vTaskDelay( 10 / portTICK_PERIOD_MS );
26+
}
27+
28+
void loop() {
29+
struct tm timeinfo = {0};
30+
getLocalTime( &timeinfo );
31+
Serial.print( asctime( &timeinfo ) );
32+
33+
moonData_t moon; // variable to receive the data
34+
moon = moonPhase.getPhase();
35+
36+
Serial.print( "Moon phase angle: " );
37+
Serial.print( moon.angle ); // angle is a integer between 0-360
38+
Serial.print( " degrees. Moon surface lit: " );
39+
Serial.printf( "%f%%\n", moon.percentLit * 100 ); // percentLit is a real between 0-1
40+
Serial.println();
41+
delay(1000);
42+
}

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ moonData_t KEYWORD1
1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
14-
getInfo KEYWORD2
14+
getPhase KEYWORD2
1515
angle KEYWORD2
1616
percentLit KEYWORD2
1717

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=MoonPhase
2-
version=0.0.1
2+
version=0.99.0
33
author=Cellie
44
maintainer=Cellie
55
sentence=Calculate the lunar phase at a certain time.
6-
paragraph=
6+
paragraph=Arduino library to calculate the moon phase and visible surface at a given time.
77
category=Other
8-
url=https://github.com/CelliesProjects/MoonPhase
8+
url=https://github.com/CelliesProjects/moonPhase
99
architectures=*
1010
includes=MoonPhase.h

moonPhase.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ inline T map(T2 val, T2 in_min, T2 in_max, T out_min, T out_max) {
77
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
88
}
99

10-
inline double moonPhase::fhour( const struct tm &timeinfo ) {
10+
inline double moonPhase::_fhour( const struct tm &timeinfo ) {
1111
return timeinfo.tm_hour + map( ( timeinfo.tm_min * 60 ) + timeinfo.tm_sec, 0, 3600, 0.0, 1.0 );
1212
}
1313

14-
moonData_t moonPhase::_getInfo( const int32_t &year, const int32_t &month, const int32_t &day, const double &hour )
14+
moonData_t moonPhase::_getPhase( const int32_t &year, const int32_t &month, const int32_t &day, const double &hour )
1515
{
1616
/*
1717
Calculates the phase of the moon at the given epoch.
@@ -28,17 +28,17 @@ moonData_t moonPhase::_getInfo( const int32_t &year, const int32_t &month, const
2828
return returnValue;
2929
}
3030

31-
moonData_t moonPhase::getInfo( const time_t t ) {
31+
moonData_t moonPhase::getPhase( const time_t t ) {
3232
struct tm timeinfo;
3333
gmtime_r( &t, &timeinfo );
34-
double hour = fhour( timeinfo );
35-
return _getInfo( 1900 + timeinfo.tm_year, 1 + timeinfo.tm_mon, timeinfo.tm_mday, hour );
34+
double hour = _fhour( timeinfo );
35+
return _getPhase( 1900 + timeinfo.tm_year, 1 + timeinfo.tm_mon, timeinfo.tm_mday, hour );
3636
}
3737

38-
moonData_t moonPhase::getInfo() {
38+
moonData_t moonPhase::getPhase() {
3939
time_t now;
4040
time( &now );
41-
return getInfo( now );
41+
return getPhase( now );
4242
}
4343

4444
double moonPhase::_Julian( int32_t year, int32_t month, const double &day )

moonPhase.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ struct moonData_t
2020
class moonPhase
2121
{
2222
public:
23-
moonData_t getInfo();
24-
moonData_t getInfo( const time_t t );
23+
moonData_t getPhase();
24+
moonData_t getPhase( const time_t t );
2525
private:
26-
moonData_t _getInfo( const int32_t &year, const int32_t &month, const int32_t &day, const double &hour );
27-
double fhour( const struct tm &timeinfo );
28-
double _Julian( int32_t year, int32_t month, const double &day );
29-
double _sun_position( const double &j );
30-
double _moon_position( const double &j, const double &ls );
31-
26+
moonData_t _getPhase( const int32_t &year, const int32_t &month, const int32_t &day, const double &hour );
27+
double _fhour( const struct tm &timeinfo );
28+
double _Julian( int32_t year, int32_t month, const double &day );
29+
double _sun_position( const double &j );
30+
double _moon_position( const double &j, const double &ls );
3231
};
3332
#endif

0 commit comments

Comments
 (0)