Advertisement
XDjackieXD

DoorLock

Dec 7th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1.    
  2. --a simple door lock with immibis peripherals mag-card
  3.  
  4.     os.loadAPI("StrUtils")
  5.      
  6.     function inFile(file, string)
  7.      
  8.       local f = fs.open(file,"r")
  9.       local line
  10.      
  11.       repeat
  12.         line = f.readLine()
  13.         if string==line then
  14.           f.close()
  15.           return true
  16.         end
  17.       until not line
  18.      
  19.       f.close()
  20.       return false
  21.      
  22.     end
  23.      
  24.     monitor = peripheral.wrap("monitor_0")
  25.     mag = peripheral.wrap("mag card reader_0")
  26.      
  27.      
  28.     monitor.setTextScale(1.5)
  29.      
  30.     while true do
  31.      
  32.       monitor.setBackgroundColor(colors.black)
  33.       monitor.setTextColor(colors.blue)
  34.       monitor.clear()
  35.       monitor.setCursorPos(1,1)
  36.       monitor.write("Swipe")
  37.       monitor.setCursorPos(1,2)
  38.       monitor.write("Card!")
  39.       monitor.setCursorPos(3,4)
  40.       monitor.setBackgroundColor(colors.blue)
  41.       monitor.write(" ")
  42.       monitor.setCursorPos(2,5)
  43.       monitor.write(" ")
  44.       monitor.setCursorPos(1,6)
  45.       monitor.write(" ")
  46.       monitor.setCursorPos(2,7)
  47.       monitor.write(" ")
  48.       monitor.setCursorPos(3,8)
  49.       monitor.write(" ")
  50.      
  51.       local event,arg1,arg2,arg3 = os.pullEvent("mag_swipe")
  52.          
  53.       if inFile("//.keys", StrUtils.SHA1(arg1)) then
  54.         monitor.setBackgroundColor(colors.green)
  55.         monitor.clear()
  56.         rs.setOutput("top",true)
  57.         os.sleep(1.5)
  58.         rs.setOutput("top",false)
  59.       else
  60.         monitor.setBackgroundColor(colors.red)
  61.         monitor.clear()
  62.         os.sleep(5)
  63.       end
  64.      
  65.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement