Advertisement
Maksandra

Untitled

Jan 23rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local accessCode = "147"
  2.  
  3. local component = require("component")
  4. local sides = require("sides")
  5. local gpu = component.gpu
  6. local event = require("event")
  7. local ser = require("serialization")
  8. local term = require("term")
  9. local computer = component.computer
  10. local rs = component.redstone
  11. keypad = component.os_keypad
  12. alarm = component.os_alarm
  13.  
  14. customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "<-", "0", "OK"}
  15. customButtonColor = {"1", "1", "1", "1", "1", "1", "1", "1", "1", "2", "1", "3"}
  16. keypad.setKey(customButtons, customButtonColor)
  17.  
  18. term.clear()
  19. print("MaksandraSecurity v1.0 [KeyPad Edition]")
  20. print("Система запущена.")
  21. alarm.setRange(150)
  22. local inputStr = ""
  23. while true do
  24.   ev, address, button, button_label = event.pull("keypad")
  25.   if ev then
  26.     if button_label == "OK" then
  27.       if inputStr == accessCode then
  28.     term.write("Доступ разрешен!\n")
  29.     inputStr = "OK!"
  30.     keypad.setDisplay(inputStr)
  31.     computer.beep()
  32.     rs.setOutput(sides.down, 15)
  33.     os.sleep(3)
  34.     rs.setOutput(sides.down, 0)
  35.       else
  36.     term.write("Доступ запрещен!\n")
  37.     inputStr = "Invalid!"
  38.     alarm.activate()
  39.     keypad.setDisplay(inputStr)
  40.     os.sleep(3)
  41.     alarm.deactivate()
  42.       end
  43.       inputStr = ""
  44.     elseif button_label == "<-" then
  45.       if string.len(inputStr) > 0 then
  46.     tmpStr = string.sub(inputStr, 1 , string.len(inputStr) -1)
  47.     inputStr = tmpStr
  48.       end
  49.     else
  50.       inputStr = inputStr .. button_label
  51.     end
  52.         a = inputStr.len(inputStr)
  53.         b = ""
  54.         for i = a,1,-1
  55.         do
  56.             b = b .. "*"
  57.         end
  58.         keypad.setDisplay(b)
  59.   end
  60.   os.sleep(0)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement