|
|
Here's my ZBasic code which runs in the embedded hardware. It may be easier
to follow than the PureBasic code (which runs on a PC under
Windows/Linux/Mac) that I posted earlier.
The last 8 lines following 'dusk =' aren't directly related to
sunrise/sunset. This is accurate to a minute. The key question is whether
your embedded microcontroller can do floating point math.
Finally, I think Sky and Telescope Magazine was where I found the original
formula - they have numerous Basic language programs.
http://www.skyandtelescope.com/resources/software/3304911.html?page=1&c=y
'====================================================================
Sub NewDay()
Dim m As Byte
Dim d As Byte
Dim y As Integer
Dim n As Integer
Dim lo As Single
Dim c As Single
Dim C2 As Single
Dim SD As Single
Dim CD As Single
Dim sc As Single
Dim C3 As Single
Dim ds As Single
Dim zone As Single
Const RadiansPerDegree As Single = 0.017453293
yd = GetDayOfYear(Register.RTCDay)
ds = CSng((dstflags/2) And 1) 'DST offset
lo = 4.8771 + 0.0172 * (CSng(yd) + 0.5 - longitude / 360.0)
c = 0.03342 * Sin(lo + 1.345)
C2 = (1.0 / RadiansPerDegree) * (Atn(Tan(lo + c)) - Atn(0.9175 * Tan(lo +
c)) - c)
SD = 0.3978 * Sin(lo + c)
CD = Sqr(1.0 - SD * SD)
sc = (SD * Sin(latitude * RadiansPerDegree) + 0.0145) / _
(Cos(latitude * RadiansPerDegree) * CD) 'astronomical sunrise,
sunset
C3 = (1.0 / RadiansPerDegree) * Atn(sc / Sqr(1.0 - sc * sc))
n = CInt(((6.0 - zone -ds - (longitude + C2 + C3) / 15.0) / 24.0) *
1440.0)
dawn = (n\60)*100 + (n Mod 60)
n = CInt(((18.0 - zone -ds - (longitude + C2 - C3) / 15.0) / 24.0) *
1440.0)
dusk = (n\60)*100 + (n Mod 60)
Call GetHolidays(0)
Call GetTime(hh,mm,ss)
Now = CInt(hh) * 100 + CInt(mm)
tx = "0000" & CStr(Now)
tx = "NOW:" & Right(tx,4) & " DAY:" & CStr(yd) & " SUNRISE:0"
tx = tx & CStr(dawn) & " SUNSET:" & CStr(dusk) & " HOLIDAY:" &
CStr(holiday)
tx = tx & CrLf
Call PutStr(0, tx)
End Sub
'====================================================================
tomcee <tomcees_pc@xxxxxxxxx> wrote:
>Has anyone determined the basic functions contained within this
>'Sunset function'? Given the basic functions, I can then calculate the
>constants.
http://davehouston.net http://davehouston.org
http://tech.groups.yahoo.com/group/roZetta/
roZetta-subscribe@xxxxxxxxxxxxxxx
|
|