Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require("component")
- local keypad = c.os_keypad
- local computer = require("computer")
- local event = require("event")
- local code = "12345678" -- Your code (Max 8 digits to fit on keypad display)
- local user_code = "" -- Variable that stores input
- local run = true
- while run do
- local e, address, _, key = event.pull(1000)
- if (e and e == "interrupted") then -- Kill program when ctrl + c is pressed
- run = false
- elseif (e and e == "keypad") then
- if (key and key == "*") then -- Uses star button as reset key
- user_code = ""
- keypad.setDisplay("")
- elseif (key) then -- On key other than reset key add it to user_code
- user_code = user_code .. key
- keypad.setDisplay(user_code) -- Update display to updated input string
- end
- if (string.len(code) == string.len(user_code)) then -- If code and user_code are the same length:
- if (code == user_code) then -- Test if they match
- computer.beep(2000)
- print("Code correct!")
- keypad.setDisplay("CORRECT")
- user_code = ""
- else
- computer.beep(100)
- print("Wrong code!")
- keypad.setDisplay("WRONG")
- user_code = ""
- end
- end
- elseif (e and e == "magData") then -- If mag card is detected, check if stored string matches code
- if (key == code) then
- keypad.setDisplay("CORRECT")
- computer.beep(2000)
- else
- keypad.setDisplay("DENIED")
- computer.beep(100)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement