Posted 08 September 2012 - 03:34 PM
This is a small programm to use with Immibis's Peripherals RFID reader
Run RFID write in your computer and you will be guided through the coding of the card
Run RFID door to activat the door lock
Make sure to set the sides of the reader, writer and redstone wire to the sides you use in your build
Program:
http://pastebin.com/Jnw5B9h1
Run RFID write in your computer and you will be guided through the coding of the card
Run RFID door to activat the door lock
Make sure to set the sides of the reader, writer and redstone wire to the sides you use in your build
Program:
Spoiler
--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"
--(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
http://pastebin.com/Jnw5B9h1