Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. -- 4x3 monitor, left side
  2. -- 2 turbines
  3. -- hopefully cant explode :)
  4. -- and an advanced computer would help
  5. -- name Drawsquare drawsquare and touchpoint touchpoint
  6.  
  7. turbine1 = peripheral.wrap("BigReactors-Turbine_9")
  8. turbine2 = peripheral.wrap("BigReactors-Turbine_8")
  9. --os.loadAPI("turbine/touchpoint")
  10. --[[ Simple function to draw a square with desired colours, x and y co-ordinates,
  11. and text within the function.
  12.  
  13. borderCol = colour of the outside border
  14. boxCol = colour of the inside of the box
  15. textCol = colour of the text that appears within the box
  16. xStart = starting X position of the box (top left hand corner of the box)
  17. xEnd = ending X position of the box (top right hand corner of the box)
  18. yStart = starting Y positon of the box
  19. ... = arguments, accepts as many as you want. First one is the title.
  20. --]]
  21.  
  22. os.loadAPI("turbine/drawsquare")
  23. t = touchpoint.new("left")
  24.  
  25. mon = peripheral.wrap("left")
  26. monX,monY = mon.getSize() -- 39, 19
  27.  
  28. local turbinendis = false
  29. local turbinendis2 = false
  30. local turbine1power = 0
  31. local turbine2power = 0
  32. local turbine1inductor = false
  33. local turbine2inductor = false
  34. local manual = false
  35.  
  36. t:add(" Manual Control", nil, 12, 15, 28, 18, colors.red, colors.lime)
  37.  
  38. function checkPower()
  39. turbine1power = turbine1.getEnergyProducedLastTick()
  40. turbine2power = turbine2.getEnergyProducedLastTick()
  41. turbine1inductor = turbine1.getInductorEngaged()
  42. turbine2inductor = turbine2.getInductorEngaged()
  43. end
  44.  
  45. function writeMon()
  46. mon.clear()
  47. t:draw()
  48. mon.setBackgroundColor(colors.black)
  49. if turbine1inductor == false then
  50. drawsquare.drawSquare(colors.red, colors.red, colors.orange, 3,15,2, "off")
  51. end
  52. if turbine1inductor == true then
  53. drawsquare.drawSquare(colors.lime, colors.lime, colors.green, 3,15,2, "on")
  54. end
  55. if turbine2inductor == false then
  56. drawsquare.drawSquare(colors.red, colors.red, colors.orange, 25,37,2, "off")
  57. end
  58. if turbine2inductor == true then
  59. drawsquare.drawSquare(colors.lime, colors.lime, colors.green, 25,37,2, "on")
  60. end
  61.  
  62. mon.setCursorPos(2,1)
  63. mon.write("Turbine 1 Inductor")
  64.  
  65. mon.setCursorPos(22,1)
  66. mon.write("Turbine 2 Inductor")
  67.  
  68. mon.setCursorPos(2,7)
  69. mon.write("Rotor speed: " .. math.floor(turbine1.getRotorSpeed()))
  70.  
  71. mon.setCursorPos(22,7)
  72. mon.write("Rotor speed: " .. math.floor(turbine2.getRotorSpeed()))
  73.  
  74. mon.setCursorPos(2,8)
  75. mon.write("Power " .. math.floor(turbine1power) .. "RF/t")
  76.  
  77. mon.setCursorPos(22,8)
  78. mon.write("Power " .. math.floor(turbine2power) .. "RF/T")
  79.  
  80. mon.setCursorPos(9,10)
  81. mon.write("Total Power:" .. math.floor(turbine1power + turbine2power) .. "RF/T")
  82. end
  83.  
  84. while true do
  85. checkPower()
  86. writeMon()
  87. local event, button = t:handleEvents(os.pullEvent())
  88. if event == "button_click" then
  89. t:toggleButton(button)
  90. if manual == false then
  91. manual = true
  92. end
  93.  
  94. if manual == true then
  95. manual = false
  96. end
  97.  
  98. end
  99.  
  100. if manual == false then
  101. turbine1.setActive(true)
  102. turbine2.setActive(true)
  103.  
  104. turbine1.setVentOverflow(true)
  105. turbine2.setVentOverflow(true)
  106.  
  107. turbine1.setFluidFlowRateMax(2000)
  108. turbine2.setFluidFlowRateMax(2000)
  109.  
  110. if turbine1.getRotorSpeed() >= 20000 then
  111. if turbine1inductor == false then
  112.  
  113. turbine1.setInductorEngaged(true)
  114. print("Turbine 1 Inductor Engaged")
  115. sleep(1)
  116. print("Turbine 1 Generating " .. turbine1.getEnergyProducedLastTick() .. "RF/T")
  117. end
  118. end
  119.  
  120. if turbine1.getRotorSpeed() < 10000 then
  121. if turbine1inductor == true then
  122.  
  123. turbine1.setInductorEngaged(false)
  124. print("Turbine 1 Inductor Disengaged")
  125. end
  126. end
  127.  
  128. if turbine2.getRotorSpeed() >= 20000 then
  129. if turbine2inductor == false then
  130.  
  131. turbine2.setInductorEngaged(true)
  132. print("Turbine 2 Inductor Engaged")
  133. sleep(1)
  134. print("Turbine 2 Generating " .. turbine2.getEnergyProducedLastTick() .. "RF/T")
  135. end
  136. end
  137.  
  138. if turbine2.getRotorSpeed() < 10000 then
  139. if turbine2inductor == true then
  140.  
  141. turbine2.setInductorEngaged(false)
  142. print("Turbine 2 Inductor Disengaged")
  143. end
  144. end
  145. end
  146. sleep(0.2)
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement