Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- local rs = redstone
- local pin = "1132"
- local display = {
- "1", "2", "3",
- "4", "5", "6",
- "7", "8", "9"
- }
- -- function to display the numbers on the monitor
- local function displayPinpad()
- monitor.clear()
- local y = 3
- for i = 1, #display do
- monitor.setCursorPos(5, y)
- monitor.write(display[i])
- y = y + 2
- end
- end
- -- function to handle right-clicks on the numbers
- local function handleClick(x, y)
- local index = (y - 1) / 2
- index = math.floor(index) + 1
- local enteredPin = enteredPin .. display[index]
- if enteredPin == pin then
- monitor.clear()
- monitor.setCursorPos(5, 4)
- monitor.write("Access Granted")
- openDoor()
- enteredPin = ""
- end
- end
- -- function to open the door for 3 seconds
- local function openDoor()
- rs.setOutput("left", true)
- sleep(3)
- rs.setOutput("left", false)
- end
- -- main program loop
- while true do
- displayPinpad()
- local button, x, y = os.pullEvent("mouse_click")
- if button == 1 or button == 2 then
- handleClick(x, y)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement