Advertisement
funnybunnyofdoom

BunnyDoor

Nov 12th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. --This program will include the APIs to
  2. --control doors using a touch screen
  3. --and to display the status of the keycard
  4.  
  5. --controlSide = "left"
  6. displaySide = "right"
  7.  
  8.  
  9.  
  10. --controlMonitor = peripheral.wrap(controlSide)
  11.  
  12. --cx,cy = controlMonitor.getSize()
  13.  
  14. --create the display monitor bg
  15. function displaybg()
  16.  
  17. displayMonitor = peripheral.wrap("right")
  18. dx,dy = displayMonitor.getSize()
  19. ebgcolor = colors.lightGray
  20. ebdcolor = colors.gray
  21. gbgcolor = colors.lime
  22. gbdcolor = colors.green
  23. rbgcolor = colors.pink
  24. rbdcolor = colors.red
  25. bgc = colors.black
  26. bdc = colors.gray
  27. txc = colors.white
  28. txt = " "
  29. mode = ""
  30.  
  31. if not disk.isPresent("bottom") then
  32. mode = "empty"
  33. elseif disk.isPresent("bottom") then
  34. mode = "good"
  35. end
  36. if mode == "good" then
  37. bgc = colors.lime
  38. bdc = colors.green
  39. txc = colors.black
  40. txt = "GOOD"
  41. elseif mode == "deny" then
  42. bgc = colors.pink
  43. bdc = colors.red
  44. txc = colors.black
  45. txt = "DENY"
  46. elseif mode == "empty" then
  47. bgc = colors.lightGray
  48. bdc = colors.gray
  49. txc = colors.white
  50. txt = "EMPTY"
  51. end
  52.  
  53.  
  54.  
  55. displayMonitor.setBackgroundColor(bdc)
  56. displayMonitor.clear()
  57. displayMonitor.setCursorPos(2,3)
  58. displayMonitor.setTextColor(txc)
  59. displayMonitor.write(txt)
  60. displayMonitor.setBackgroundColor(bgc)
  61. for i=0,dx,1 do
  62. displayMonitor.setCursorPos(i+1,1)
  63. displayMonitor.write(" ")
  64. end
  65. for i=0,dx,1 do
  66. displayMonitor.setCursorPos(i+1,dy)
  67. displayMonitor.write(" ")
  68. end
  69. for i=0,dy,1 do
  70. displayMonitor.setCursorPos(1,i+1)
  71. displayMonitor.write(" ")
  72. end
  73. for i=0,dy,1 do
  74. displayMonitor.setCursorPos(dx,i+1)
  75. displayMonitor.write(" ")
  76. end
  77.  
  78. displayMonitor.setBackgroundColor(colors.black)
  79. displayMonitor.setTextColor(colors.white)
  80.  
  81. if mode == "good" then
  82. doors.open()
  83. return false
  84. end
  85.  
  86. end
  87.  
  88. function displayInput(selection)
  89. local selection = selection or 15
  90.  
  91. displayMonitor = peripheral.wrap("left")
  92. displayMonitor.clear()
  93. displayMonitor.setCursorPos(1,1)
  94. displayMonitor.setBackgroundColor(colors.lime)
  95. displayMonitor.write(" + ")
  96. displayMonitor.setCursorPos(1,2)
  97. if selection == 50 then
  98. displayMonitor.setBackgroundColor(colors.lightGray)
  99. else
  100. displayMonitor.setBackgroundColor(colors.black)
  101. end
  102. displayMonitor.write(" Open ")
  103. displayMonitor.setCursorPos(1,12)
  104. displayMonitor.setBackgroundColor(colors.red)
  105. displayMonitor.write(" - ")
  106. displayMonitor.setBackgroundColor(colors.black)
  107. for i=0,8,1 do
  108. local mult = 10^(0)
  109. number = 45-(i*5)
  110.  
  111. if selection == number then
  112. displayMonitor.setBackgroundColor(colors.lightGray)
  113. else
  114. displayMonitor.setBackgroundColor(colors.black)
  115. end
  116. displayMonitor.setCursorPos(1,i+3)
  117. displayMonitor.write(" ")
  118. displayMonitor.write(number)
  119. displayMonitor.setCursorPos(6,i+3)
  120. if number == 5 then displayMonitor.setCursorPos(5,i+3) end
  121. displayMonitor.write(" ")
  122.  
  123. end
  124.  
  125. end
  126.  
  127. function timeSelector()
  128. Selection = 15
  129. while true do
  130. event,side,x,y = os.pullEvent()
  131. if event == "disk" then doorgui.displaybg()
  132. doorgui.displaybg()
  133. elseif event == "monitor_touch" then
  134. if y==1 and Selection <= 45 then
  135. Selection = Selection + 5
  136. elseif y==12 and Selection >= 10 then
  137. Selection = Selection - 5
  138. end
  139. displayInput(Selection)
  140. local file = fs.open("documents/timer.cfg",'w')
  141. file.write(Selection)
  142. file.close()
  143. end
  144.  
  145. end
  146. end
  147.  
  148.  
  149.  
  150.  
  151. -- This program will form the API for operating
  152. -- Doors in the laboratory
  153. -- Author: FunnyBunnyofDOOM
  154.  
  155. local timer = 15 --ticks to count
  156.  
  157. function open() --Emits a signal to close the door
  158. local file = fs.open("documents/timer.cfg",'r')
  159. timer = file.readLine()
  160. timer = tonumber(timer)
  161.  
  162. file.close()
  163. disk.eject("bottom") -- Handles disk drive?
  164. term.clear()
  165. term.setCursorPos(1,1)
  166. term.write("Elevator Open")
  167. redstone.setAnalogOutput("back",10)
  168. if timer ~= 50 then
  169. for i=0,timer,1 do
  170. term.setCursorPos(1,1)
  171. term.clear()
  172. print(timer - i)
  173. os.sleep(1)
  174. term.setCursorPos(1,1)
  175. end
  176. end
  177. term.clear()
  178. term.setCursorPos(1,1)
  179. term.write("Elevator Closed")
  180. if timer ~= 50 then
  181. redstone.setAnalogOutput("back",0)
  182. end
  183. term.setCursorPos(1,1)
  184. end
  185.  
  186.  
  187. function diskListen()
  188. while true do
  189. local event,side = os.pullEvent()
  190. if event == "monitor_touch" then
  191. doorgui.timeSelector()
  192. end
  193. end
  194. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement