Skip to content

Commit 8ceef37

Browse files
Changed types so it will work on 8 bit controllers.
Precision will be less on 8 bit CPUs like Arduino UNO.
1 parent 6e9042c commit 8ceef37

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

MoonPhase.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "MoonPhase.h"
2+
#include <inttypes.h>
23

3-
MoonPhase::moonData MoonPhase::getInfo( const int year, const int month, const int day, const double hour )
4+
MoonPhase::moonData MoonPhase::getInfo( const int32_t year, const int32_t month, const int32_t day, const double hour )
45
{
56
/*
67
Calculates the phase of the moon at the given epoch.
@@ -17,17 +18,17 @@ MoonPhase::moonData MoonPhase::getInfo( const int year, const int month, const i
1718
return returnValue;
1819
}
1920

20-
double MoonPhase::_Julian( int year, int month, double day )
21+
double MoonPhase::_Julian( int32_t year, int32_t month, double day )
2122
{
22-
int b, c, e;
23+
int32_t b, c, e;
2324
b = 0;
2425
if (month < 3) {
2526
year--;
2627
month += 12;
2728
}
2829
if (year > 1582 || (year == 1582 && month > 10) ||
2930
(year == 1582 && month == 10 && day > 15)) {
30-
int a;
31+
int32_t a;
3132
a = year / 100;
3233
b = 2 - a + a / 4;
3334
}
@@ -39,7 +40,7 @@ double MoonPhase::_Julian( int year, int month, double day )
3940
double MoonPhase::_sun_position( const double j )
4041
{
4142
double n, x, e, l, dl, v;
42-
int i;
43+
int32_t i;
4344
n = 360 / 365.2422 * j;
4445
i = n / 360;
4546
n = n - i * 360.0;
@@ -61,7 +62,7 @@ double MoonPhase::_sun_position( const double j )
6162
double MoonPhase::_moon_position( double j, double ls )
6263
{
6364
double ms, l, mm, ev, sms, ae, ec;
64-
int i;
65+
int32_t i;
6566
ms = 0.985647332099 * j - 3.762863;
6667
if (ms < 0) ms += 360.0;
6768
l = 13.176396 * j + 64.975464;

MoonPhase.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
and percentage illuminated. (as seen from Earth)
44
Created by Marcel Timmer, April 28, 2018.
55
Code adapted from http://www.voidware.com/phase.c
6-
A big thanks to Hugh at voidware from granting permission.
6+
A big thanks to Hugh at voidware for granting permission.
77
Released under MIT license.
88
*/
99
#ifndef MoonPhase_h
@@ -17,15 +17,15 @@ class MoonPhase
1717

1818
struct moonData
1919
{
20-
int angle;
21-
float percentLit;
20+
int32_t angle;
21+
double percentLit;
2222
};
2323

24-
moonData getInfo( const int year, const int month, const int day, const double hour );
24+
moonData getInfo( const int32_t year, const int32_t month, const int32_t day, const double hour );
2525

2626
private:
2727

28-
double _Julian( int year, int month, double day );
28+
double _Julian( int32_t year, int32_t month, double day );
2929

3030
double _sun_position( const double j );
3131

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ An Arduino library to get the moon phase angle and percentage of the moon that i
77
1. Download the latest release and unpack in the Arduino `libraries` folder.
88
2. Restart the Arduino IDE.
99

10-
A simple example that should run on most 16 and 32 bits Arduino supported boards is included.
10+
A simple example that should run on most Arduino IDE supported boards is included.
1111

1212
A more elaborate example only suitable for an ESP32 with an ILI9341 tft display can be found in the `esp32/ILI9341` folder.
1313

1414
## Issues:
1515

16-
This library will not work on most 8 bit Arduino boards, as these have no real `double` data type available.
16+
Precision will be smaller on 8 bit Arduino boards, as these have no real `double` data type available.

0 commit comments

Comments
 (0)