Advertisement
PrinceOfCookies

Untitled

Feb 12th, 2023 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local rs = redstone
  3.  
  4. local pin = "1132"
  5. local display = {
  6. "1", "2", "3",
  7. "4", "5", "6",
  8. "7", "8", "9"
  9. }
  10.  
  11. -- function to display the numbers on the monitor
  12. local function displayPinpad()
  13. monitor.clear()
  14. local y = 3
  15. for i = 1, #display do
  16. monitor.setCursorPos(5, y)
  17. monitor.write(display[i])
  18. y = y + 2
  19. end
  20. end
  21.  
  22. -- function to handle right-clicks on the numbers
  23. local function handleClick(x, y)
  24. local index = (y - 1) / 2
  25. index = math.floor(index) + 1
  26. local enteredPin = enteredPin .. display[index]
  27. if enteredPin == pin then
  28. monitor.clear()
  29. monitor.setCursorPos(5, 4)
  30. monitor.write("Access Granted")
  31. openDoor()
  32. enteredPin = ""
  33. end
  34. end
  35.  
  36.  
  37. -- function to open the door for 3 seconds
  38. local function openDoor()
  39. rs.setOutput("left", true)
  40. sleep(3)
  41. rs.setOutput("left", false)
  42. end
  43.  
  44. -- main program loop
  45. while true do
  46. displayPinpad()
  47. local button, x, y = os.pullEvent("mouse_click")
  48.  
  49. if button == 1 or button == 2 then
  50. handleClick(x, y)
  51. end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement