Sunrise

Description

Calculates sunrise and sunset for the current day of the year and given latitude and longitude.

OVERVIEW

Sunrise_Abstract:
This library can be used to Calculate sunrise and sunset for the current day of the year and given latitude and longitude.

Interfaces: No hardware interface required
Sunrise_How_to_use:
/* Setup */ const { // Location for which the sunrise and sunset should be calculated Float:POSITION_LAT = 47.770364, // Latitude [°] Float:POSITION_LONG = 13.334748, // Longitude [°] TIME_BASE = 0, // Selection of whether sunrise and sunset are returned // in UTC or local time (Use "0" = Local Time, "SUN_USE_UTC" = UTC) } main(){ new iSunrise; // Calculated sunrise [min] new iSunset; // calculated sunset [min] new DayOfYear = Sun_GetDayOfYear(); // Determines the day of the year (optional) #watch("DayOfYear=%d",DayOfYear); // Issues the day of the year via the watch panel (optional) // Calculates the sunrise and sunset for the desired location an issues it via the watch panel Sun_GetDayLimit(iSunrise, iSunset,POSITION_LAT, POSITION_LONG, TIME_BASE); #watch("Sunrise=%d",iSunrise); #watch("Sunset=%d",iSunset); }

BASIC

SUN_USE_UTC -

Must be used for the "iFlags" parameter of the Sun_GetDayLimit() function if the sunrise and sunset should be returned in UTC

Sun_GetDayOfYear()

The function returns the day of the year, starting with 1 (January 1st).

Leap years are not taken into account
returns : s32 - Day of the year
Sun_GetDayLimit(&iSunrise, &iSunset, Float:fLatitude=DEF_POSITION_LAT, Float:fLongitude=DEF_POSITION_LONG, iFlags=0)

This functioncan be used to calculate sunrise and sunset for the current day of the year and given latitude and longitude.


The information that is needed for sunrise and sunset calculation can be split up to two parts:

  • Equation of time: Provides information about the difference between apparent solar time and mean solar time. This is necessary because the apparent solar time can differ up to 15 minutes from the mean solar time. The time equation can be understood as the difference between a mechanical or electrical clock and a sundial (our clocks always use a 24 hours time span for one day).

  • Time difference: This is the actual time span during which the sun is above the horizon (sunrise to midday or midday to sunset). To calculate this time difference the declination of the sun is needed. The declination is defined as the angular distance of a point (heavenly body -> in this case the sun) north or south of the celestial equator.
  • if latitude and longitude are not specified sunrise and sunset are calculated for the center of Austria (approximately St. Gilgen)
    iSunrise : s32 - Buffer for storing the calculated sunrise at given longitude and time zone in minutes
    iSunset : s32 - Buffer for storing the calculated sunset at given longitude and time zone in minutes
    fLatitude : Float - Latitude of the location for which the sunrise and sunset should be calculated [°]
    fLongitude : Float - Longitude of the location for which the sunrise and sunset should be calculated [°]
    iFlags : s32 - Selection of whether sunrise and sunset are returned in UTC or local time
    0 - Local time is uses (i.e. Time Zone Offset is taken into account)
    SUN_USE_UTC - UTC is used

    DEBUG

    Sunrise_Debug_Config:
    To configure debug mode add the following macro to the main.dde file.
    /** * Use this macro to configure the debug mode: * * 0: No debugging * 1: Issues the "Day of the year" and the "Time Zone Offset" via the console * when calling Sun_GetDayLimit */ #define DEBUG_SUNRISE 0

    On this page

    Sunrise