Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ocal wSide = "right" -- the side the RFID Writer is on
- local writer = peripheral.wrap(wSide) -- wraps the RFID Writer to the writer variable
- local cReady = false -- stores if an RFID card is present and not previously encoded
- local info = {"Username: ", "Password: "} -- an array that stores prompts for the user
- local str = "" -- variable used as a placeholder for formatting functions
- local data = "" -- will store all of the data for the card
- local label = "" -- will store the card label
- function sData(str) -- formats a string with [] use substring search to get data between
- return "[" .. str .. "]"
- end
- function sProgress(str) -- formats the progress 'bar'
- local temp2 = math.floor(str * 100)
- return "[" .. temp2 .. "%]"
- end
- function wProgress(str) -- displays the write progress 'bar'
- print("Write in progress: " .. sProgress(str))
- end
- function checkCard() -- checks that the card is writtable
- if writer.isPresent()== true then
- if writer.isCoded() == false then
- cReady = true
- end
- else
- cReady = false
- end
- end
- function getData() -- gets the information needed for the card
- for i,v in ipairs(info) do -- this loop will gather the basic information by prompting the user
- term.clear()
- term.setCursorPos(1,1)
- write(info[i])
- local temp = read()
- data = data .. sData(temp) -- appends the data together until we have a single line; you could append \n if line breaks were necessary
- end
- term.clear()
- term.setCursorPos(1,1)
- write("Card Label: ")
- label = read() -- stores the
- end
- function writeData() -- writes the data to the card
- checkCard()
- if cReady == true then
- getData()
- writer.encode(data, label) -- this is the part where the card actually gets written
- while writer.getProgress() > -1 do -- displays the write progress
- term.clear()
- term.setCursorPos(1,1)
- wProgress(writer.getProgress())
- sleep(3)
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Process complete.")
- else
- print("No card inserted, or invalid card.")
- end
- end
- writeData() -- showtime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement