Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chestSide = "bottom"
- signalSide = "top"
- updateDelay = 5 --in seconds
- fill = 0.98 --in % --> 0-1
- x,y = term.getSize()
- function clear() --GUI stuff.
- term.clear()
- term.setCursorPos(1,1)
- end
- function drawLine() --GUI stuff.
- for i=1,x-1 do
- write("-")
- end
- end
- function valueExists(tbl,value) --Checks if a value exists in a table.
- for k,v in ipairs(tbl) do
- if value == v then
- return true
- end
- end
- return false
- end
- function setup()
- clear()
- drawLine()
- print("Monitoring on side: "..chestSide)
- print("Sending signal to side: "..signalSide.." every "..updateDelay.." seconds.")
- print("Outputting if above "..(fill*100).."%")
- drawLine()
- chest = peripheral.wrap(chestSide)
- if chest == nil then
- clear()
- drawLine()
- print("No chest found!")
- drawLine()
- error()
- end
- sleep(2)
- end
- function display()
- clear()
- drawLine()
- print("Status:")
- print("Chest: "..currentContent.."/"..maxContent*64)
- percentage = (currentContent *100) / (maxContent*64)
- print("Chest is "..math.floor(percentage).."% full.")
- print("Threshold is: "..(fill*100).."%")
- signal = currentContent > ((maxContent*64)*fill)
- if signal then
- print("Above Threshold!")
- else
- print("Below Threshold.")
- end
- print("")
- print("Update Interval: "..updateDelay.."s")
- drawLine()
- end
- function main()
- while true do
- maxContent = chest.getInventorySize()
- currentContent = 0
- for i = 1,maxContent do
- data = chest.getStackInSlot(i)
- if data == nil then
- data = 0
- else
- currentContent = currentContent + data.qty
- end
- end
- display()
- rs.setOutput(signalSide,signal)
- sleep(updateDelay)
- end
- end
- setup()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement