Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local accessCode = "1111"
- local isOpened = false
- local component = require("component")
- local gpu = component.gpu
- local event = require("event")
- local ser = require("serialization")
- local computer = component.computer
- local door = component.os_door
- keypad = component.os_keypad
- customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "<-", "0", "OK"}
- customButtonColor = {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}
- keypad.setKey(customButtons, customButtonColor)
- if door.isOpen()
- then
- door.toggle()
- end
- local inputStr = ""
- while true do
- ev, address, button, button_label = event.pull("keypad")
- if ev then
- if (button_label == "OK")
- then
- if inputStr == accessCode
- then
- inputStr = "OK!"
- keypad.setDisplay(inputStr)
- computer.beep()
- door.toggle()
- isOpened = true
- else
- inputStr = "Invalid!"
- keypad.setDisplay(inputStr)
- os.sleep(2)
- end
- inputStr = ""
- elseif (button_label == "<-")
- then
- if (isOpened == false)
- then
- if string.len(inputStr) > 0
- then
- tmpStr = string.sub(inputStr, 1 , string.len(inputStr) -1)
- inputStr = tmpStr
- end
- else
- door.toggle()
- isOpened = false
- keypad.setDisplay("Locked!")
- inputStr = ""
- os.sleep(2)
- keypad.setDisplay(inputStr)
- end
- else
- inputStr = inputStr .. button_label
- end
- a = inputStr.len(inputStr)
- b = ""
- for i = a,1,-1
- do
- b = b .. "*"
- end
- keypad.setDisplay(b)
- end
- os.sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement