Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --If you want this to start at every boot of a computer run the following line of code in the startup
- -- shell.run("RFID","door")
- --The door stays open as long as you stay in the area of the reader
- -- !!! Make sure there is no creeper behind you !!!
- -- Set up your own door system
- doorPass = "wsxedcrfvbgtnhzmjuzvrnzcif" --Max Length 82 chars
- cardLabel = "Ident: Front Door" --Max Length 20 chars
- --Make sure the following sides are equal to your build
- readerSide = "left"
- writerSide = "right"
- redstoneSide = "bottom"
- --Variables (Don“t change)
- tArgs = {...}
- lastTimer = {}
- -- Check the arguments given
- if #tArgs < 1 then
- print("Usage:")
- print("RFID write")
- print("RFID door")
- return
- end
- mode = tArgs[1]
- shell.run("clear")
- if mode == "write" then
- writer = peripheral.wrap(writerSide)
- print("Enter writing mode")
- print("Insert card in the writer")
- while not writer.isPresent() do --Waits until a card is in the writer
- sleep(0)
- end
- if writer.encode(doorPass, cardLabel) then --Start write to card
- print("Start writing Pass to card")
- else --Error handling
- if writer.isCoded() then
- print("Card is already coded\nInsert a blank card")
- elseif #cardLabel > 20 then
- print("Card Label is too long max. 20 char")
- elseif #doorPass > 82 then
- print("Data is too long max. 82 char")
- else
- print("Leave the card in the writer")
- end
- return
- end
- os.pullEvent("rfid_written") --Wait until the card is written
- print("RFID card is coded")
- print("Take the card out of the writer")
- while writer.isCoded() do --Ends the program when the card is taken out of the writer
- sleep(0)
- end
- shell.run("clear")
- ------------------------------------------------------
- ------------------------------------------------------
- elseif mode == "door" then
- reader = peripheral.wrap(readerSide)
- print("Door Contol is running")
- while true do
- reader.scan() --Creats an "rfid_detected" when a card is in range
- event, p1 = os.pullEvent()
- if event == "rfid_detected" then
- if p1 == doorPass then
- rs.setOutput(redstoneSide, true)
- lastTimer = os.startTimer(1)
- end
- elseif event == "timer" and lastTimer == p1 then
- rs.setOutput(redstoneSide, false)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement