Guest User

rfid-magcard reader (cc)

a guest
May 6th, 2013
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --made for computercraft with immibis periherals mod
  2. --(minecraft)
  3. --made by dragonmaster90
  4. --"rfid and magcard reader/writer"
  5.  
  6. function clear()
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. end
  10.  
  11. s = peripheral.wrap("back") --speaker
  12. w = peripheral.wrap("top")  --rfid writer
  13. r = peripheral.wrap("right")--rfid reader
  14. m = peripheral.wrap("left") --magcard
  15.  
  16. function sdb(db)
  17. s.setAttenuation(db)
  18. end
  19.  
  20. while true do
  21. print("chose option 1,2,3,4 or 5 \n[1] write a RFID card\n[2] read all RFID cards in range\n[3] write code on a magcard\n[4] read the code of a magcard\n[5] exit")
  22. num=tonumber(read())
  23. if num == 1 then
  24.    if w.isPresent() == true then
  25.       print("enter a code for your RFID card")
  26.       c=read()
  27.       print("now enter a label")
  28.       l=read()
  29.       print("encoding...")
  30.       w.encode(tostring(c),tostring(l))
  31.       sdb(10)
  32.       s.start(2,200)
  33.       os.pullEvent("rfid_written")
  34.       print("done!\nplease take out your card")
  35.       s.stop(2)
  36.       sdb(0)
  37.       s.start(1,400)
  38.       sleep(1)
  39.       s.stop(1)
  40.       clear()
  41.     else
  42.       print("no RFID card inserted")
  43.       s.start(1,200)
  44.       sleep(0.5)
  45.       s.stop(1)
  46.       sleep(1)
  47.       clear()
  48.     end
  49. elseif num == 2 then
  50.   print("scanning")
  51.   r.scan(5)
  52.   z,x = os.pullEvent("rfid_detected")
  53.   print("scanned a RFID card with the code "..x.." on it")
  54.   sleep(3)
  55.   clear()    
  56. elseif num == 3 then
  57.   print("enter a code for your magcard")
  58.   la=tostring(read())
  59.   print("now enter a label")
  60.   oa=tostring(read())
  61.   print("now swipe your magcard on the reader (left)")
  62.   m.setInsertCardLight(true)
  63.   m.beginWrite(la,oa)
  64.   os.pullEvent("mag_write_done")
  65.   print("done!")
  66.   m.setInsertCardLight(false)
  67.   sdb(0)
  68.   s.start(1,400)
  69.   sleep(1)
  70.   s.stop(1)
  71.   clear()
  72. elseif num == 4 then
  73.   print("scanning...")
  74.   za,xa = os.pullEvent("mag_swipe")
  75.   print("scanned a magcard with "..xa.." on it")
  76.   s.start(1,400)
  77.   sleep(0.5)
  78.   s.stop(1)
  79.   sleep(3)
  80.   clear()
  81. elseif num == 5 then clear() break end
  82. end
  83.  
  84. print("bye bye!")
  85. sleep(1)
  86. clear()
Advertisement
Add Comment
Please, Sign In to add comment