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"
- local user_code = ""
- local run = true
- while run do
- local e, address, _, key = event.pull(1000)
- if (e and e == "interrupted") then
- run = false
- elseif (e and e == "keypad") then
- if (key and key == "*") then
- user_code = ""
- keypad.setDisplay("")
- elseif (key) then
- user_code = user_code .. key
- keypad.setDisplay(user_code)
- end
- if (string.len(code) == string.len(user_code)) then
- if (code == user_code) then
- 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
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement