Jharakn

Reactor Controller

Dec 19th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. ---------------------------------
  2. -- Big Reactors Control System --
  3. -- Written by Jharakn --
  4. ---------------------------------
  5.  
  6. --Specific Variables------------------------------
  7. local reactorName = "BigReactors-Reactor_0"
  8. local screen1Name = "monitor_0"
  9. local screen2Name = "monitor_1"
  10. local maxTemp = 180
  11. local controlRodIndex = 0 --should be 0 I don't know if it changes
  12. --------------------------------------------------
  13.  
  14. --Global Variables--------------------------------
  15. local rodPosition = 0
  16. --------------------------------------------------
  17.  
  18. local reactor = peripheral.wrap(reactorName)
  19. local screen1 = peripheral.wrap(screen1Name)
  20. local screen2 = peripheral.wrap(screen2Name)
  21.  
  22. screen2.clear()
  23.  
  24. displayTemp = coroutine.create(function()
  25. while true do
  26. screen1.setCursorPos(13,2); screen1.write("TEMP")
  27.  
  28. local tempPercnt = (reactor.getTemperature() / maxTemp)*100
  29.  
  30. for i = 3,22 do
  31. screen1.setCursorPos(12,i); screen1.write("|")
  32.  
  33. screen1.setCursorPos(13,i)
  34. if reactor.getActive() then
  35. if tempPercnt <= 100 - (i-3)*5 then
  36. screen1.setBackgroundColor(colors.black)
  37. screen1.write(" ")
  38. screen1.setBackgroundColor(colors.black)
  39. else
  40. screen1.setBackgroundColor(colors.red)
  41. screen1.write(" ")
  42. screen1.setBackgroundColor(colors.black)
  43. end
  44. else
  45. screen1.setBackgroundColor(colors.gray)
  46. screen1.write(" ")
  47. screen1.setBackgroundColor(colors.black)
  48. end
  49. screen1.setCursorPos(16,i); screen1.write("|")
  50. end
  51. screen1.setCursorPos(13,24); screen1.write(reactor.getTemperature())
  52. coroutine.yield()
  53. end
  54. end)
  55.  
  56. displayControl = coroutine.create(function()
  57. while true do
  58. screen1.setCursorPos(2,2); screen1.write("CONTROL")
  59. for i = 3,22 do
  60. screen1.setCursorPos(3,i); screen1.write("|")
  61.  
  62. screen1.setCursorPos(4,i)
  63. if reactor.getActive() then
  64. if reactor.getControlRodLevel(controlRodIndex) <= 100 - (i-3)*5 then
  65. screen1.setBackgroundColor(colors.black)
  66. screen1.write(" ")
  67. screen1.setBackgroundColor(colors.black)
  68. else
  69. screen1.setBackgroundColor(colors.green)
  70. screen1.write(" ")
  71. screen1.setBackgroundColor(colors.black)
  72. end
  73. else
  74. screen1.setBackgroundColor(colors.gray)
  75. screen1.write(" ")
  76. screen1.setBackgroundColor(colors.black)
  77. end
  78.  
  79. screen1.setCursorPos(7,i); screen1.write("|")
  80. end
  81. screen1.setCursorPos(4,24); screen1.write(reactor.getControlRodLevel(controlRodIndex))
  82. coroutine.yield()
  83. end
  84. end)
  85.  
  86. displayPower = coroutine.create(function()
  87. while true do
  88. screen2.setCursorPos(3,5); screen2.write("POWER")
  89.  
  90. for i = 6,16 do
  91. screen2.setCursorPos(3,i); screen2.write("|")
  92.  
  93. screen2.setCursorPos(4,i)
  94. if reactor.getEnergyStored() <= 100 - (i-6)*10 then
  95. screen2.setBackgroundColor(colors.black)
  96. screen2.write(" ")
  97. screen2.setBackgroundColor(colors.black)
  98. else
  99. screen2.setBackgroundColor(colors.orange)
  100. screen2.write(" ")
  101. screen2.setBackgroundColor(colors.black)
  102. end
  103. screen2.setCursorPos(7,i); screen2.write("|")
  104. end
  105. screen2.setCursorPos(3,17); screen2.write("-----")
  106. screen2.setCursorPos(9,9); screen2.write("OUTPUT")
  107. screen2.setCursorPos(9,10); screen2.write("RATE")
  108. screen2.setCursorPos(9,11); screen2.write("------")
  109. screen2.setCursorPos(9,12); screen2.write(math.ceil(reactor.getEnergyProducedLastTick()))
  110. screen2.setCursorPos(9,13); screen2.write("------")
  111. coroutine.yield()
  112. end
  113. end)
  114.  
  115. displayStats = coroutine.create(function()
  116. local powerStored = reactor.getEnergyStored()
  117.  
  118. while true do
  119. screen2.setCursorPos(1,19); screen2.write(" NET POWER FLOW")
  120. screen2.setCursorPos(1,20); screen2.write("------------------")
  121. screen2.setCursorPos(1,21); screen2.write(" ")
  122. screen2.setCursorPos(2,21)
  123. if reactor.getEnergyStored() - powerStored < 0 then
  124. screen2.setBackgroundColor(colors.red)
  125. elseif reactor.getEnergyStored() - powerStored > 0 then
  126. screen2.setBackgroundColor(colors.green)
  127. else
  128. screen2.setBackgroundColor(colors.blue)
  129. end
  130. screen2.write(reactor.getEnergyStored() - powerStored)
  131. screen2.setBackgroundColor(colors.black)
  132. screen2.setCursorPos(1,22); screen2.write("------------------")
  133.  
  134. powerStored = reactor.getEnergyStored()
  135. coroutine.yield()
  136. end
  137. end)
  138.  
  139. displayStartStop = coroutine.create(function()
  140. while true do
  141. if reactor.getActive() then
  142. screen2.setCursorPos(3,24); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  143. screen2.setCursorPos(3,25); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  144. screen2.setCursorPos(3,26); screen2.setBackgroundColor(colors.red); screen2.write(" STOP "); screen2.setBackgroundColor(colors.black)
  145. screen2.setCursorPos(3,27); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  146. screen2.setCursorPos(3,28); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  147. else
  148. screen2.setCursorPos(3,24); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  149. screen2.setCursorPos(3,25); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  150. screen2.setCursorPos(3,26); screen2.setBackgroundColor(colors.green); screen2.write(" START "); screen2.setBackgroundColor(colors.black)
  151. screen2.setCursorPos(3,27); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  152. screen2.setCursorPos(3,28); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
  153. end
  154. coroutine.yield()
  155. end
  156. end)
  157.  
  158. function setupScreen1()
  159. screen1.clear()
  160. screen1.setBackgroundColor(colors.black)
  161. screen1.setCursorPos(1,23); screen1.write("------------------")
  162. screen1.setCursorPos(1,25); screen1.write("------------------")
  163. screen1.setCursorPos(3,27); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  164. screen1.setCursorPos(3,28); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  165. screen1.setCursorPos(3,29); screen1.setBackgroundColor(colors.blue); screen1.write(" - "); screen1.setBackgroundColor(colors.black)
  166. screen1.setCursorPos(3,30); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  167. screen1.setCursorPos(3,31); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  168. screen1.setCursorPos(12,27); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  169. screen1.setCursorPos(12,28); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  170. screen1.setCursorPos(12,29); screen1.setBackgroundColor(colors.blue); screen1.write(" + "); screen1.setBackgroundColor(colors.black)
  171. screen1.setCursorPos(12,30); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  172. screen1.setCursorPos(12,31); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
  173. screen1.setCursorPos(1,33); screen1.write(" ADJUST CONTROL ")
  174. end
  175.  
  176. function setupScreen2()
  177. screen2.clear()
  178. screen2.setBackgroundColor(colors.black)
  179. screen2.setCursorPos(1,1); screen2.write("------------------")
  180. screen2.setCursorPos(1,2); screen2.write(" REACTOR ONE")
  181. screen2.setCursorPos(1,3); screen2.write("------------------")
  182.  
  183. end
  184.  
  185. setupScreen1()
  186. setupScreen2()
  187.  
  188. while true do
  189. if reactor.getConnected() then
  190. os.startTimer(2)
  191. local event, var1, var2, var3 = os.pullEvent()
  192. if event == "timer" then
  193. coroutine.resume(displayTemp)
  194. coroutine.resume(displayControl)
  195. coroutine.resume(displayPower)
  196. coroutine.resume(displayStats)
  197. coroutine.resume(displayStartStop)
  198.  
  199. elseif event == "monitor_touch" then
  200. if var1 == screen1Name then
  201. if var2 >= 3 and var2 <= 7 then
  202. if var3 >= 27 and var3 <= 31 then
  203. if reactor.getControlRodLevel(controlRodIndex) ~= 0 then
  204. reactor.setAllControlRodLevels(reactor.getControlRodLevel(controlRodIndex) -5)
  205. end
  206. end
  207. elseif var2 >= 12 and var2 <= 16 then
  208. if var3 >= 27 and var3 <= 31 then
  209. if reactor.getControlRodLevel(controlRodIndex) ~= 100 then
  210. reactor.setAllControlRodLevels(reactor.getControlRodLevel(controlRodIndex) +5)
  211. end
  212. end
  213. end
  214. elseif var1 == screen2Name then
  215. if var2 >= 3 and var2 <= 16 then
  216. if var3 >= 24 and var3 <= 28 then
  217. if reactor.getActive() then
  218. reactor.setActive(false)
  219. else
  220. reactor.setActive(true)
  221. end
  222. end
  223. end
  224. else
  225. print("error")
  226. end
  227.  
  228. coroutine.resume(displayTemp)
  229. coroutine.resume(displayControl)
  230. coroutine.resume(displayPower)
  231. coroutine.resume(displayStats)
  232. coroutine.resume(displayStartStop)
  233. end
  234. end
  235. end
Advertisement
Add Comment
Please, Sign In to add comment