Giter Site home page Giter Site logo

jc_sunrise's Introduction

Arduino Sunrise Library

https://github.com/JChristensen/JC_Sunrise
README file

License

Arduino Sunrise Library Copyright (C) 2021 Jack Christensen GNU GPL v3.0

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v3.0 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/gpl.html

Introduction

Library to calculate sunrise and sunset times, for a given latitude, longitude, and zenith of the sun.

Prerequisite Libraries

Example Sketch

The following example sketch is included with the JC_Sunrise library:

  • PrintListing: Prints a listing of sunrise and sunset times for a given range of years.

Constructor

JC_Sunrise(lat, lon, zenith)

Description

The constructor defines a JC_Sunrise object for a particular location.

Syntax

JC_Sunrise(lat, lon, zenith);

Required parameters

lat: Latitude (float)
lon: Longitude (float)
zenith: Sun's zenith for sunrise/sunset (float)

Several constants are available that can be used for the zenith parameter:

JC_Sunrise::officialZenith {90.83333}  
JC_Sunrise::civilZenith {96.0}  
JC_Sunrise::nauticalZenith {102.0}  
JC_Sunrise::astronomicalZenith {108.0}
Example
constexpr float myLat {45.8171}, myLon {-84.7278};
JC_Sunrise sun {myLat, myLon, JC_Sunrise::officialZenith};

Library Functions

void calculate(time_t t, int utcOffset, int& sunriseOut, int& sunsetOut);

Description

Calculates sunrise and sunset times as single integers of the form HHMM, for the day given by the local epoch time t.

Syntax

calculate(t, utcOffset, sunriseOut, sunsetOut);

Input Parameters

t: Local epoch time (time_t)
utcOffset: UTC offset in minutes (int)

Output Parameters

sunriseOut: Time of sunrise for the given day, HHMM (int)
sunsetOut: Time of sunset for the given day, HHMM (int)

Returns

None.

Example
constexpr float myLat {45.8171}, myLon {-84.7278};
JC_Sunrise sun {myLat, myLon, JC_Sunrise::officialZenith};

// 01Jan2022 08:00:00 EST0
int utcOffset {-300};
tmElements_t tm;
tm.Year = 2022 - 1970;
tm.Month = tm.Day = 1;
tm.Hour = 8; tm.Minute = tm.Second = 0;
time_t localTime = makeTime(tm);
int sunrise, sunset;
sun.calculate(localTime, utcOffset, sunrise, sunset);
Serial.print(sunrise);      // 820
Serial.print(' ');
Serial.println(sunset);     // 1705

void calculate(time_t t, int utcOffset, time_t& sunriseOut, time_t& sunsetOut);

Description

As above, except the sunrise and sunset times are returned as time_t values.

Syntax

calculate(t, utcOffset, sunriseOut, sunsetOut);

Input Parameters

t: Local epoch time (time_t)
utcOffset: UTC offset in minutes (int)

Output Parameters

sunriseOut: Time of sunrise for the given day (time_t)
sunsetOut: Time of sunset for the given day (time_t)

Returns

None.

Example
constexpr float myLat {45.8171}, myLon {-84.7278};
JC_Sunrise sun {myLat, myLon, JC_Sunrise::officialZenith};

// 01Jan2022 08:00:00 EST
int utcOffset {-300};
tmElements_t tm;
tm.Year = 2022 - 1970;
tm.Month = tm.Day = 1;
tm.Hour = 8; tm.Minute = tm.Second = 0;
time_t localTime = makeTime(tm);
time_t sunrise, sunset;
sun.calculate(localTime, utcOffset, sunrise, sunset);
Serial.print(hour(sunrise));        // 8
Serial.print(' ');
Serial.print(minute(sunrise));      // 20
Serial.print(' ');
Serial.print(hour(sunset));         // 17
Serial.print(' ');
Serial.println(minute(sunset));     // 5

jc_sunrise's People

Contributors

jchristensen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.