Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.exists("button") ~= true then
- shell.run("pastebin get xujPVbgB button")
- end
- local red = "right"
- local margin = 1
- local textScale = 2
- local maxRunningTicks = 400 -- 20 seconds
- local eveningStart = 19
- local morningStart = 6
- local morningEnd = 12
- os.loadAPI("button")
- mon = peripheral.find("monitor")
- mon.setTextScale(textScale)
- x,y = mon.getSize()
- mon.clear()
- rs.setOutput(red, false)
- function setTime(timeOfDay)
- local runningTicks = 0
- rs.setOutput(red, true)
- print("setting time to: " .. timeOfDay)
- if timeOfDay == "morning" then
- -- wait for morning [6.00]
- while(os.time() < morningStart or os.time() > morningEnd) do
- sleep(.05) -- one tick
- runningTicks = runningTicks + 1
- if(runningTicks > maxRunningTicks) then break end -- Failsafe
- end
- elseif timeOfDay == "evening" then
- -- wait for evening [18.541]
- while(os.time() < eveningStart) do
- sleep(.05) -- one tick
- runningTicks = runningTicks + 1
- if(runningTicks > maxRunningTicks) then break end -- Failsafe
- end
- end
- print("done")
- -- turn off
- rs.setOutput(red, false)
- end
- function Menu()
- button.clearTable()
- button.setTable("Morning", setTime, "morning", 1, (x/2)-margin, 1, y)
- button.setTable("Evening", setTime, "evening", (x/2)+margin, x, 1, y)
- button.screen()
- end
- while true do
- Menu()
- timerCode = os.startTimer(1)
- local event, side, x, y
- repeat
- event, side, x, y = os.pullEvent()
- until event == "monitor_touch"
- button.checkxy(x,y)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement