Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get 0X93VE9M mfsumon
- -- http://www.computercraft.info/forums2/index.php?/topic/16109-mfsu-monitor/
- --[[
- * Pad the left side of a string x number of times
- ]]
- local function padLeft(str, w)
- return string.rep(" ", w - #str) .. str
- end
- --[[
- * Locate the nearest
- ]]
- local function findPeripheral(_type)
- for _,name in pairs(peripheral.getNames()) do
- if peripheral.getType(name) == _type then
- return peripheral.wrap(name)
- end
- end
- end
- -- Locate the nearest monitor and power sources
- local m = findPeripheral("monitor")
- -- Error catches
- if not m then
- error("Cannot find monitor attached to this computer", 0)
- end
- m.setTextScale(0.5)
- local w, h = m.getSize()
- local totalCap = 0
- local totalStore = 0
- local percent = 0
- local mfsu
- os.startTimer(1)
- while true do
- -- Start getting numbers
- totalCap = 0
- totalStore = 0
- percent = 0
- for k,v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "mfsu" then
- -- Increment the storage and capacity
- mfsu = peripheral.wrap(v)
- totalCap = totalCap + mfsu.getEUCapacity()
- totalStore = totalStore + mfsu.getEUStored()
- end
- end
- -- Calculate a percentage
- percent = math.ceil(totalStore / totalCap) * 100
- m.clear()
- m.setCursorPos(1, 2)
- m.setTextColour(colours.orange)
- m.write("Avail EU: ")
- m.setTextColour(colours.white)
- m.write(tostring(percent) .. "%")
- -- If available power is 75% of more, turn redstone on
- if percent > 75 then
- redstone.setOutput("right", false)
- m.setCursorPos(1, 4)
- m.setTextColour(colours.orange)
- m.write("Redstone: ")
- m.setTextColour(colours.white)
- m.write("Off")
- end
- -- If power falls below 15%, turn redstone off
- if percent < 15 then
- redstone.setOutput("right", true)
- m.setCursorPos(1, 4)
- m.setTextColour(colours.orange)
- m.write("Redstone: ")
- m.setTextColour(colours.white)
- m.write("On")
- end
- os.pullEvent("timer")
- os.startTimer(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement