Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Predeclare Functions
- local clear
- local rnd
- local dbug
- local doSunrise
- local doSunset
- --Variable defaults and settings
- local debugmode = false --set to true for debug readout
- local mon = peripheral.wrap( "left" )
- local side = "right" --redstone output side
- local redside = "bottom" --redstone input side
- local readout = "Waiting"
- local time1 = 6.10
- local time2 = 18.00
- local event = "blank"
- local input = "blank"
- local timecheck
- --Functions
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function rnd() --reset and display
- clear()
- mon.clear()
- mon.setCursorPos(1,1)
- sunrise = os.setAlarm(time1)
- sunset = os.setAlarm(time2)
- print(readout)
- mon.write(readout)
- end
- function dbug()
- print("event:" .. event)
- print("input:" .. input)
- print("readout:" .. readout)
- end
- function doSunrise()
- redstone.setOutput(side, true)
- sleep(0.1)
- redstone.setOutput(side, false)
- sleep(0.1)
- redstone.setOutput(side, true)
- readout = "Morning."
- rnd()
- if debugmode == true then
- dbug()
- end
- print("Door Open.")
- sleep(0.8)
- end
- function doSunset()
- redstone.setOutput(side, true)
- sleep(0.1)
- redstone.setOutput(side, false)
- readout = "Night."
- rnd()
- if debugmode == true then
- dbug()
- end
- print("Door Shut.")
- sleep(0.9)
- end
- --Code Start
- mon.setTextScale(1)
- rnd()
- --Fires once to set current time and door state
- timecheck = os.time()
- if ( timecheck >= 6.10 and timecheck < 18.00 ) then
- doSunrise()
- elseif ( timecheck >= 18.00 or timecheck < 6.00 ) then
- doSunset()
- end
- --Main block
- while true do
- event, input = os.pullEvent()
- if event == "alarm" and input == sunrise then
- doSunrise()
- elseif event == "alarm" and input == sunset then
- doSunset()
- elseif event == "redstone" and redstone.getInput(redside) == true then
- if redstone.getOutput(side) == false then
- redstone.setOutput(side, true)
- print("Door Open.")
- sleep(1)
- redstone.setOutput(side, false)
- print("Door Shut.")
- end
- end
- end
- clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement