Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Valve, Monitor & Wireless Modem
- local tank = peripheral.wrap("back")
- local mon = peripheral.wrap("top")
- local wmod = peripheral.wrap("bottom")
- -- Make sure channel/frequency match main computer
- local sendFreq = 2 -- Modem "Frequency"
- local warning = 30 -- Warning level in %
- local cap -- Tank capacity
- local amount -- Amount liquid in tank
- local percentfull -- Percent liquid in tank
- local sleeptime -- How long to sleep
- local sendpercent -- Formatted percentage string
- monX,monY = mon.getSize()
- -- Set warning lamp to off
- redstone.setOutput("right", false)
- function getTank(tank)
- local output = tank.getTanks() -- Local to the getTank function.
- fluidName = output[1]["displayName"]
- fluidAmount = output[1]["amount"]
- fluidCapacity = output[1]["capacity"]
- return fluidName, fluidAmount, fluidCapacity -- Returning the values of global variables (which are nil).
- end
- -- Main prog loop, never stop
- while true do
- wmod.open(2)
- mon.clear()
- mon.setCursorPos(1,1)
- -- Fill table with data from tank valve
- local fluidName, fluidAmount, fluidCapacity = getTank(tank)
- if fluidName then
- -- Get values for tank capacity and amount
- cap = fluidCapacity / 1000
- am = fluidAmount
- -- If tank is empty, to avoid math issues with 0
- if am == nil then
- am = 0
- percentfull = 0
- else
- -- Use math.floor to convert to integers
- am = math.floor(am / 1000)
- percentfull = math.floor(100 * am / cap)
- end
- -- Self explanatory :)
- mon.write("Fluid :" ..fluidName)
- mon.setCursorPos(1,2)
- mon.write("Amount: " ..am .."/"..cap .." B.")
- mon.setCursorPos(1,3)
- mon.write("Percent: " ..percentfull .."% ")
- --Transmition Zone
- tankw = {water = percentfull}
- wmod.transmit(2,2,tankw)
- print("Current Percent :"..tankw["water"])
- --Warning Zone
- mon.setCursorPos(1,4)
- if percentfull < warning then
- redstone.setOutput("right", true)
- mon.write("Less than " ..warning .."% full")
- sleeptime = 1
- else
- -- Above warning level, sleep longer
- mon.write("More than " ..warning .."% full")
- redstone.setOutput("right", false)
- sleeptime = 10
- end
- else
- -- If no liquid is found in tank..
- mon.write("No liquid in tank")
- percentfull = 0
- term.clear()
- term.setCursorPos(1,1)
- print("No liquid in tank")
- sleeptime = 10
- percentfull = 0
- tankw = {water = percentfull}
- wmod.transmit(2,2,tankw)
- print("Current Percent :"..tankw["water"])
- end
- -- Sleep either 1 or 10 seconds
- sleep(sleeptime)
- end
Add Comment
Please, Sign In to add comment