-- reactor_monitor.lua
-- Attach modem to "back" (or change side)
-- Attach monitor to "right" (or change side)
local modemSide = "back"
local monitorSide = "right"
local channel = "reactorFuel"
local mon = peripheral.wrap(monitorSide)
if not mon then
error("No monitor on " .. monitorSide)
end
rednet.open(modemSide)
mon.setTextScale(1)
local function drawBar(fuel)
local w, h = mon.getSize()
local barWidth = math.floor(fuel * w)
-- Clear
mon.setBackgroundColor(colors.black)
mon.clear()
-- Fuel bar
for x = 1, barWidth do
local color
if fuel > 0.5 then
color = colors.green
elseif fuel > 0.25 then
color = colors.orange
else
color = colors.red
end
mon.setBackgroundColor(color)
mon.setCursorPos(x, h // 2)
mon.write(" ")
end
-- Text overlay
mon.setBackgroundColor(colors.black)
mon.setCursorPos(1, h)
mon.write("Fuel: " .. math.floor(fuel * 100) .. "%")
end
while true do
local id, fuel, proto = rednet.receive(channel)
if fuel then
drawBar(fuel)
end
end