添加反射率定标
This commit is contained in:
@ -0,0 +1,35 @@
|
||||
//======================================================================================================================
|
||||
// SolarCalculator Library for Arduino example sketch: EquationOfTime.ino
|
||||
//
|
||||
// Plot the equation of time for a given year.
|
||||
//
|
||||
// Tested with Arduino IDE 1.8.19 and Arduino Uno
|
||||
//======================================================================================================================
|
||||
|
||||
#include <SolarCalculator.h>
|
||||
|
||||
int year = 2022;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// Starting day (January 1)
|
||||
JulianDay day(year, 1, 1);
|
||||
|
||||
for (int i = 0; i < 365; i++)
|
||||
{
|
||||
double eq;
|
||||
calcEquationOfTime(day, eq);
|
||||
|
||||
// Print and view with serial plotter (Ctrl+Shift+L)
|
||||
Serial.println(eq);
|
||||
|
||||
// Next day
|
||||
++day.JD;
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
//======================================================================================================================
|
||||
// SolarCalculator Library for Arduino example sketch: SolarCalculatorTimeLib.ino
|
||||
//
|
||||
// Calculate the rise and set times, equation of time, and current solar coordinates.
|
||||
//
|
||||
// Tested with Arduino IDE 1.8.19 and Arduino Uno
|
||||
//======================================================================================================================
|
||||
|
||||
#include <SolarCalculator.h>
|
||||
#include <TimeLib.h>
|
||||
|
||||
// Location
|
||||
double latitude = 45.55;
|
||||
double longitude = -73.633;
|
||||
int utc_offset = -5;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
double transit, sunrise, sunset; // Event times, in hours (UTC)
|
||||
double eq; // Equation of time, in minutes
|
||||
double ra, dec, r; // Equatorial coordinates, in degrees and AUs
|
||||
double az, el; // Horizontal coordinates, in degrees
|
||||
|
||||
// Set system time to compile time
|
||||
setTime(toUtc(compileTime()));
|
||||
|
||||
// Set time manually (hr, min, sec, day, mo, yr)
|
||||
//setTime(0, 0, 0, 1, 1, 2022);
|
||||
|
||||
// Get current time
|
||||
time_t utc = now();
|
||||
|
||||
calcEquationOfTime(utc, eq);
|
||||
calcEquatorialCoordinates(utc, ra, dec, r);
|
||||
calcHorizontalCoordinates(utc, latitude, longitude, az, el);
|
||||
calcSunriseSunset(utc, latitude, longitude, transit, sunrise, sunset);
|
||||
|
||||
// Print results
|
||||
Serial.print(F("Sunrise: "));
|
||||
printSunTime24h(sunrise + utc_offset);
|
||||
Serial.print(F("Transit: "));
|
||||
printSunTime24h(transit + utc_offset);
|
||||
Serial.print(F("Sunset: "));
|
||||
printSunTime24h(sunset + utc_offset);
|
||||
Serial.print(F("Eq of time: "));
|
||||
Serial.print(eq);
|
||||
Serial.println(F(" min"));
|
||||
Serial.print(F("RA: "));
|
||||
Serial.print(degreesToHours(ra), 3);
|
||||
Serial.print(F("h Dec: "));
|
||||
Serial.print(dec);
|
||||
Serial.print(F("° R: "));
|
||||
Serial.print(r, 6);
|
||||
Serial.println(F(" AU"));
|
||||
Serial.print(F("Az: "));
|
||||
Serial.print(az);
|
||||
Serial.print(F("° El: "));
|
||||
Serial.print(el);
|
||||
Serial.println(F("°"));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
time_t toUtc(time_t local)
|
||||
{
|
||||
return local - utc_offset * 3600L;
|
||||
}
|
||||
|
||||
double degreesToHours(double deg)
|
||||
{
|
||||
return deg / 15;
|
||||
}
|
||||
|
||||
// Code from JChristensen/Timezone Clock example
|
||||
time_t compileTime()
|
||||
{
|
||||
const uint8_t COMPILE_TIME_DELAY = 8;
|
||||
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
char chMon[4], *m;
|
||||
tmElements_t tm;
|
||||
|
||||
strncpy(chMon, compDate, 3);
|
||||
chMon[3] = '\0';
|
||||
m = strstr(months, chMon);
|
||||
tm.Month = ((m - months) / 3 + 1);
|
||||
|
||||
tm.Day = atoi(compDate + 4);
|
||||
tm.Year = atoi(compDate + 7) - 1970;
|
||||
tm.Hour = atoi(compTime);
|
||||
tm.Minute = atoi(compTime + 3);
|
||||
tm.Second = atoi(compTime + 6);
|
||||
time_t t = makeTime(tm);
|
||||
return t + COMPILE_TIME_DELAY;
|
||||
}
|
||||
|
||||
void printSunTime24h(double hours)
|
||||
{
|
||||
int m = int(round(hours * 60));
|
||||
int hr = (m / 60) % 24;
|
||||
int mn = m % 60;
|
||||
printDigits(hr);
|
||||
Serial.print(':');
|
||||
printDigits(mn);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printDigits(int digits)
|
||||
{
|
||||
if (digits < 10)
|
||||
Serial.print('0');
|
||||
Serial.print(digits);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
//======================================================================================================================
|
||||
// SolarCalculator Library for Arduino example sketch: SolarTrackingTimeLib.ino
|
||||
//
|
||||
// Monitor the Sun's position in the sky for any location on Earth.
|
||||
//
|
||||
// Tested with Arduino IDE 1.8.19 and Arduino Uno
|
||||
//======================================================================================================================
|
||||
|
||||
#include <SolarCalculator.h>
|
||||
#include <TimeLib.h>
|
||||
|
||||
// Location
|
||||
double latitude = 45.55;
|
||||
double longitude = -73.633;
|
||||
int utc_offset = -5;
|
||||
|
||||
// Refresh interval, in seconds
|
||||
int interval = 10;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// Set system time to compile time
|
||||
setTime(toUtc(compileTime()));
|
||||
|
||||
// Set time manually (hr, min, sec, day, mo, yr)
|
||||
//setTime(0, 0, 0, 1, 1, 2022);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static unsigned long next_millis = 0;
|
||||
|
||||
// At every interval
|
||||
if (millis() > next_millis)
|
||||
{
|
||||
time_t utc = now();
|
||||
double az, el;
|
||||
|
||||
// Calculate the solar position, in degrees
|
||||
calcHorizontalCoordinates(utc, latitude, longitude, az, el);
|
||||
|
||||
// Print results
|
||||
Serial.print(F("Az: "));
|
||||
Serial.print(az);
|
||||
Serial.print(F("° El: "));
|
||||
Serial.print(el);
|
||||
Serial.println(F("°"));
|
||||
|
||||
next_millis = millis() + interval * 1000L;
|
||||
}
|
||||
}
|
||||
|
||||
time_t toUtc(time_t local)
|
||||
{
|
||||
return local - utc_offset * 3600L;
|
||||
}
|
||||
|
||||
// Code from JChristensen/Timezone Clock example
|
||||
time_t compileTime()
|
||||
{
|
||||
const uint8_t COMPILE_TIME_DELAY = 8;
|
||||
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
||||
char chMon[4], *m;
|
||||
tmElements_t tm;
|
||||
|
||||
strncpy(chMon, compDate, 3);
|
||||
chMon[3] = '\0';
|
||||
m = strstr(months, chMon);
|
||||
tm.Month = ((m - months) / 3 + 1);
|
||||
|
||||
tm.Day = atoi(compDate + 4);
|
||||
tm.Year = atoi(compDate + 7) - 1970;
|
||||
tm.Hour = atoi(compTime);
|
||||
tm.Minute = atoi(compTime + 3);
|
||||
tm.Second = atoi(compTime + 6);
|
||||
time_t t = makeTime(tm);
|
||||
return t + COMPILE_TIME_DELAY;
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
//======================================================================================================================
|
||||
// SolarCalculator Library for Arduino example sketch: SunriseSunset.ino
|
||||
//
|
||||
// Calculate the times of sunrise, solar noon, and sunset for a given date and location.
|
||||
//
|
||||
// Tested with Arduino IDE 1.8.19 and Arduino Uno
|
||||
//======================================================================================================================
|
||||
|
||||
#include <SolarCalculator.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// Date
|
||||
int year = 2022;
|
||||
int month = 1;
|
||||
int day = 1;
|
||||
|
||||
// Location
|
||||
double latitude = 45.55;
|
||||
double longitude = -73.633;
|
||||
int utc_offset = -5;
|
||||
|
||||
double transit, sunrise, sunset;
|
||||
|
||||
// Calculate the times of sunrise, transit, and sunset, in hours (UTC)
|
||||
calcSunriseSunset(year, month, day, latitude, longitude, transit, sunrise, sunset);
|
||||
|
||||
// Get the approximate times (minimum program size) (iterations = 0)
|
||||
//calcSunriseSunset(year, month, day, latitude, longitude, transit, sunrise, sunset, SUNRISESET_STD_ALTITUDE, 0);
|
||||
|
||||
// Print results
|
||||
char str[6];
|
||||
Serial.println(hoursToString(sunrise + utc_offset, str));
|
||||
Serial.println(hoursToString(transit + utc_offset, str));
|
||||
Serial.println(hoursToString(sunset + utc_offset, str));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// Rounded HH:mm format
|
||||
char * hoursToString(double h, char *str)
|
||||
{
|
||||
int m = int(round(h * 60));
|
||||
int hr = (m / 60) % 24;
|
||||
int mn = m % 60;
|
||||
|
||||
str[0] = (hr / 10) % 10 + '0';
|
||||
str[1] = (hr % 10) + '0';
|
||||
str[2] = ':';
|
||||
str[3] = (mn / 10) % 10 + '0';
|
||||
str[4] = (mn % 10) + '0';
|
||||
str[5] = '\0';
|
||||
return str;
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
//======================================================================================================================
|
||||
// SolarCalculator Library for Arduino example sketch: SunriseSunsetAltitude.ino
|
||||
//
|
||||
// Calculate the rise and set times at a height above the level of the horizon.
|
||||
//
|
||||
// Tested with Arduino IDE 1.8.19 and Arduino Uno
|
||||
//======================================================================================================================
|
||||
|
||||
#include <SolarCalculator.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
|
||||
// Date
|
||||
int year = 2022;
|
||||
int month = 1;
|
||||
int day = 1;
|
||||
|
||||
// Location
|
||||
double latitude = 45.5034;
|
||||
double longitude = -73.5869;
|
||||
int utc_offset = -5;
|
||||
|
||||
double transit, sunrise, sunset;
|
||||
|
||||
// From the Explanatory Supplement to the Astronomical Almanac (1992), p. 484
|
||||
// Sunrise or sunset at a height above the level of the horizon occurs when the Sun's altitude is approximately:
|
||||
|
||||
int height = 200; // in meters
|
||||
double sun_altitude = SUNRISESET_STD_ALTITUDE - 0.0353 * sqrt(height);
|
||||
|
||||
// Calculate the times of sunrise, transit, and sunset, in hours (UTC)
|
||||
calcSunriseSunset(year, month, day, latitude, longitude, transit, sunrise, sunset, sun_altitude);
|
||||
|
||||
// Print results
|
||||
char str[6];
|
||||
Serial.println(hoursToString(sunrise + utc_offset, str));
|
||||
Serial.println(hoursToString(transit + utc_offset, str));
|
||||
Serial.println(hoursToString(sunset + utc_offset, str));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// Rounded HH:mm format
|
||||
char * hoursToString(double h, char *str)
|
||||
{
|
||||
int m = int(round(h * 60));
|
||||
int hr = (m / 60) % 24;
|
||||
int mn = m % 60;
|
||||
|
||||
str[0] = (hr / 10) % 10 + '0';
|
||||
str[1] = (hr % 10) + '0';
|
||||
str[2] = ':';
|
||||
str[3] = (mn / 10) % 10 + '0';
|
||||
str[4] = (mn % 10) + '0';
|
||||
str[5] = '\0';
|
||||
return str;
|
||||
}
|
Reference in New Issue
Block a user