Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find('monitor')
- function getFormattedTime()
- local now = os.time()
- local hour = math.floor(now)
- local minute = math.floor(now * 60) % 60
- -- local second = math.floor(now * 60 * 60) % 60
- return ("%02d:%02d"):format(hour, minute)
- end
- function canSleep()
- local now = os.time()
- local tick = math.floor(((now + (24 - 6)) % 24) * 1000)
- -- print(tick)
- return 12542 <= tick and tick < 23460
- end
- function setup()
- monitor.setTextScale(1)
- end
- function setColor()
- if canSleep() then
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.black)
- else
- monitor.setTextColor(colors.black)
- monitor.setBackgroundColor(colors.white)
- end
- end
- function update()
- setColor()
- monitor.clear()
- monitor.setCursorPos(2, 3)
- monitor.write(getFormattedTime())
- end
- setup()
- while true do
- update()
- os.sleep()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement