Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- KeyPad v1.0
- by Fwacer
- May 29th, 2014
- ]]--
- function touch()
- local event, side
- event, side, xPos, yPos = os.pullEvent("monitor_touch") --Gets the coordinates of where the player touched the screen
- end
- function printKey()
- local mon = peripheral.wrap('top') --Change 'top' to wherever your monitor is located.
- mon.clear()
- mon.setTextColor(colors.white)
- mon.setCursorPos(1,1)
- mon.setTextScale(1.25)
- mon.write(" 1 2 3")
- mon.setCursorPos(1,2.5)
- mon.write(" 4 5 6")
- mon.setCursorPos(1,3.5)
- mon.write(" 7 8 9")
- mon.setCursorPos(4,4.5)
- mon.write("0")
- mon.setCursorPos(1,5)
- mon.setTextColor(colors.red)
- mon.setTextScale(1)
- mon.write("CLR ")
- mon.setCursorPos(4,5)
- mon.setTextColor(colors.purple)
- end
- function codeConvert()
- local x = xPos
- local y = yPos
- local xVar
- local num
- local isValid
- --Change the xPos into blocks 1,2,3
- if x==1 or x==2 then
- xVar = 1
- elseif x==3 or x==4 or x==5 then
- xVar = 2
- else
- xVar = 3
- end
- if y<4 then
- isValid = true
- elseif y==4 then
- if xVar==2 then
- isValid = true
- else
- isValid = false
- end
- elseif y==5 then --CLS button
- if x>4 then
- mon.clear()
- num = -1
- end
- end
- --Now to determine the numbers picked
- if isValid then
- if xVar==1 then
- if y==1 then
- num = 1
- elseif y==2 then
- num = 4
- elseif y==3 then
- num = 7
- end
- elseif xVar==2 then
- if y==1 then
- num = 2
- elseif y==2 then
- num = 5
- elseif y==3 then
- num = 8
- elseif y==4 then
- num = 0
- end
- elseif xVar==3 then
- if y==1 then
- num = 3
- elseif y==2 then
- num = 6
- elseif y==3 then
- num = 9
- end
- end
- end
- if num==null then
- print("num is null") --Failsafe
- return -1
- elseif num>-1 then
- write(num)
- end
- return num
- end
- local code = 1352 --Edit this to change the password
- local userCode = 0
- local count = 0
- local loop = true
- local num = 0
- mon = peripheral.wrap('top')
- printKey()
- while loop do
- if count<4 then
- touch()
- end
- num = codeConvert()
- if num==-1 then
- printKey()
- count = 0
- userCode = 0
- elseif count<4 then
- userCode = (userCode*10)+num
- count = count+1
- mon.write(tostring(num))
- else
- print(" ")
- print(userCode)
- if code==userCode then
- printKey()
- mon.setTextColor(colors.lime)
- mon.write(tostring(userCode))
- print("CORRECT")
- redstone.setOutput('bottom', true)
- sleep(10) --How long the redstone stays on
- printKey()
- redstone.setOutput('bottom', false)
- --To run another program if the code is correct,
- --do: shell.run("myProgram")
- --right here.
- term.clear()
- term.setCursorPos(1,1)
- userCode = 0
- count = 0
- else
- printKey()
- mon.setTextColor(colors.red)
- mon.write(tostring(userCode))
- userCode = 0
- count = 0
- print("DENIED")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- printKey()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement