Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- local power = sensor.wrap("left")
- local net = peripheral.wrap("back")
- local mon = "monitor_0"
- if ( power == nil ) then
- print("No sensor!")
- os.exit()
- end
- if ( net == nil ) then
- print("No network!")
- os.exit()
- end
- -- coordinates of blocks to monitor
- local locations = {"-1,-1,0","0,-1,0","1,-1,0","-2,-2,-1"}
- function displayPercent(percent)
- net.callRemote(mon,"clear")
- net.callRemote(mon,"setCursorPos",2,3)
- --local display = string.format("%.2f",percent)
- local display = string.sub(tostring(percent),1,4) .. "%"
- net.callRemote(mon,"write",display)
- end
- function getEnergySpace()
- local location
- local total = 0
- local totalStorage = 0
- for i,location in ipairs(locations) do
- local blockInfo = power.getTargetDetails(location)
- if ( blockInfo == nil ) then
- print("Can't get block info " .. location)
- exit()
- end
- total = total + blockInfo["Stored"]
- totalStorage = totalStorage + blockInfo["Capacity"]
- end
- percentTotal = 100 * total / totalStorage
- displayPercent(percentTotal)
- return percentTotal
- end
- while true do
- if ( getEnergySpace() < 95 ) then
- rs.setBundledOutput("right",colors.white)
- os.sleep(2)
- else
- rs.setBundledOutput("right",0)
- os.sleep(10)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement