Advertisement
XDjackieXD

RFID Door Lock

Dec 7th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("StrUtils")
  2.  
  3.     function inFile(file, string)
  4.      
  5.       local f = fs.open(file,"r")
  6.       local line
  7.      
  8.       repeat
  9.         line = f.readLine()
  10.         if string==line then
  11.           f.close()
  12.           return true
  13.         end
  14.       until not line
  15.      
  16.       f.close()
  17.       return false
  18.      
  19.     end
  20.  
  21. readerSide = "back"
  22. writerSide = "left"
  23. redstoneSide = "top"
  24.  
  25. lastTimer = {}
  26.  
  27.     reader = peripheral.wrap(readerSide)
  28.     print("Door Contol is running")
  29.     while true do
  30.         reader.scan() --Creats an "rfid_detected" when a card is in range
  31.         event, p1, p2 = os.pullEvent()
  32.         if event == "rfid_detected" then
  33.             if inFile("//.keys", StrUtils.SHA1(p1)) and p2 < 3 then
  34.                 rs.setOutput(redstoneSide, true)
  35.                 lastTimer = os.startTimer(0.5)
  36.             end
  37.         elseif event == "timer" and lastTimer == p1 then
  38.             rs.setOutput(redstoneSide, false)
  39.         end
  40.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement