Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- local event = require("event")
- local term = require("term")
- local thread = require("thread")
- local rs = component.redstone
- local gpu = component.gpu
- -- Config
- local delay, isOpen = 5, (rs.getOutput(sides.right) > 0) and true or false
- local timer = nil
- term.clear()
- term.setCursor(1, 1)
- gpu.setForeground(0x00FF00)
- print("--------------------------- ToNELvision MICROSYTEMS ---------------------------\n")
- gpu.setForeground(0xFFFFFF)
- print("Welcome. Please enter one of the displayed commands. It may take a few seconds for the command to be interpreted.\n")
- gpu.setForeground(0xE6AB38)
- print("Open\nClose")
- term.setCursor(1, 9)
- local inputThread
- inputThread = thread.create(function()
- while true do
- local input = term.read(nil, false)
- if type(input) == "string" then
- input = input:sub(1, -2)
- elseif type(input) == "boolean" and input == false then
- print("interrupted")
- inputThread:kill()
- end
- term.clearLine()
- if input == "open" or input == "Open" then
- if not isOpen then
- rs.setOutput(sides.right, 15)
- isOpen = true
- if timer then event.cancel(timer) end
- timer = event.timer(delay, function()
- if isOpen then
- rs.setOutput(sides.right, 0)
- isOpen = false
- timer = nil
- end
- end)
- end
- elseif input == "close" or input == "Close" then
- if isOpen then
- rs.setOutput(sides.right, 0)
- event.cancel(timer)
- isOpen = false
- end
- elseif input == "quit" or input == "Quit" then
- inputThread:kill()
- end
- end
- end)
- local motionThread = thread.create(function()
- while true do
- local _, _, x, y, name = event.pull("motion")
- if not isOpen then
- rs.setOutput(sides.right, 15)
- isOpen = true
- if timer then event.cancel(timer) end
- timer = event.timer(delay, function()
- if isOpen then
- rs.setOutput(sides.right, 0)
- isOpen = false
- timer = nil
- end
- end)
- else
- event.cancel(timer)
- timer = event.timer(delay, function()
- if isOpen then
- rs.setOutput(sides.right, 0)
- isOpen = false
- timer = nil
- end
- end)
- end
- end
- end)
- thread.waitForAny({inputThread, motionThread})
- print("\nProgram Exit")
- os.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement