Advertisement
Guest User

rfid

a guest
Oct 20th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. --RFID Door with automagic card creation
  2.  
  3. --configuration
  4. writer = peripheral.wrap("rfid writer_1");
  5. reader = peripheral.wrap("rfid reader_1");
  6. redside = "bottom";
  7.  
  8. label = "GateKey";
  9. data = "this is the gate key";
  10. range = 15;
  11.  
  12. print("Simple in-secure RFID door!");
  13. print("Key name: " .. label);
  14. print("Scanning Range " .. range);
  15.  
  16. function main()
  17. while true do
  18.   --If there is a card in the writer
  19.   -- and it is blank
  20.   -- and we are not currently writing
  21.   if writer.isPresent() and (not writer.isCoded()) and (writer.getProgress() == -1) then
  22.     --make a key
  23.     writer.encode(data,label);    
  24.   end
  25.   redstone.setOutput(redside,readerloop());
  26.   os.sleep(.5); --let the redstone settle
  27.   os.queueEvent("marker_event"); --clear the event stack
  28.   repeat
  29.     e = os.pullEvent();
  30.   until e == "marker_event";
  31. end
  32. end
  33.  
  34. function readerloop()
  35.   reader.scan(range);
  36.   while true do --we will break from this one
  37.     e,p1,p2,p3,p4,p5 = os.pullEvent()
  38.     if e == "rfid_detected" and p1 == data then
  39.       return true;
  40.     elseif e == "rfid_scan_done" then
  41.       return false;
  42.     end
  43.   end
  44. end
  45.  
  46. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement