Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --time = "night"
- mon = peripheral.wrap("back")
- function setColor(text, background)
- term.setTextColor(text)
- term.setBackgroundColor(background)
- end
- function drawImage(image)
- myImage = paintutils.loadImage(image)
- paintutils.drawImage(myImage, 1, 1)
- end
- function writeFile()
- handle = fs.open("dayOrNight", "w")
- handle.write(time)
- handle.close()
- end
- function loadFile()
- handle = fs.open("dayOrNight", "r")
- time = handle.readLine()
- handle.close()
- end
- function mWrite(message, cX, cY, background, text)
- mon.setBackgroundColor(background)
- if text == nil then mon.setTextColor(colors.black)
- else mon.setTextColor(text)
- end
- mon.setCursorPos(cX, cY)
- mon.write(message)
- mon.setBackgroundColor(colors.black)
- end
- function testClick()
- event, param1, x, y = os.pullEvent("monitor_touch")
- print("x: "..x)
- print("y; "..y)
- end
- function clock()
- clockTime = {}
- for i = 1, 24 do
- clockTime[i] = os.setAlarm(i)
- end
- end
- function writeTime()
- floorTime = math.floor(os.time())
- if floorTime > 9 then currTime = floorTime..":00"
- else currTime = "0"..floorTime..":00"
- end
- if time == "night" then
- mWrite(currTime, 13, 1, colors.black, colors.white)
- elseif time == "day" then
- mWrite(currTime, 13, 1, colors.lightBlue, colors.white)
- end
- end
- function day()
- term.clear()
- time = "day"
- drawImage("day")
- writeTime()
- redstone.setOutput("left", false)
- signal = "off"
- end
- function night()
- term.clear()
- time = "night"
- drawImage("night")
- writeTime()
- redstone.setOutput("left", true)
- signal = "on"
- end
- function updateClock()
- currTime = os.time()
- term.clear()
- drawImage(time)
- writeTime()
- end
- function determineTime()
- notInUse = os.time()
- if math.floor(os.time()) > 19 and math.floor(os.time()) < 6 or math.floor(os.time()) == 20 then night()
- elseif math.floor(os.time()) < 20 and math.floor(os.time()) > 5 or math.floor(os.time()) == 6 then day()
- end
- end
- ---------------------------------
- print("determining time")
- determineTime()
- print(time)
- term.redirect(mon)
- determineTime()
- ----------------------------------
- while true do
- clock()
- sunset = os.setAlarm(20)
- sunrise = os.setAlarm(6)
- for i = 1, 24 do
- event, arg, xpos, ypos = os.pullEvent()
- if event == "alarm" then
- determineTime()
- elseif event == "monitor_touch" and signal == "on" then
- -- day()
- redstone.setOutput("left", false)
- signal = "off"
- elseif event == "monitor_touch" and signal == "off" then
- -- night()
- redstone.setOutput("left", true)
- signal = "on"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement