Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Power controller
- function Reduce(num)
- local temp = 0
- local a = ""
- if num > 1000 then
- temp = round(num / 1000, 2)
- a = temp .. "KRF"
- end
- if num > 1000000 then
- temp = round(num / 1000000, 2)
- a = temp .. "MRF"
- end
- if num > 1000000000 then
- temp = round(num / 1000000000, 2)
- a = temp .. "GRF"
- end
- return a
- end
- function round(number, decimal)
- local multiplier = 10^(decimal or 0)
- return math.floor(number * multiplier + 0.5) / multiplier
- end
- local modem = peripheral.wrap("back")
- modem.open(1)
- --=Chanel 1 is used for recieving all transmissions
- local monitor = peripheral.wrap("right")
- local w, h = monitor.getSize()
- --Prints header to monitor
- local header = "Power monitor"
- local sLenght = string.len(header)
- monitor.clear()
- monitor.setCursorPos((w / 2) - (sLenght / 2), 1)
- monitor.write(header)
- local numberOfReactors = 2
- while true do
- local event, modemSide, recieveChan, replyChan, msg, senderDistance = os.pullEvent("modem_message")
- print(msg)
- local t = textutils.unserialize(msg)
- for i = 0, numberOfReactors - 1 do
- if t[1] == (i + 1) then
- if t[2] == true then
- monitor.setTextColor(colors.green)
- monitor.setCursorPos(1, 3 + (5 * i))
- monitor.clearLine()
- monitor.write("Reactor " .. i .. ": ")
- local x, y = monitor.getCursorPos()
- monitor.setCursorPos(x + 2, y)
- monitor.write("Online")
- monitor.setTextColor(colors.white)
- else
- monitor.setTextColor(colors.red)
- monitor.setCursorPos(1, 3 + (5 * i))
- monitor.clearLine()
- monitor.write("Reactor " .. i .. ": ")
- local x, y = monitor.getCursorPos()
- monitor.setCursorPos(x + 2, y)
- monitor.write("Offline")
- monitor.setTextColor(colors.white)
- end
- monitor.setCursorPos(1, 4 + (5 * i))
- monitor.clearLine()
- monitor.write("Energy stored: ".. round(t[4], 2) .."%")
- monitor.setCursorPos(1, 5 + (5 * i))
- monitor.clearLine()
- local temp = Reduce(t[3])
- monitor.write("Energy last tick: ".. temp)
- end
- end
- if t[1] == 3 then
- monitor.setCursorPos(1, (numberOfReactors * 5) + 3)
- monitor.clearLine()
- monitor.setTextColor(colors.green)
- monitor.write("Induction Matrix: ")
- local x,y = monitor.getCursorPos()
- monitor.setCursorPos(x + 2, y)
- monitor.write(reduce(t[5]))
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(1, (numberOfReactors * 5) + 4)
- monitor.clearLine()
- monitor.write("Energy stored: " .. round(t[2], 2) .. "%")
- monitor.setCursorPos(1, (numberOfReactors * 5) + 5)
- monitor.clearLine()
- local temp = Reduce(t[3])
- monitor.write("Input: " .. temp)
- monitor.setCursorPos(1, (numberOfReactors * 5) + 6)
- monitor.clearLine()
- temp = Reduce(t[4])
- monitor.write("Output: " .. temp)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment