Skip to content

Instantly share code, notes, and snippets.

@asvae
Created August 28, 2025 13:22
Show Gist options
  • Select an option

  • Save asvae/4210585bad992b22c8a317122aa68e46 to your computer and use it in GitHub Desktop.

Select an option

Save asvae/4210585bad992b22c8a317122aa68e46 to your computer and use it in GitHub Desktop.
-- Finds the first energy buffer (your AE2 acceptor) and a monitor,
-- then shows stored energy & approximate FE/t on the monitor.
local dev = peripheral.find("energy_storage")
assert(dev, "No energy_storage peripheral found (check wired modem ON & cabling)")
local mon = peripheral.find("monitor")
assert(mon, "No monitor found. Place one and connect (touching or via wired modem).")
-- make the monitor comfy to read
mon.setTextScale(1.5) -- try 2.0 on very large monitors, 1.0 on small ones
mon.setBackgroundColor(colors.black)
mon.setTextColor(colors.white)
local function drawOn(termLike, lines)
local old = term.redirect(termLike)
term.clear(); term.setCursorPos(1,1)
for i, line in ipairs(lines) do
term.setCursorPos(1, i); term.clearLine(); term.write(line)
end
term.redirect(old)
end
local lastE = dev.getEnergy()
local lastT = os.clock()
while true do
sleep(1.0) -- sample every ~1s
local nowE = dev.getEnergy()
local cap = dev.getEnergyCapacity()
local nowT = os.clock()
local dE = nowE - lastE
local dt = math.max(nowT - lastT, 0.05)
local fe_per_s = dE / dt
local fe_per_t = fe_per_s / 20 -- 20 ticks per second
local lines = {
("Power meter"):upper(),
string.rep("-", 24),
("Stored: %d / %d FE"):format(nowE, cap),
("Flow: %.1f FE/t (+gen / -use)"):format(fe_per_t),
"",
"Tip: enlarge monitor or tweak setTextScale."
}
-- draw to the monitor
drawOn(mon, lines)
-- (optional) also draw in the computer terminal:
drawOn(term.current(), lines)
lastE, lastT = nowE, nowT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment