Guest User

keypad

a guest
Sep 14th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 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. mon.setCursorPos(1,1)
  38. for i = 1, 9 do
  39.   print(hFile.readLine())        
  40. end
  41. hFile.close()
  42.  
  43. --it looks like this
  44. --/-\/-\/-\
  45. --|1||2||3|
  46. --\-/\-/\-/ ^^^^
  47. --/-\/-\/-\
  48. --|4||5||6|
  49. --\-/\-/\-/
  50. --/-\/-\/-\
  51. --|7||8||9|
  52. --\-/\-/\-/
  53.  
  54. w,h = mon.getSize()
  55.  
  56. repeat
  57.  
  58.   event,side,w,h = os.pullEvent("monitor_touch")
  59.  
  60.   if w > 0 and w < 4 and h > 0 and h < 4 then _123or4()
  61.     print("1")
  62.     elseif w > 3 and w < 7 and h > 0 and h < 4 then _123or4()
  63.       print("2")
  64.     elseif w > 6 and w < 10 and h > 0 and h < 4 then _123or4()
  65.       print("3")
  66.     elseif w > 0 and w < 4 and h > 3 and h < 7 then _123or4()
  67.       print("4")
  68.     elseif w > 3 and w < 7 and h > 3 and h < 7 then _123or4()
  69.       print("5")
  70.     elseif w > 6 and w < 10 and h > 3 and h < 7 then _123or4()
  71.       print("6")
  72.     elseif w > 0 and w < 4 and h > 6 and h < 10 then _123or4()
  73.       print("7")
  74.     elseif w > 3 and w < 7 and h > 6 and h < 10 then _123or4()
  75.       print("8")
  76.     elseif w > 6 and w < 10 and h > 6 and h < 10 then _123or4()
  77.       print("9")
  78.   end
  79. i = #codeTbl
  80. until i == 4
  81.   if #codeTbl == 4 then check()
  82.   end
Advertisement
Add Comment
Please, Sign In to add comment