Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- timeOfDay = "Day"
- os.loadAPI("ocs/apis/sensor")
- mySensor = sensor.wrap("top")
- currentMinutes = -1
- currentSeconds = -1
- function printTime(minutes, seconds)
- currentSeconds = seconds
- currentMinutes = minutes
- min = tostring(minutes)
- sec = tostring(seconds)
- if string.len(sec) == 1 then
- sec = "0"..sec
- end
- if timeOfDay == "Day" then
- term.clear()
- term.setCursorPos(1,1)
- print(min..":"..sec.." till Night")
- else
- term.clear()
- term.setCursorPos(1,1)
- print(min..":"..sec.." till Day")
- end
- end
- function getTime()
- returnedString = textutils.serialize(mySensor.getTargets())
- angleIdx = string.find(returnedString, "Angle") + 8
- timeRatio = tonumber(string.sub(string.sub(returnedString,angleIdx), 1, -5))
- if timeRatio >= .5 then
- timeRatio = timeRatio - .5
- timeOfDay = "Night"
- else
- timeOfDay = "Day"
- end
- time = 10 - 2 * (10 * timeRatio)
- minutes = math.floor(time)
- secondsDecimal = time - minutes
- seconds = math.floor(secondsDecimal * 60)
- if (seconds ~= currentSeconds or minutes ~= currentMinutes) then
- printTime(minutes, seconds)
- end
- end
- function run()
- while true do
- getTime()
- end
- end
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement