tsargothruneclaw

Big Reactor Controller

May 2nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Set peripheral wrapping
  2.  
  3. local Reactor = peripheral.wrap("BigReactors-Reactor_0")
  4. local Turbine = peripheral.wrap("BigReactors-Turbine_0")
  5. local BatterySide= "right"
  6.  
  7. -- Constants
  8.  
  9. local batteryLow = 3
  10. local batteryHigh = 12
  11. local batteryState=false
  12. local active=false
  13. local rodBase=75
  14. local rod=rodBase
  15.  
  16. -- Functions
  17.  
  18. function checkBattery()
  19.     if (redstone.getAnalogInput(BatterySide) <= batteryLow) then
  20.         batteryState=true
  21.     elseif (redstone.getAnalogInput(BatterySide) >= batteryHigh) then
  22.         batteryState=false
  23.     end
  24.     return batteryState
  25. end
  26.  
  27. function control()
  28.     Reactor.setActive(active)
  29.     Turbine.setActive(active)
  30. end
  31.  
  32. function tune()
  33.  
  34.     rod=Reactor.getControlRodLevel(0)
  35.     if (active) then
  36.  
  37.         if (Reactor.getHotFluidProducedLastTick()< 2000) then
  38.             rod=rod-1
  39.             if (rod <1 ) then rod=1 end
  40.         elseif (Reactor.getHotFluidProducedLastTick()> 2060 or Reactor.getFuelTemperature()>200) then
  41.             rod=rod+1
  42.             if (rod > 100) then rod=100 end
  43.         end
  44.     end
  45.     Reactor.setAllControlRodLevels(rod)
  46. end
  47. -- Start up
  48.     Reactor.setAllControlRodLevels(rodBase)
  49.  
  50. while true do
  51.  
  52. if (checkBattery()) then
  53.     active=true
  54. else
  55.     active=false
  56. end
  57.     control()
  58.     tune()
  59.     sleep(10)
  60. end
Add Comment
Please, Sign In to add comment