Stary2001

Untitled

Jan 25th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. local correctPin = "596711"
  2.  
  3. local monitorSide = "back"
  4.  
  5. local doorTime = 2
  6.  
  7. function display()
  8. local mon = peripheral.wrap(monitorSide)
  9.  
  10. mon.clear()
  11. mon.setTextScale(1)
  12. local xSize,ySize = mon.getSize()
  13.  
  14. mon.setCursorPos(1,1)
  15. mon.write(("-"):rep( xSize ))
  16.  
  17. local hSpace = (" "):rep( (xSize / 3) - 1 )
  18. local row3="|7"..hSpace.."8"..hSpace.."9|"
  19. local row2="|4"..hSpace.."5"..hSpace.."6|"
  20. local row1="|1"..hSpace.."2"..hSpace.."3|"
  21.  
  22. mon.setCursorPos(1,2)
  23. mon.write(row1)
  24.  
  25. mon.setCursorPos(1,3)
  26. mon.write(row2)
  27.  
  28. mon.setCursorPos(1,4)
  29. mon.write(row3)
  30.  
  31. mon.setCursorPos(1,5)
  32. mon.write(("-"):rep( xSize ))
  33. end
  34.  
  35. function detect()
  36. local buttons =
  37. {
  38. [7]={2,4},
  39. [8]={4,4},
  40. [9]={6,4},
  41.  
  42. [4]={2,3},
  43. [5]={4,3},
  44. [6]={6,3},
  45.  
  46. [1]={2,2},
  47. [2]={4,2},
  48. [3]={6,2}
  49. }
  50. local pin = ""
  51.  
  52. while true do
  53. local button
  54.  
  55. local _,__,x,y = os.pullEvent("monitor_touch")
  56.  
  57. for i,v in ipairs(buttons) do
  58. if ( x==v[1] or x==v[1]-1 ) and y==v[2] then
  59. button = i
  60. break
  61. end
  62. end
  63.  
  64. if button then
  65. pin = pin .. button
  66. local mon = peripheral.wrap(monitorSide)
  67. mon.setCursorPos(#pin+1,1)
  68. mon.write("#")
  69. end
  70. if #pin == #correctPin then break end
  71. end
  72.  
  73. local mon = peripheral.wrap(monitorSide)
  74.  
  75. if pin == correctPin then
  76. mon.setBackgroundColor(colors.green)
  77. mon.clear()
  78. rs.setOutput("top",true)
  79. os.sleep(doorTime)
  80. rs.setOutput("top",false)
  81. mon.setBackgroundColor(colors.black)
  82. mon.clear()
  83.  
  84. else
  85. mon.setBackgroundColor(colors.red)
  86. mon.clear()
  87. os.sleep(0.5)
  88. mon.setBackgroundColor(colors.black)
  89. mon.clear()
  90. end
  91. end
  92.  
  93. while true do
  94. display()
  95. detect()
  96. end
Advertisement
Add Comment
Please, Sign In to add comment