Welcome Guest, you are in: Login

Fruit Of The Shed

Navigation (MMBasic)






Search the wiki

»


Page History: Quick and Dirty Daylight Indicator

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: 2017/09/22 13:21


The following is a function to provide a Boolean indicator of whether the given Month, Hour & minute occur during "Civil Daylight" i.e. this is the time considered between sunrise and sunset not including any twilight. It was written to provide some intelligence to exterior lighting so that it is only activated around the hours of darkness.

It is very rough and ready and the use of daylight means it covers dawn & dusk (especially during the equinox zones). This means that although the daylight hours change considerably between the start and finish of say, March, The use of daylight will cover the twilight periods and so a degree of "over-compensation" is seen. It also means that we only need to be concerned with whole months rather than specific dates which makes the function much smaller and less complex.

The times in the data statements are UTC (i.e. no daylight saving time) in 12 groups and are hard-coded for London, UK - you will need to change these for your own location and time format if necessary. The start and finish are specified as minutes from midnight. A day contains 1440 minutes and so daylight may start at the 405th minute and continue until the 1060th minute (so full daylight starts at 06:45 and ends at 17:40). This sunrise/set lookup tool online tool was used to obtain the daylight times (as Hours *60 + Minutes).


Syntax:
x=Daylight(Month,Hour,Minute)

Example Uses:
DaylightAug5am=Daylight(8,5,0)

If Daylight(Val(Mid$(DATE$,4,2)),Val(Left$(TIME$,2)),Val(Mid$(TIME$,4,2))) Then LightsOff Else LightsOn


Code
	Function DayLight(mm as integer,h as integer,m as integer) as integer
		local integer mn,st,fn

		select case mm
			Case 1:st=480:fn=960 	'08h00-16h00 start/end of full daylight GMT, London UK - probably OK for all of UK
			Case 2:st=460:fn=1010	'07h40-16h50 you may need to tweak these for your location
			Case 3:st=405:fn=1060	'06h45-17h40
			Case 4:st=335:fn=1115	'05h35-18h35
			Case 5:st=270:fn=1165	'04h30-19h25
			Case 6:st=230:fn=1210	'03h50-20h10
			Case 7:st=230:fn=1220	'03h50-20h20
			Case 8:st=265:fn=1190	'04h25-19h50
			Case 9:st=315:fn=1125	'05h15-18h45
			Case 10:st=360:fn=1060	'06h00-17h40
			Case 11:st=410:fn=990	'06h50-16h30
			Case 12:st=465:fn955	'07h45-15h55
		end select

		mn=h*60+m ' mins of day
		if mn>st and mn<fn then
			DayLight=1
		else
			DayLight=0
		endif
	end function