Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function findMonitors()
- local monitors = {}
- for _, name in pairs(peripheral.getNames()) do
- if string.match(name, "^monitor_") then
- local monitor = peripheral.wrap(name)
- table.insert(monitors, monitor)
- end
- end
- return monitors
- end
- local function drawBar(monitor, x, y, width, fillPercentage)
- local w, h = monitor.getSize()
- term.redirect(monitor)
- paintutils.drawLine(3, 3, 4, 3, colors.lime)
- paintutils.drawLine(13, 3, w - 2, 3, colors.lime)
- paintutils.drawLine(3, 3, 3, h - 1, colors.lime)
- paintutils.drawLine(w - 2, 3, w - 2, h - 1, colors.lime)
- paintutils.drawLine(w - 2, h - 1, 3, h - 1, colors.lime)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(6, 3)
- monitor.write("[INFO]")
- local fillWidth = math.floor(width * fillPercentage)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(x, y)
- monitor.write("[ ")
- for i = 1, width do
- if i <= fillWidth then
- monitor.setBackgroundColor(colors.green)
- monitor.write(" ")
- else
- monitor.setBackgroundColor(colors.red)
- monitor.write(" ")
- end
- end
- monitor.setBackgroundColor(colors.gray)
- monitor.write(" ] " .. math.floor(fillPercentage * 100) .. "%")
- end
- local jouleToFeRatio = 276 / 690 -- 1 J = (276 / 690) Fe
- local monitors = findMonitors()
- if #monitors == 0 then
- print("No monitors found. Please connect a monitor.")
- return
- end
- local monitor = monitors[1]
- local modem = peripheral.wrap("back")
- modem.open(11)
- local battery
- for _, name in pairs(peripheral.getNames()) do
- if string.match(name, "^inductionPort_0") then
- battery = peripheral.wrap(name)
- break
- end
- end
- if not battery then
- print("IC2 battery not found. Please use modem and right-click on it to connect.")
- return
- end
- while true do
- local totalEnergyJoule = battery.getEnergy()
- local capPercentageJoule = battery.getEnergyFilledPercentage() or 0
- local totalEnergyFe = totalEnergyJoule * jouleToFeRatio
- local capPercentageFe = capPercentageJoule -- Remove unnecessary multiplication
- monitor.clear()
- drawBar(monitor, 5, 7, 20, capPercentageFe)
- monitor.setCursorPos(5, 5)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.black)
- monitor.write("Energy: " .. string.format("%.2f", totalEnergyFe / 1000) .. " kFe") -- Display in kFe
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement