Advertisement
opencomputerstest2

Keypad Code (For OpenSecurity)

Dec 28th, 2021 (edited)
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. keypad = require("component").os_keypad
  2. event = require("event")
  3.  
  4. local pin = "1234"
  5. local keypadInput = ""
  6.  
  7. function checkPin()
  8.     if keypadInput == pin then
  9.         keypad.setDisplay("Pass", 2)
  10.     else
  11.         keypad.setDisplay("Wrong", 4)
  12.     end    
  13.     keypadInput = ""
  14.     os.sleep(1) -- Enforce a small delay to keep text for a short time
  15. end
  16.  
  17. function keypadEvent(eventName, address, button, label)
  18.     if button == 10 then -- Is it del
  19.         keypadInput = string.sub(keypadInput, 1, -2) -- Del last char
  20.     elseif button == 12 then
  21.         checkPin()
  22.     else
  23.         keypadInput = keypadInput .. button_label
  24.     end
  25.     keypad.setDisplay(keypadInput, 7)
  26. end
  27. event.listen("keypad", keypadEvent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement