Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("right") --define monitor
- mon.setTextScale(0.5) --text size in 0.5 increments
- monX,monY = mon.getSize()
- rednet.open("back") --wireless modem only. wired just work
- power1 = peripheral.wrap("ic2:mfsu_2")
- power2 = peripheral.wrap("ic2:mfsu_3")
- power3 = peripheral.wrap("ic2:mfsu_4")
- power4 = peripheral.wrap("ic2:mfsu_1")
- generator1 = peripheral.wrap("ic2:matter_generator_1")
- local DEBUG = 1
- local reactorOnline = 0
- local turnOnAt = 30
- local turnOffAt = 90
- local maxpower1 = 0
- local curpower1 = 0
- local perpower1 = 0
- local maxpower2 = 0
- local curpower2 = 0
- local perpower2 = 0
- local maxpower3 = 0
- local curpower3 = 0
- local perpower3 = 0
- local maxpower4 = 0
- local curpower4 = 0
- local perpower4 = 0
- function readMFSU()
- maxPower1 = power1.getEUCapacity()
- curPower1 = power1.getEUStored()
- perPower1 = math.floor(((curPower1/maxPower1)*100)+0.5)
- maxPower2 = power2.getEUCapacity()
- curPower2 = power2.getEUStored()
- perPower2 = math.floor(((curPower2/maxPower2)*100)+0.5)
- maxPower3 = power3.getEUCapacity()
- curPower3 = power3.getEUStored()
- perPower3 = math.floor(((curPower3/maxPower3)*100)+0.5)
- maxPower4 = power4.getEUCapacity()
- curPower4 = power4.getEUStored()
- perPower4 = math.floor(((curPower4/maxPower4)*100)+0.5)
- avgPower = math.floor(((curPower1+curPower2+curPower3+curPower4)/(maxPower1*4)*100)+0.5)
- end
- function centerT(text,line,backColor,txtColor)
- mon.setBackgroundColor(backColor)
- mon.setTextColor(txtColor)
- length = (string.len(text))
- dif = math.floor(monX-length)
- x = math.floor(dif/2)
- mon.setCursorPos(x+1,line)
- mon.write(text)
- end
- function autoUU(per)
- if per < 5 then
- redstone.setOutput("left",true)
- print("UUMatter : OFF")
- title = " UUMatter Status: OFF "
- centerT(title,4,colors.red,colors.white)
- elseif per >= 5 then
- redstone.setOutput("left",false)
- print("UUMatter : ON")
- title = " UUMatter Status: ON "
- centerT(title,4,colors.black,colors.green)
- end
- end
- function drawBar(current,max,per,title,Y)
- if per > 70 then
- color=colors.green
- elseif (per >40) and (per < 70) then
- color=colors.orange
- elseif per < 40 then
- color=colors.red
- end
- bar = math.floor(((current/max)*(monX-2))+0.5)
- --Draw Background Bar
- mon.setCursorPos(2,Y)
- mon.setBackgroundColor(colors.black)
- mon.write(title.." MFSU")
- mon.setCursorPos(2,(Y+1))
- mon.setBackgroundColor(colors.blue)
- mon.write(string.rep(" ", monX-2))
- --Draw Percentage Bar
- mon.setCursorPos(2,(Y+1))
- mon.setBackgroundColor(color)
- mon.write(string.rep(" ", bar))
- mon.setCursorPos(2,(Y+1))
- mon.write(current .. "/" .. max .. " (" .. per .. "%)")
- end
- function updateScreens()
- --update computer screen
- term.setCursorPos(1,1)
- print("Average MFSU power: "..avgPower.."% Full")
- --update monitor
- mon.setCursorPos(1,1)
- mon.setBackgroundColor(colors.black)
- title = " Average MFSU Power " .. avgPower .. "% Full "
- centerT(title,1,colors.green,colors.white)
- if reactorOnline == 1 then
- print("Redstone Status: start")
- title = " Reactor Status: STARTED "
- centerT(title,3,colors.black,colors.green)
- elseif reactorOnline == 0 then
- print("Redstone Status: STOP")
- title = " Reactor Status: STOPPED "
- centerT(title,3,colors.red,colors.white)
- end
- if DEBUG == 1 then
- print("avgPower: "..avgPower)
- print("turnOnAt: "..turnOnAt)
- print("turnOffAt: "..turnOffAt)
- print("reactorOnline: "..reactorOnline)
- print("overlay bar value: "..bar)
- print("monitor XxY size: "..monX.."x"..monY)
- end
- end
- function autoReactor()
- if avgPower < turnOnAt then
- if reactorOnline == 0 then
- rednet.broadcast("start")
- reactorOnline = 1
- end
- end
- if avgPower >= turnOffAt then
- if reactorOnline == 1 then
- rednet.broadcast("STOP")
- reactorOnline = 0
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- mon.clear()
- term.clear()
- while true do
- readMFSU()
- drawBar(curPower1,maxPower1,perPower1,"1st",5)
- drawBar(curPower2,maxPower2,perPower2,"2nd",8)
- drawBar(curPower3,maxPower3,perPower3,"3rd",11)
- drawBar(curPower4,maxPower4,perPower4,"4th",14)
- autoReactor()
- autoUU(avgPower)
- updateScreens()
- sleep(1)
- end
Add Comment
Please, Sign In to add comment