Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ComputerCraft PIN Display
- -- Install: pastebin get ewAZEHGu /startup
- local mon = peripheral.wrap("top")
- local pass = "0000"
- local passlen = string.len(pass)
- local press = "";
- tblpad = {};
- for i=0,10 do
- tblpad[i] = {}
- for x=0,10 do
- tblpad[i][x] = "x"
- end
- end
- tblpad[2][2] = "1"
- tblpad[4][2] = "2"
- tblpad[6][2] = "3"
- tblpad[2][3] = "4"
- tblpad[4][3] = "5"
- tblpad[6][3] = "6"
- tblpad[2][4] = "7"
- tblpad[4][4] = "8"
- tblpad[6][4] = "9"
- tblpad[4][5] = "0"
- function drawpad()
- if term.isColor() then
- mon.setBackgroundColor(colors.green)
- end
- mon.setCursorPos(1,1)
- mon.write("x-----x")
- mon.setCursorPos(1,2)
- mon.write("|1 2 3|")
- mon.setCursorPos(1,3)
- mon.write("|4 5 6|")
- mon.setCursorPos(1,4)
- mon.write("|7 8 9|")
- mon.setCursorPos(1,5)
- mon.write("x--0--x")
- end
- function countdown(c)
- for i=1,c do
- if term.isColor() then
- mon.setBackgroundColor(colors.green)
- end
- mon.setCursorPos(1,1)
- mon.write(" ")
- mon.setCursorPos(1,2)
- mon.write(" ")
- mon.setCursorPos(1,3)
- mon.write(" [".. c .."] ")
- mon.setCursorPos(1,4)
- mon.write(" ")
- mon.setCursorPos(1,5)
- mon.write(" ")
- sleep(1)
- c = c-1
- end
- end
- function dots()
- if term.isColor() then
- mon.setBackgroundColor(colors.red)
- end
- mon.setCursorPos(1,1)
- mon.write(" ")
- mon.setCursorPos(1,2)
- mon.write(" ")
- mon.setCursorPos(1,3)
- mon.write(" ... ")
- mon.setCursorPos(1,4)
- mon.write(" ")
- mon.setCursorPos(1,5)
- mon.write(" ")
- end
- function opendoor()
- dots()
- redstone.setOutput("top", true)
- redstone.setOutput("left", true)
- redstone.setOutput("right", true)
- redstone.setOutput("bottom", true)
- redstone.setOutput("front", true)
- redstone.setOutput("back", true)
- countdown(5)
- redstone.setOutput("top", false)
- redstone.setOutput("left", false)
- redstone.setOutput("right", false)
- redstone.setOutput("bottom", false)
- redstone.setOutput("front", false)
- redstone.setOutput("back", false)
- dots()
- drawpad()
- end
- function wrongpass()
- if term.isColor() then
- mon.setBackgroundColor(colors.red)
- end
- mon.setCursorPos(1,1)
- mon.write(" ")
- mon.setCursorPos(1,2)
- mon.write("INVALID")
- mon.setCursorPos(1,3)
- mon.write("PINCODE")
- mon.setCursorPos(1,4)
- mon.write("ENTERED")
- mon.setCursorPos(1,5)
- mon.write(" ")
- sleep(4)
- drawpad()
- end
- drawpad()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if tblpad[xPos][yPos] ~= "x" then
- mon.setCursorPos(xPos, yPos)
- if term.isColor() then
- mon.setBackgroundColor(colors.gray)
- end
- mon.write(tblpad[xPos][yPos])
- sleep(0.2)
- mon.setCursorPos(xPos, yPos)
- if term.isColor() then
- mon.setBackgroundColor(colors.gray)
- end mon.write(tblpad[xPos][yPos])
- press = press .. tblpad[xPos][yPos]
- if string.len(press) == passlen and press == pass then
- press = ""
- opendoor()
- elseif string.len(press) == passlen and press ~= pass then
- press = ""
- wrongpass()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement