Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. local accessCode = "0312"
  2.  
  3. local component = require("component")
  4. local gpu = component.gpu
  5. local event = require("event")
  6. local ser = require("serialization")
  7. local term = require("term")
  8. local computer = component.computer
  9. local doorcontroller = component.os_doorcontroller
  10. keypad = component.os_keypad
  11.  
  12. customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "<", "0", "ok"}
  13. customButtonColor = {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}
  14. keypad.setKey(customButtons, customButtonColor)
  15.  
  16. term.clear()
  17. print("Security door")
  18. print("---------------------------------------------------------------------------")
  19.  
  20. local inputStr = ""
  21. while true do
  22. ev, address, button, button_label = event.pull("keypad")
  23. if ev then
  24. if button_label == "ok" then
  25. if inputStr == accessCode then
  26. term.write("Access granted\n")
  27. inputStr = "wellcome"
  28. keypad.setDisplay(inputStr)
  29. computer.beep()
  30. doorcontroller.toggle()
  31. os.sleep(2)
  32. doorcontroller.toggle()
  33. else
  34. term.write("Access denied\n")
  35. inputStr = "ERROR"
  36. keypad.setDisplay(inputStr)
  37. os.sleep(2)
  38. end
  39. inputStr = ""
  40. elseif button_label == "<" then
  41. if string.len(inputStr) > 0 then
  42. tmpStr = string.sub(inputStr, 1 , string.len(inputStr) -1)
  43. inputStr = tmpStr
  44. end
  45. else
  46. inputStr = inputStr .. button_label
  47. end
  48. keypad.setDisplay(inputStr)
  49. end
  50. os.sleep(0)
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement