-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMoonPhase.hpp
More file actions
39 lines (34 loc) · 919 Bytes
/
MoonPhase.hpp
File metadata and controls
39 lines (34 loc) · 919 Bytes
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
39
/*
MoonPhase.hpp - Library to get moon phase angle
and amount 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_hpp
#define MoonPhase_hpp
#include <Arduino.h>
struct moonData_t
{
int32_t angleDeg;
double amountLit;
};
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