Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitorName = "top"
- local rainSensor = "right"
- --Basic Variables
- local textSize = 1
- local militaryTime = true
- local updateDelay = 2
- --Customize Notifications
- local dayMessage = "Day"
- local nightMessage = "Night"
- local clearMessage = "Clear"
- local rainMessage = "Storm"
- --Used on Advanced Monitors
- local timeColor = colors.white
- local dayTextColor = colors.lightBlue
- local nightTextColor = colors.blue
- local dayBackColor = colors.black
- local nightBackColor = colors.black
- local clearWeatherColor = colors.yellow
- local rainyWeatherColor = colors.red
- --Used Internally
- local monitor = nil
- local rainOn = false
- local isAm = true
- local tTime
- local x = 1
- local y = 1
- local function getSetup()
- print("Connecting to monitor.")
- while monitor == nil do
- monitor = peripheral.wrap(monitorName)
- if monitor == nil then
- print("Waiting for monitor.")
- os.sleep(2)
- end
- end
- print("Monitor found. Establishing base variables.")
- monitor.clear()
- monitor.setTextScale(textSize)
- x, y = monitor.getSize()
- if y < 3 then
- print("Text size too large for current monitor. Please adjust.")
- end
- end
- local function centerText(cString)
- local sSize = string.len(cString)
- if sSize < x then
- offset = math.floor((x - sSize) / 2) + 1
- else
- offset = 1
- end
- return offset
- end
- local function formatTime(curTime)
- local curHour = 1
- local curMin = 1
- local strTime = ""
- curHour = math.floor(curTime)
- curMin = math.floor((curTime - curHour) * 60)
- if curHour < 12 then
- isAm = true
- else
- isAm = false
- if militaryTime == false then
- curHour = curHour - 12
- end
- end
- if curMin < 10 then
- curMin = "0"..curMin
- end
- if curHour < 10 then
- strTime = "0"..curHour..":"..curMin
- else
- strTime = tostring(curHour)..":"..curMin
- end
- return strTime
- end
- getSetup()
- if y >= 3 then
- print("Starting main loop.")
- while true do
- tTime = formatTime(os.time())
- if monitor.isColor() then
- if isAm then
- monitor.setBackgroundColor(dayBackColor)
- else
- monitor.setBackgroundColor(nightBackColor)
- end
- end
- monitor.clear()
- if militaryTime == false then
- if isAm then
- tTime = tTime.." AM"
- else
- tTime = tTime.." PM"
- end
- end
- monitor.setCursorPos(centerText(tTime),1)
- if monitor.isColor() then
- monitor.setTextColor(timeColor)
- end
- monitor.write(tTime)
- if os.time() < 6 or os.time() > 18 then
- if monitor.isColor() then
- monitor.setTextColor(nightTextColor)
- end
- monitor.setCursorPos(centerText(nightMessage),2)
- monitor.write(nightMessage)
- else
- if monitor.isColor() then
- monitor.setTextColor(dayTextColor)
- end
- monitor.setCursorPos(centerText(dayMessage),2)
- monitor.write(dayMessage)
- end
- if redstone.getInput(rainSensor) then
- if monitor.isColor() then
- monitor.setTextColor(rainyWeatherColor)
- end
- monitor.setCursorPos(centerText(rainMessage),3)
- monitor.write(rainMessage)
- else
- if monitor.isColor() then
- monitor.setTextColor(clearWeatherColor)
- end
- monitor.setCursorPos(centerText(clearMessage),3)
- monitor.write(clearMessage)
- end
- os.sleep(updateDelay)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement