Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This code is designed to leave the reactor on all the times and maintain
- --power levels by adjusting the control rod insertion
- --return a integar ignoring any remainder
- function DIV(a,b)
- return (a - (a % b)) / b
- end
- --the total size of the buffer
- local BUFFER_MAX = 10000000
- --the amount of power we want to maintain in the buffer
- local TARGET_AMOUNT = 5000000
- --the default insertion of control rods
- local controlLevel = 50
- --connect to reactor
- local reactor = peripheral.wrap("back")
- --confirm connection
- if(not reactor.getConnected) then
- print("Not connected to Reactor")
- end
- --turn the reactor on
- if(not reactor.getActive()) then
- reactor.setActive(true)
- print("Starting Reactor")
- end
- --move control rod to defaul level
- reactor.setAllControlRodLevels(controlLevel)
- while(true) do
- --control the rods to maintain a specified buffer
- --find the current amount of energy in the buffer
- local currentEnergy = reactor.getEnergyStored()
- --set the new control level to the difference between the
- --amount of evergy and wanted energy
- local number = (currentEnergy - TARGET_AMOUNT)
- print("Number: ", number)
- local controlNumber = DIV(math.abs(number), 100000)
- print("Control Number: ", contorolNumber)
- if (number > 0) then
- controlLevel = controlLevel + controlNumber
- elseif(number < 0 ) then
- controlLevel = controlLevel - controlNumber
- end
- if (controlLevel < 0) then
- controlLevel = 0
- elseif (controlLevel > 100) then
- controlLevel = 100
- end
- reactor.setAllControlRodLevels(controlLevel)
- print("Control Level: %d", controlLevel)
- --Check reactor
- if(reactor.getFuelAmount() == 0)then
- redstone.setOutput("right", true)
- print("Control Rods complety Open")
- end
- sleep(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement