Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------
- -- Big Reactors Control System --
- -- Written by Jharakn --
- ---------------------------------
- --Specific Variables------------------------------
- local reactorName = "BigReactors-Reactor_0"
- local screen1Name = "monitor_0"
- local screen2Name = "monitor_1"
- local maxTemp = 180
- local controlRodIndex = 0 --should be 0 I don't know if it changes
- --------------------------------------------------
- --Global Variables--------------------------------
- local rodPosition = 0
- --------------------------------------------------
- local reactor = peripheral.wrap(reactorName)
- local screen1 = peripheral.wrap(screen1Name)
- local screen2 = peripheral.wrap(screen2Name)
- screen2.clear()
- displayTemp = coroutine.create(function()
- while true do
- screen1.setCursorPos(13,2); screen1.write("TEMP")
- local tempPercnt = (reactor.getTemperature() / maxTemp)*100
- for i = 3,22 do
- screen1.setCursorPos(12,i); screen1.write("|")
- screen1.setCursorPos(13,i)
- if reactor.getActive() then
- if tempPercnt <= 100 - (i-3)*5 then
- screen1.setBackgroundColor(colors.black)
- screen1.write(" ")
- screen1.setBackgroundColor(colors.black)
- else
- screen1.setBackgroundColor(colors.red)
- screen1.write(" ")
- screen1.setBackgroundColor(colors.black)
- end
- else
- screen1.setBackgroundColor(colors.gray)
- screen1.write(" ")
- screen1.setBackgroundColor(colors.black)
- end
- screen1.setCursorPos(16,i); screen1.write("|")
- end
- screen1.setCursorPos(13,24); screen1.write(reactor.getTemperature())
- coroutine.yield()
- end
- end)
- displayControl = coroutine.create(function()
- while true do
- screen1.setCursorPos(2,2); screen1.write("CONTROL")
- for i = 3,22 do
- screen1.setCursorPos(3,i); screen1.write("|")
- screen1.setCursorPos(4,i)
- if reactor.getActive() then
- if reactor.getControlRodLevel(controlRodIndex) <= 100 - (i-3)*5 then
- screen1.setBackgroundColor(colors.black)
- screen1.write(" ")
- screen1.setBackgroundColor(colors.black)
- else
- screen1.setBackgroundColor(colors.green)
- screen1.write(" ")
- screen1.setBackgroundColor(colors.black)
- end
- else
- screen1.setBackgroundColor(colors.gray)
- screen1.write(" ")
- screen1.setBackgroundColor(colors.black)
- end
- screen1.setCursorPos(7,i); screen1.write("|")
- end
- screen1.setCursorPos(4,24); screen1.write(reactor.getControlRodLevel(controlRodIndex))
- coroutine.yield()
- end
- end)
- displayPower = coroutine.create(function()
- while true do
- screen2.setCursorPos(3,5); screen2.write("POWER")
- for i = 6,16 do
- screen2.setCursorPos(3,i); screen2.write("|")
- screen2.setCursorPos(4,i)
- if reactor.getEnergyStored() <= 100 - (i-6)*10 then
- screen2.setBackgroundColor(colors.black)
- screen2.write(" ")
- screen2.setBackgroundColor(colors.black)
- else
- screen2.setBackgroundColor(colors.orange)
- screen2.write(" ")
- screen2.setBackgroundColor(colors.black)
- end
- screen2.setCursorPos(7,i); screen2.write("|")
- end
- screen2.setCursorPos(3,17); screen2.write("-----")
- screen2.setCursorPos(9,9); screen2.write("OUTPUT")
- screen2.setCursorPos(9,10); screen2.write("RATE")
- screen2.setCursorPos(9,11); screen2.write("------")
- screen2.setCursorPos(9,12); screen2.write(math.ceil(reactor.getEnergyProducedLastTick()))
- screen2.setCursorPos(9,13); screen2.write("------")
- coroutine.yield()
- end
- end)
- displayStats = coroutine.create(function()
- local powerStored = reactor.getEnergyStored()
- while true do
- screen2.setCursorPos(1,19); screen2.write(" NET POWER FLOW")
- screen2.setCursorPos(1,20); screen2.write("------------------")
- screen2.setCursorPos(1,21); screen2.write(" ")
- screen2.setCursorPos(2,21)
- if reactor.getEnergyStored() - powerStored < 0 then
- screen2.setBackgroundColor(colors.red)
- elseif reactor.getEnergyStored() - powerStored > 0 then
- screen2.setBackgroundColor(colors.green)
- else
- screen2.setBackgroundColor(colors.blue)
- end
- screen2.write(reactor.getEnergyStored() - powerStored)
- screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(1,22); screen2.write("------------------")
- powerStored = reactor.getEnergyStored()
- coroutine.yield()
- end
- end)
- displayStartStop = coroutine.create(function()
- while true do
- if reactor.getActive() then
- screen2.setCursorPos(3,24); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,25); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,26); screen2.setBackgroundColor(colors.red); screen2.write(" STOP "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,27); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,28); screen2.setBackgroundColor(colors.red); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- else
- screen2.setCursorPos(3,24); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,25); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,26); screen2.setBackgroundColor(colors.green); screen2.write(" START "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,27); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(3,28); screen2.setBackgroundColor(colors.green); screen2.write(" "); screen2.setBackgroundColor(colors.black)
- end
- coroutine.yield()
- end
- end)
- function setupScreen1()
- screen1.clear()
- screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(1,23); screen1.write("------------------")
- screen1.setCursorPos(1,25); screen1.write("------------------")
- screen1.setCursorPos(3,27); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(3,28); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(3,29); screen1.setBackgroundColor(colors.blue); screen1.write(" - "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(3,30); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(3,31); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(12,27); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(12,28); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(12,29); screen1.setBackgroundColor(colors.blue); screen1.write(" + "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(12,30); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(12,31); screen1.setBackgroundColor(colors.blue); screen1.write(" "); screen1.setBackgroundColor(colors.black)
- screen1.setCursorPos(1,33); screen1.write(" ADJUST CONTROL ")
- end
- function setupScreen2()
- screen2.clear()
- screen2.setBackgroundColor(colors.black)
- screen2.setCursorPos(1,1); screen2.write("------------------")
- screen2.setCursorPos(1,2); screen2.write(" REACTOR ONE")
- screen2.setCursorPos(1,3); screen2.write("------------------")
- end
- setupScreen1()
- setupScreen2()
- while true do
- if reactor.getConnected() then
- os.startTimer(2)
- local event, var1, var2, var3 = os.pullEvent()
- if event == "timer" then
- coroutine.resume(displayTemp)
- coroutine.resume(displayControl)
- coroutine.resume(displayPower)
- coroutine.resume(displayStats)
- coroutine.resume(displayStartStop)
- elseif event == "monitor_touch" then
- if var1 == screen1Name then
- if var2 >= 3 and var2 <= 7 then
- if var3 >= 27 and var3 <= 31 then
- if reactor.getControlRodLevel(controlRodIndex) ~= 0 then
- reactor.setAllControlRodLevels(reactor.getControlRodLevel(controlRodIndex) -5)
- end
- end
- elseif var2 >= 12 and var2 <= 16 then
- if var3 >= 27 and var3 <= 31 then
- if reactor.getControlRodLevel(controlRodIndex) ~= 100 then
- reactor.setAllControlRodLevels(reactor.getControlRodLevel(controlRodIndex) +5)
- end
- end
- end
- elseif var1 == screen2Name then
- if var2 >= 3 and var2 <= 16 then
- if var3 >= 24 and var3 <= 28 then
- if reactor.getActive() then
- reactor.setActive(false)
- else
- reactor.setActive(true)
- end
- end
- end
- else
- print("error")
- end
- coroutine.resume(displayTemp)
- coroutine.resume(displayControl)
- coroutine.resume(displayPower)
- coroutine.resume(displayStats)
- coroutine.resume(displayStartStop)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment