Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Use sides or modem names to connect the devices
- local reactorName = "back"
- local redstoneListener = "top"
- local redstoneOutput = "right"
- -- How long to wait for various parts of the program. Do note that
- -- any changes to sleepDelay will affect updateDelay.
- local connectDelay = 1
- local updateDelay = 2
- local sleepDelay = 1
- -- Whether or not to clear display between printouts
- local clearDisplay = true
- -- Used internally. Do not adjust.
- local reactor = nil
- local isOnline = true
- local hasFuel = true
- local rodLevels = 100
- local updateCountdown = 0
- local redPower = 0
- function getConnected()
- while reactor == nil do
- reactor=peripheral.wrap(reactorName)
- if reactor == nil then
- print("Waiting for reactor peripheral")
- os.sleep(reactorDelay)
- end
- end
- print("Found reactor.")
- while not reactor.getConnected() do
- print("Waiting for reactor to connect.")
- os.sleep(reactorDelay)
- end
- print("Program Initialized.")
- end
- function adjustLevels()
- if reactor.getEnergyStored()>= 1 then
- rodLevels = math.floor(reactor.getEnergyStored()/100000)
- else
- rodLevels = 0 --Full Draw
- end
- reactor.setAllControlRodLevels(rodLevels)
- end
- function checkIssues()
- if reactor.getFuelAmount()<=100 and isOnline then
- rodLevels = 100
- reactor.setAllControlRodLevels(100)
- reactor.setActive(false)
- hasFuel = false
- else
- hasFuel = true
- end
- if rs.getInput(redstoneListener)==false and hasFuel then
- reactor.setActive(true)
- isOnline = true
- end
- if rs.getInput(redstoneListener)==true and hasFuel then
- rodLevels = 100
- reactor.setActive(false)
- reactor.setAllControlRodLevels(100)
- isOnline = false
- end
- end
- function displayUpdate()
- if clearDisplay then
- term.clear()
- term.setCursorPos(1,1)
- end
- if not hasFuel then
- print("Reactor Offline - No Fuel")
- elseif not isOnline then
- print("Reactor Offline - Detected Redstone")
- else
- print("Reactor Online - "..(100 - rodLevels).."% Production.")
- end
- end
- function determineOutput()
- if not (redstoneListener == redstoneOutput) then
- if rodLevels < 100 then
- redPower = math.floor((100 - rodLevels) / 15) + 1
- else
- redPower = 0
- end
- rs.setAnalogOutput(redstoneOutput, redPower)
- end
- end
- getConnected()
- while true do
- checkIssues()
- if hasFuel and isOnline then
- adjustLevels()
- end
- determineOutput()
- if updateCountdown > 0 then
- updateCountdown = updateCountdown - 1
- else
- updateCountdown = updateDelay
- displayUpdate()
- end
- os.sleep(sleepDelay)
- end
Add Comment
Please, Sign In to add comment