Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ints = {peripheral.find("redstone_integrator")}
- local mons = {peripheral.find("monitor")}
- local openTime = 15
- local scale = 4
- local function forEachPeripheral(periphs, func)
- local x = {}
- for i, periph in ipairs(periphs) do
- table.insert(x, {func(periph, i)})
- end
- return x
- end
- local function turnOn()
- forEachPeripheral(
- ints,
- function(integrator)
- for i, side in ipairs(integrator.getSides()) do
- integrator.setOutput(side, true)
- end
- end
- )
- end
- local function turnOff()
- forEachPeripheral(
- ints,
- function(integrator)
- for i, side in ipairs(integrator.getSides()) do
- integrator.setOutput(side, false)
- end
- end
- )
- end
- local function writeMonitors(col1, col2, stuff)
- forEachPeripheral(
- mons,
- function(monitor)
- monitor.setBackgroundColor(col1 or colors.black)
- monitor.setTextColor(col2 or colors.white)
- monitor.clear()
- monitor.setTextScale(scale)
- monitor.setCursorPos(1, 1)
- monitor.write(stuff or "")
- end
- )
- end
- local function wait(tm)
- local tmr = os.startTimer(tm)
- while true do
- local ev, tmr2 = os.pullEventRaw()
- if ev == "terminate" then
- turnOff()
- error("Terminated", 0)
- elseif ev == "timer" and tmr == tmr2 then
- return
- end
- end
- end
- local function countDown()
- local sizes = forEachPeripheral(
- mons,
- function(monitor)
- return monitor.getSize()
- end
- )
- for i = openTime, 0, -1 do
- forEachPeripheral(
- mons,
- function(monitor, o)
- local mx, my = table.unpack(sizes[o])
- local ln = #tostring(i)
- local wrt = string.rep(' ', mx - ln) .. tostring(i)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write(wrt)
- end
- )
- wait(1)
- end
- end
- local function open()
- writeMonitors(colors.red)
- print("Opening.")
- turnOn()
- parallel.waitForAny(
- function()
- wait(openTime)
- end,
- countDown
- )
- turnOff()
- writeMonitors(nil, nil, "DOORS")
- end
- local function main()
- turnOff()
- writeMonitors(nil, nil, "DOORS")
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("Press 'o' to open.")
- local ev, key = os.pullEvent()
- if ev == "key" and key == keys.o then
- open()
- elseif ev == "monitor_touch" then
- open()
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement