Guest User

keypad

a guest
Sep 13th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. function check()
  2.   entry = tonumber(codeTbl[1]..codeTbl[2]..codeTbl[3]..codeTbl[4])
  3.   if entry == code then mon.setCursorPos(1,10) print("ACCESS GRANTED")  --do something here with redstone
  4.     else mon.setCursorPos(1,10) print("ACCESS DENIED")
  5.   end
  6. _1st = false
  7. _2nd = false
  8. _3rd = false
  9. _4th = false
  10. codeTbl = {}  
  11. end
  12.  
  13. function _123or4() --is it the 1st, 2nd, 3rd, or 4th number you pressed
  14.   if _1st == false then mon.setCursorPos(11,2) _1st = true
  15.     elseif _2nd == false then mon.setCursorPos(12,2) _2nd = true
  16.     elseif _3rd == false then mon.setCursorPos(13,2) _3rd = true
  17.     elseif _4th == false then mon.setCursorPos(14,2) _4th = true
  18.   end
  19. end
  20.  
  21. mon = peripheral.wrap("left")
  22. term.redirect(peripheral.wrap("left"))
  23. mon.setTextScale(.5)
  24. mon.setBackgroundColor(colors.black)
  25. mon.clear()
  26.  
  27. codeTbl = {}  --table the code is hopefully being stored within
  28.  
  29. _1st = false
  30. _2nd = false
  31. _3rd = false
  32. _4th = false
  33. code = 1234
  34.  
  35. --read txt file and print it to monitor
  36. hFile = fs.open("keypad.txt", "r")
  37. for i = 1, 9 do
  38.   print(hFile.readLine())        
  39. end
  40. hFile.close()
  41.  
  42. --it looks like this
  43. --/-\/-\/-\
  44. --|1||2||3|
  45. --\-/\-/\-/ ^^^^
  46. --/-\/-\/-\
  47. --|4||5||6|
  48. --\-/\-/\-/
  49. --/-\/-\/-\
  50. --|7||8||9|
  51. --\-/\-/\-/
  52.  
  53. w,h = mon.getSize()
  54.  
  55. repeat
  56.  
  57.   event,side,w,h = os.pullEvent("monitor_touch")
  58.  
  59.   if w == 1 or 2 or 3 and h == 1 or 2 or 3 then _123or4()
  60.     print("1")
  61.     elseif w == 4 or 5 or 6 and h == 1 or 2 or 3 then _123or4()
  62.       print("2")
  63.     elseif w == 7 or 8 or 9 and h == 1 or 2 or 3 then _123or4()
  64.       print("3")
  65.     elseif w == 1 or 2 or 3 and h == 4 or 5 or 6 then _123or4()
  66.       print("4")
  67.     elseif w == 4 or 5 or 6 and h == 4 or 5 or 6 then _123or4()
  68.       print("5")
  69.     elseif w == 7 or 8 or 9 and h == 4 or 5 or 6 then _123or4()
  70.       print("6")
  71.     elseif w == 1 or 2 or 3 and h == 7 or 8 or 9 then _123or4()
  72.       print("7")
  73.     elseif w == 4 or 5 or 6 and h == 7 or 8 or 9 then _123or4()
  74.       print("8")
  75.     elseif w == 7 or 8 or 9 and h == 7 or 8 or 9 then _123or4()
  76.       print("9")
  77.   end
  78. i = #codeTbl
  79. until i == 4
  80.   if #codeTbl == 4 then check()
  81.   end
Advertisement
Add Comment
Please, Sign In to add comment