Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- threshold = 0.8
- notifThreshold = 0.25
- mon = peripheral.find("monitor")
- modem = peripheral.find("modem")
- notifSentFlag = false
- cells = table.pack(peripheral.find("thermal:energy_cell"))
- function notifSend (text)
- modem.transmit(1337,1,text)
- end
- function writeMonStatus (state,pct)
- mon.clear()
- if mon.setTextScale ~= nil then
- mon.setTextScale(1)
- local width, height = mon.getSize()
- if width < 15 or height < 5 then -- Small monitor - scale down
- mon.setTextScale(0.5)
- else -- Large monitor - scale up
- local scale = math.min(width / 14, height / 2, 5)
- scale = math.floor(scale * 2) / 2 -- multiple of 0.5
- mon.setTextScale(scale)
- end
- end
- mon.setCursorPos(1,1)
- mon.write("State: " .. (state and "On" or "Off"))
- mon.setCursorPos(1,2)
- mon.write("Energy: " .. pct .. "%")
- end
- function main ()
- local energyCur = 0
- local energyMax = 0
- for _,cell in ipairs(cells) do -- ipairs avoids returning count (key "n")
- energyCur = energyCur + cell.getEnergy()
- energyMax = energyMax + cell.getEnergyCapacity()
- end
- local energyFraction = energyCur/energyMax
- print(energyFraction)
- local energyPercent = string.format("%.2f",
- math.floor(energyFraction*10000)/100)
- if energyFraction < notifThreshold then
- if not notifSentFlag then
- notifSentFlag = true
- notifSend("Warning: Base power capacity at "
- ..energyPercent.."%")
- end
- else
- notifSentFlag = false
- end
- local state = energyFraction < threshold
- redstone.setOutput("top",state)
- writeMonStatus(state,energyPercent)
- end
- while true do
- status,err = pcall(main)
- if not status then print(err) end
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement