Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. doorPass = "kanker" --Max Length 82 chars
  2. cardLabel = "kanker" --Max Length 20 chars
  3.  
  4. readerSide = "right"
  5. writerSide = "left"
  6. redstoneSide = "back"
  7.  
  8. --(Don´t change)
  9. tArgs = {...}
  10. lastTimer = {}
  11.  
  12. -- Check the arguments given
  13. if #tArgs < 1 then
  14. print("Usage:")
  15. print("RFID write")
  16. print("RFID door")
  17. return
  18. end
  19.  
  20. mode = tArgs[1]
  21. shell.run("clear")
  22.  
  23. if mode == "write" then
  24. writer = peripheral.wrap(writerSide)
  25. print("Enter writing mode")
  26. print("Insert card in the writer")
  27. while not writer.isPresent() do --Waits until a card is in the writer
  28. sleep(0)
  29. end
  30.  
  31. if writer.encode(doorPass, cardLabel) then --Start write to card
  32. print("Start writing Pass to card")
  33. else --Error handling
  34. if writer.isCoded() then
  35. print("Card is already coded\nInsert a blank card")
  36. elseif #cardLabel > 20 then
  37. print("Card Label is too long max. 20 char")
  38. elseif #doorPass > 82 then
  39. print("Data is too long max. 82 char")
  40. else
  41. print("Leave the card in the writer")
  42. end
  43. return
  44. end
  45. os.pullEvent("rfid_written") --Wait until the card is written
  46. print("RFID card is coded")
  47. print("Take the card out of the writer")
  48.  
  49. while writer.isCoded() do --Ends the program when the card is taken out of the writer
  50. sleep(0)
  51. end
  52. shell.run("clear")
  53.  
  54. ------------------------------------------------------
  55. ------------------------------------------------------
  56. elseif mode == "door" then
  57. reader = peripheral.wrap(readerSide)
  58. print("Door Contol is running")
  59. while true do
  60. reader.scan() --Creats an "rfid_detected" when a card is in range
  61. event, p1 = os.pullEvent()
  62. if event == "rfid_detected" then
  63. if p1 == doorPass then
  64. rs.setOutput(redstoneSide, true)
  65. lastTimer = os.startTimer(1)
  66. end
  67. elseif event == "timer" and lastTimer == p1 then
  68. rs.setOutput(redstoneSide, false)
  69. end
  70. end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement