-
Notifications
You must be signed in to change notification settings - Fork 6
/
moonPhase.h
38 lines (34 loc) · 883 Bytes
/
moonPhase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
MoonPhase.h - Library to get moon phase angle
and percentage illuminated. (as seen from Earth)
Created by Marcel Timmer, April 28, 2018.
Code adapted from http://www.voidware.com/phase.c
A big thanks to Hugh at voidware for granting permission.
Released under MIT license.
*/
#ifndef MoonPhase_h
#define MoonPhase_h
#include <Arduino.h>
struct moonData_t
{
int32_t angle;
double percentLit;
};
class moonPhase
{
public:
moonData_t getPhase(const time_t t)
{
struct tm timeinfo;
gmtime_r(&t, &timeinfo);
return _getPhase(1900 + timeinfo.tm_year, 1 + timeinfo.tm_mon, timeinfo.tm_mday, _fhour(timeinfo));
}
moonData_t getPhase()
{
return getPhase(time(NULL));
}
private:
double _fhour(const struct tm &timeinfo);
moonData_t _getPhase(const int32_t year, const int32_t month, const int32_t day, const double &hour);
};
#endif