Advertisement
Guest User

Untitled

a guest
May 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. --If you want this to start at every boot of a computer run the following line of code in the startup
  2. -- shell.run("RFID","door")
  3.  
  4.  
  5. --The door stays open as long as you stay in the area of the reader
  6. -- !!! Make sure there is no creeper behind you !!!
  7.  
  8. -- Set up your own door system
  9. doorPass = "wsxedcrfvbgtnhzmjuzvrnzcif" --Max Length 82 chars
  10. cardLabel = "Ident: Front Door" --Max Length 20 chars
  11. --Make sure the following sides are equal to your build
  12. readerSide = "left"
  13. writerSide = "right"
  14. redstoneSide = "bottom"
  15.  
  16. --Variables (Don´t change)
  17. tArgs = {...}
  18. lastTimer = {}
  19.  
  20. -- Check the arguments given
  21. if #tArgs < 1 then
  22. print("Usage:")
  23. print("RFID write")
  24. print("RFID door")
  25. return
  26. end
  27.  
  28. mode = tArgs[1]
  29. shell.run("clear")
  30.  
  31. if mode == "write" then
  32. writer = peripheral.wrap(writerSide)
  33. print("Enter writing mode")
  34. print("Insert card in the writer")
  35. while not writer.isPresent() do --Waits until a card is in the writer
  36. sleep(0)
  37. end
  38.  
  39. if writer.encode(doorPass, cardLabel) then --Start write to card
  40. print("Start writing Pass to card")
  41. else --Error handling
  42. if writer.isCoded() then
  43. print("Card is already coded\nInsert a blank card")
  44. elseif #cardLabel > 20 then
  45. print("Card Label is too long max. 20 char")
  46. elseif #doorPass > 82 then
  47. print("Data is too long max. 82 char")
  48. else
  49. print("Leave the card in the writer")
  50. end
  51. return
  52. end
  53. os.pullEvent("rfid_written") --Wait until the card is written
  54. print("RFID card is coded")
  55. print("Take the card out of the writer")
  56.  
  57. while writer.isCoded() do --Ends the program when the card is taken out of the writer
  58. sleep(0)
  59. end
  60. shell.run("clear")
  61.  
  62. ------------------------------------------------------
  63. ------------------------------------------------------
  64. elseif mode == "door" then
  65. reader = peripheral.wrap(readerSide)
  66. print("Door Contol is running")
  67. while true do
  68. reader.scan() --Creats an "rfid_detected" when a card is in range
  69. event, p1 = os.pullEvent()
  70. if event == "rfid_detected" then
  71. if p1 == doorPass then
  72. rs.setOutput(redstoneSide, true)
  73. lastTimer = os.startTimer(1)
  74. end
  75. elseif event == "timer" and lastTimer == p1 then
  76. rs.setOutput(redstoneSide, false)
  77. end
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement