Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. ocal wSide = "right" -- the side the RFID Writer is on
  2. local writer = peripheral.wrap(wSide) -- wraps the RFID Writer to the writer variable
  3. local cReady = false -- stores if an RFID card is present and not previously encoded
  4. local info = {"Username: ", "Password: "} -- an array that stores prompts for the user
  5. local str = "" -- variable used as a placeholder for formatting functions
  6. local data = "" -- will store all of the data for the card
  7. local label = "" -- will store the card label
  8.  
  9. function sData(str) -- formats a string with [] use substring search to get data between
  10. return "[" .. str .. "]"
  11. end
  12.  
  13. function sProgress(str) -- formats the progress 'bar'
  14. local temp2 = math.floor(str * 100)
  15. return "[" .. temp2 .. "%]"
  16. end
  17.  
  18. function wProgress(str) -- displays the write progress 'bar'
  19. print("Write in progress: " .. sProgress(str))
  20. end
  21.  
  22. function checkCard() -- checks that the card is writtable
  23. if writer.isPresent()== true then
  24. if writer.isCoded() == false then
  25. cReady = true
  26. end
  27. else
  28. cReady = false
  29. end
  30. end
  31.  
  32. function getData() -- gets the information needed for the card
  33. for i,v in ipairs(info) do -- this loop will gather the basic information by prompting the user
  34. term.clear()
  35. term.setCursorPos(1,1)
  36. write(info[i])
  37. local temp = read()
  38. data = data .. sData(temp) -- appends the data together until we have a single line; you could append \n if line breaks were necessary
  39. end
  40. term.clear()
  41. term.setCursorPos(1,1)
  42. write("Card Label: ")
  43. label = read() -- stores the
  44. end
  45.  
  46. function writeData() -- writes the data to the card
  47. checkCard()
  48. if cReady == true then
  49. getData()
  50. writer.encode(data, label) -- this is the part where the card actually gets written
  51. while writer.getProgress() > -1 do -- displays the write progress
  52. term.clear()
  53. term.setCursorPos(1,1)
  54. wProgress(writer.getProgress())
  55. sleep(3)
  56. end
  57. term.clear()
  58. term.setCursorPos(1,1)
  59. print("Process complete.")
  60. else
  61. print("No card inserted, or invalid card.")
  62. end
  63. end
  64.  
  65. writeData() -- showtime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement