Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitors = {
- peripheral.wrap("top");
- }
- local outputSide = "right";
- local reLockTime = 20;
- local locked = true;
- local onColor = colors.green;
- local offColor = colors.red;
- local defaultColor = colors.white;
- --clears all monitors
- function clear()
- for i=1, #monitors do
- monitors[i].clear()
- monitors[i].setTextColor(defaultColor)
- monitors[i].setCursorPos(1,1)
- end
- end
- --goes to the next line for all monitors
- function nextLine()
- for i=1, #monitors do
- local x,y = monitors[i].getCursorPos()
- local y = y + 1
- monitors[i].setCursorPos(1,y)
- end
- end
- --writes text on all monitors
- function writeText(text)
- for i=1, #monitors do
- monitors[i].write(text)
- end
- end
- --sets text color for all monitors
- function textColor(color)
- for i=1, #monitors do
- monitors[i].setTextColor(color)
- end
- end
- --sets background color for all monitors
- function backgroundColor(color)
- for i=1, #monitors do
- monitors[i].setBackgroundColor(color)
- end
- end
- --sets textScale for all monitors
- function textScale(scale)
- for i=1, #monitors do
- monitors[i].setTextScale(scale)
- end
- end
- function routine()
- clear()
- textScale(0.5)
- activeColor = defaultColor
- if(locked) then
- writeText(" Access denied ")
- nextLine()
- nextLine()
- activeColor = offColor
- redstone.setOutput(outputSide,false)
- else
- writeText(" Access granted")
- nextLine()
- nextLine()
- activeColor = onColor
- redstone.setOutput(outputSide,true)
- end
- writeText("+-------------+")
- nextLine()
- for i=1, 6,1 do
- writeText("|")
- backgroundColor(activeColor)
- writeText(" ")
- backgroundColor(colors.black)
- writeText("|")
- nextLine()
- end
- writeText("+-------------+")
- end
- local lockTime = 0;
- while true do
- local timer = os.startTimer(1)
- local event,a1,a2,a3 = os.pullEvent()
- if event == "timer" then
- routine()
- if(lockTime == 0 and not locked) then
- locked = true;
- elseif(lockTime > 0 and not locked) then
- lockTime = lockTime -1
- elseif(lockTime > 0 and locked) then
- lockTime = 0
- end
- elseif event == "monitor_touch" then
- routine()
- local x = a2;
- local y = a3;
- if(x > 2 and x < 14) then
- if(y > 4 and y < 9) then
- locked = not locked
- lockTime = reLockTime
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement