Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Firebox, Wireless Modem
- local fireb = peripheral.wrap("top")
- local mon = peripheral.wrap("front")
- local wmod = peripheral.wrap("bottom")
- local tankName = "Boiler 01" -- Name of the tank
- local warning = 20 -- Warning level in %
- local wcap -- Water Tank capacity
- local scap -- Steam Tank capacity
- local fcap -- Fuel Tank capacity
- local wamount -- Amount liquid in tank
- local samount -- Amount liquid in tank
- local famount -- Amount liquid in tank
- local wpercentfull -- Percent liquid in tank
- local spercentfull -- Percent liquid in tank
- local fpercentfull -- Percent liquid in tank
- local wlastpercent = 1000 -- Percent last loop
- local slastpercent = 1000 -- Percent last loop
- local flastpercent = 1000 -- Percent last loop
- local sendmsg -- Message to send
- local sleeptime -- How long to sleep
- local wsendFreq = 10 -- Modem Frequency
- local ssendFreq = 11 -- Modem Frequency
- local fsendFreq = 12 -- Modem Frequency
- -- Make sure the frequency matches the main computer
- -- Main loop
- while true do
- mon.clear()
- mon.setCursorPos(1,1)
- -- Fill table with data from tank valve
- tanksTable = fireb.getTanks("WhatIsThis")
- watertank = tanksTable[1]
- steamtank = tanksTable[2]
- fueltank = tanksTable[3]
- -- Water
- -- Get values for tank capacity and amount
- wcap = watertank.capacity / 1000 -- in buckets
- wamount = watertank.amount -- in millibuckets
- scap = steamtank.capacity / 1000 -- in buckets
- samount = steamtank.amount -- in millibuckets
- fcap = fueltank.capacity / 1000 -- in buckets
- famount = fueltank.amount -- in millibuckets
- -- If Water tank is empty, to avoid math issues with 0
- if wamount == nil then
- wamount = 0
- wpercentfull = 0
- else
- -- Use math.floor to convert to integers
- wamount = math.floor(wamount / 1000)
- wpercentfull = math.floor(100 * wamount / wcap)
- end
- -- Self explanatory :)
- mon.write(watertank.name)
- mon.setCursorPos(1,2)
- mon.write("Amount: " ..wamount .."/"..wcap .." B.")
- mon.setCursorPos(1,3)
- mon.write("Amount: " ..wpercentfull .."% ")
- -- Check for change since last loop
- if wpercentfull == wlastpercent then
- print("Still " ..wpercentfull .. "%, nothing sent.")
- else
- -- If value changed, send to main!
- wsendmsg = [[tankName
- watertank.name ..": " ..wpercentfull .." %"
- wmod.transmit(wsendFreq,0,wsendmsg)
- print("Sent: " ..wsendmsg)
- end
- -- Save for next loop
- wlastpercent = wpercentfull
- -- Steam
- -- If steam tank is empty, to avoid math issues with 0
- if samount == nil then
- samount = 0
- spercentfull = 0
- else
- -- Use math.floor to convert to integers
- samount = math.floor(samount / 1000)
- spercentfull = math.floor(100 * samount / scap)
- end
- -- Self explanatory :)
- mon.setCursorPos(1,4)
- mon.write(steamtank.name)
- mon.setCursorPos(1,5)
- mon.write("Amount: " ..samount .."/"..scap .." B.")
- mon.setCursorPos(1,6)
- mon.write("Amount: " ..spercentfull .."% ")
- -- Check for change since last loop
- if spercentfull == slastpercent then
- print("Still " ..spercentfull .. "%, nothing sent.")
- else
- -- If value changed, send to main!
- sendmsg = steamtank.name ..": " ..spercentfull .." %"
- wmod.transmit(ssendFreq,0,sendmsg)
- print("Sent: " ..sendmsg)
- end
- -- Save for next loop
- slastpercent = spercentfull
- -- Fuel
- -- If fuel tank is empty, to avoid math issues with 0
- if famount == nil then
- famount = 0
- fpercentfull = 0
- else
- -- Use math.floor to convert to integers
- famount = math.floor(famount / 1000)
- fpercentfull = math.floor(100 * famount / fcap)
- end
- -- Self explanatory :)
- mon.setCursorPos(1,7)
- mon.write(fueltank.name)
- mon.setCursorPos(1,8)
- mon.write("Amount: " ..famount .."/"..fcap .." B.")
- mon.setCursorPos(1,9)
- mon.write("Amount: " ..fpercentfull .."% ")
- -- Check for change since last loop
- if fpercentfull == flastpercent then
- print("Still " ..fpercentfull .. "%, nothing sent.")
- else
- -- If value changed, send to main!
- sendmsg = fueltank.name ..": " ..fpercentfull .." %"
- wmod.transmit(fsendFreq,0,sendmsg)
- print("Sent: " ..sendmsg)
- end
- -- Save for next loop
- flastpercent = fpercentfull
- -- Warning control, local lamp
- mon.setCursorPos(1,10)
- if wpercentfull < warning then
- redstone.setOutput("right", true)
- mon.write("Less than " ..warning .."% full")
- sleep(1)
- redstone.setOutput("right", false)
- sleeptime = 1
- else
- -- Above warning level, sleep longer
- mon.write("More than " ..warning .."% full")
- sleeptime = 10
- end
- -- Sleep either 1 or 10 seconds
- sleep(sleeptime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement