Skip to content

Instantly share code, notes, and snippets.

@DarkMukke
Last active August 1, 2023 15:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkMukke/59389cde70be64ee97797cffa70c4384 to your computer and use it in GitHub Desktop.
Save DarkMukke/59389cde70be64ee97797cffa70c4384 to your computer and use it in GitHub Desktop.
probably the same amount of components, just simple
Also you could display the hours and minutes on 2 different displays
;; I have used long variable names to reduce confusion,
;; daylightSensorDegrees integer (0 -> 180 and back after midnight)
;; daylightSensorVisible integer ( 0 || 1)
;; daylightSensorMax integer 180
memTrue = 1
memFalse = 0
;; effectively a NOT or toggle switch
daylightSensorVisibleNot = if( daylightSensorVisible ) then memFalse else memTrue
;; will only be great than 0 before midnight
daytimeOnlyDegrees = daylightSensorDegrees * daylightSensorVisible
;; * -1 makes it counts upwards instead of backwards
nightUpCount = daylightSensorDegrees * -1
;; as above, will only be greater than 0 after midnight
nightOnlyDegrees daylightSensorVisibleNot * nightUpCount
fullCircle = daytimeOnlyDegrees + nightOnlyDegrees
;; so at this point fullCircle is a range between -180 and 180
;; offsetting that by 180 gives you 0 -> 360, 0/360 at sundown, 180 at sunsrise
;; but we might aswell already calculate in the clock offset
;; so we want 0 at the bottom of the circle for midnigt, so we only offset by 90
memCircleTimeOffset = 90
circleOffset = fullCircle + memCircleTimeOffset
;; this means:
;; 0 -> midnight
;; 90 -> sunrise
;; 180 -> noon
;; 270 -> sunset
;; now after 270 the value will be negative, so we can just correct the value with a switch
memCircleNegativeCorrection = 360;
circleCorrected = circleOffset + memCircleNegativeCorrection
circleEffective = if( circleOffset < 0 ) then circleCorrected else circleOffset
;; so at this point you have a 0 -> 360 circle, where 0 is midnight
;; 360 / 24 = 15, so every hour is 15 degrees
memDegreesPerHour = 15
memMinutes = 60
memMilitaryFactor = 100
time = circleEffective / memDegreesPerHour
hours = floor( time )
timeDecimals = time - hours
timeMinutes = timeDecimals * memMinutes
minutes = floor( timeMinutes )
militaryHours = hours * memMilitaryFactor
militaryTime = militaryHours + minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment