Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Find peripherals
- local meBridge = peripheral.find("meBridge")
- local monitor = peripheral.find("monitor")
- if not meBridge then
- error("ME Bridge not found!")
- end
- if not monitor then
- error("Monitor not found!")
- end
- -- Set up monitor
- monitor.setTextScale(0.75) -- Medium text size
- monitor.setCursorBlink(false)
- monitor.clear()
- -- Function to draw a two-color progress bar
- local function drawProgressBar(x, y, width, height, progress)
- local filledWidth = math.floor(width * math.max(0, math.min(1, progress))) -- Clamp between 0 and 1
- -- Draw background (gray)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- for i = 0, height - 1 do
- monitor.setCursorPos(x, y + i)
- monitor.write(string.rep(" ", width))
- end
- -- Draw filled progress (green)
- monitor.setBackgroundColor(colors.green)
- for i = 0, height - 1 do
- monitor.setCursorPos(x, y + i)
- monitor.write(string.rep(" ", filledWidth))
- end
- -- Reset background color
- monitor.setBackgroundColor(colors.black)
- end
- -- Store previous values to minimize unnecessary updates
- local prevUsed, prevTotal
- -- Main loop
- while true do
- -- Get storage data
- local totalStorage = meBridge.getTotalItemStorage()
- local usedStorage = meBridge.getUsedItemStorage()
- -- Prevent division by zero
- local progress = usedStorage / (totalStorage > 0 and totalStorage or 1)
- -- Format numbers for alignment
- local usedStr = string.format("%10d", usedStorage) -- Right-align to 10 characters
- local totalStr = string.format("%10d", totalStorage) -- Right-align to 10 characters
- -- Update only if values have changed
- if usedStorage ~= prevUsed or totalStorage ~= prevTotal then
- monitor.clear()
- -- Display storage info
- monitor.setCursorPos(2, 1)
- monitor.write("ME Storage Monitor")
- monitor.setCursorPos(2, 3)
- monitor.write("Used: " .. usedStr .. " items")
- monitor.setCursorPos(2, 4)
- monitor.write("Total: " .. totalStr .. " items")
- -- Draw progress bar
- drawProgressBar(2, 6, 30, 2, progress)
- -- Store previous values
- prevUsed = usedStorage
- prevTotal = totalStorage
- end
- -- Wait before updating
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment