Advertisement
Birog

rfid_writer

Mar 16th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. isRunning = true
  2. state ={"Waitint for Card", "CardReceived", "Wait", "Writing Card", "Card Complete"}
  3. curState=1
  4. function toPercent(num)
  5.  num = num*100
  6.  return math.floor(num+.5).."%"
  7. end
  8. writer = peripheral.wrap("right")
  9.  
  10. while isRunning do
  11.  if not writer.isPresent() then
  12.   curState = 1
  13.  else -- card ist present
  14.   curState = 2
  15.   if writer.getProgress() >0 then
  16.    curState = 4
  17.   elseif writer.isCoded() then
  18.    curState = 5
  19.   end
  20.  end
  21.  
  22.  if curState == 2 then
  23.   print("Card Ready. Enter data to write to card")
  24.   data = read()
  25.   print("Enter label ")
  26.   label = read()
  27.  
  28.   curState = 3
  29.  
  30.   sleep(2)
  31.   writer.encode(data, label)
  32.  end
  33.  
  34.  term.clear()
  35.  term.setCursorPos(1,1)
  36.  print(state[curState])
  37.  if curState == 4 then
  38.   print(toPercent(writer.getProgress()))
  39.  end
  40.  sleep(2)
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement