Local Sidereal Time on Atmega328 (Arduino)

Sokat nem tennék hozzá, egy távcsőves projektemhez van szükség rá, hátha másnak is jól jön.

Itt a sketch:

/* Based on http://astro.neutral.org/arduino/local-sidereal-time-arduino-microcontroller.shtml
and https://forum.arduino.cc/index.php?topic=359573.0 V-drive user's example.

távcsőves 2017.06.24.
*/

#include <RTClib.h> // https://github.com/adafruit/RTClib
#include <Wire.h>
RTC_DS3231 RTC;

int TIMEZONE = 1; // Your timezone, my location timezone is 1 (Central Europe)
int DST = 1; // Value = 1 if summer time, in winter value = 0
float LONGITUDE = 15.28133; // Your position to the Earth (West value - sign. My current position in the example, if you not have GPS receiver, Google Maps tell your cordinate's.)

void setup()
{
Serial.begin(9600);
Wire.begin();
RTC.begin();
}

void loop() {
CalculateLST();
delay(1000);
}

void CalculateLST() { // Calculate Local Sidereal Time
DateTime now = RTC.now();

double M, Y, D, MN, H, S;
double A, B, C, E, F;

M = (int)now.month();
Y = (int)now.year();
D = (int)now.day();
MN = (int)now.minute();
H = (int)now.hour() - (TIMEZONE + DST); // Hours must be GMT/UT.
S = (int)now.second();

if (M < 3) {
M += 12;
Y -= 1;
}

A = (long)Y / 100;
B = (long)A / 4;
C = (long)2 - A + B;
E = (long)(365.25 * (Y + 4716));
F = (long)(30.6001 * (M + 1));

double LastJDN = C + D + E + F - 1524.5; // Julian day last midnight UT
double Current_d = LastJDN - 2451545.0; //Days since Year 2000
long Current_T = Current_d / 36525; // Julian centuries since Year 2000
long NewJDN = LastJDN + H / 24; // Julian day today

Serial.println();
Serial.print("Julian Day Number..: ");
Serial.print(NewJDN); // Julian day today

double Term1 = 6.697374558; // this line must be a double!
double Term2 = 0.06570982441908 * Current_d;

H = H + ((double)MN / 60) + ((double)S / 3600);

float GMST;
float Term3;

Term3 = 0.00273790935 * H;
Term3 += H;
GMST = Term1 + Term2 + Term3; // Terms are found at http://aa.usno.navy.mil/faq/docs/GAST.php

//add on longitude divided by 15 to get LST

double LST = GMST + (LONGITUDE / 15); // longitude as hour angle.

//reduce it to 24 format

int LSTint;
LSTint = (int)LST;
LSTint /= 24;
LST = LST - (double)LSTint * 24;

int LST_H = (int)LST;
int LST_M = ((LST - LST_H) * 60);
int LST_S = (((LST - LST_H) * 60) - LST_M) * 60;

Serial.println();
Serial.print("Local Sidereal time: ");
Serial.print(LST_H);
Serial.print(':');
Serial.print(LST_M);
Serial.print(':');
Serial.println(LST_S);
}

Hirdetés

3 pénzügyi döntés, amit minden kisvállalkozónak érdemes átgondolnia az év végéig

PR Ahogy az év vége közeledik, itt az ideje, hogy egy pillanatra megálljunk és áttekintsük vállalkozásunk pénzügyi helyzetét. Ne hagyjuk, hogy az év utolsó hónapjai elússzanak a sürgető feladatok és elfeledett határidők között!

Tovább a fórumba.