Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Valve, Monitor & Wireless Modem
- local nir = peripheral.wrap("right")
- local mon = peripheral.wrap("top")
- local wmod = peripheral.wrap("back")
- local warning = 25 -- Warning level in %
- local cap -- Tank capacity
- local amount -- Amount liquid in tank
- local percentFull -- Percent liquid in tank
- local lastPercent = 1000 -- Percent last loop
- local sendMsg -- Message to send
- local sleepTime -- How long to sleep
- local sendFreq -- Modem Tx Frequency
- local content = liquidType -- What is in tank?
- -- Make sure frequency match the main computer
- -- grab data values
- a,b,c,data = nir.get(1)
- if data["liquidId"] == 11
- then
- liquidType = "Lava"
- sendFreq = "3"
- elseif data["liquidId"] == 255
- then
- liquidType = "Oil"
- sendFreq = "4"
- elseif data["liquidId"] == 4064
- then
- liquidType = "Fuel"
- sendFreq = "5"
- else
- liquidType = "Unknown"
- sendFreq = "6"
- end
- -- Set warning lamp to off
- redstone.setOutput("left", false)
- -- Main prog loop, never stop
- while true do
- mon.clear()
- mon.setCursorPos(1,1)
- -- Get values for tank capacity and amount
- cap = data["capacity"]
- amount = data["amount"]
- -- If tank is empty, to avoid math issues with 0
- if amount == nil then
- amount = 0
- percentFull = 0
- else
- -- Use math.floor to convert to integers
- percentFull = math.floor(100 * amount / cap)
- end
- -- Self explanatory :)
- mon.write(content)
- mon.setCursorPos(1,2)
- mon.write("Amount: " ..amount .."/"..cap .." mB.")
- mon.setCursorPos(1,3)
- mon.write("Amount: " ..percentFull .."% ")
- -- Check for change since last loop
- if percentFull == lastPercent then
- print("Still " ..percentfull .. "%, nothing sent.")
- else
- -- If value changed, send to main!
- sendmsg = content ..": " ..percentFull .." %"
- wmod.transmit(sendFreq,"0",sendmsg)
- print("Sent: " ..sendmsg)
- end
- -- Save for next loop
- lastPercent = percentFull
- -- Warning control, local lamp
- mon.setCursorPos(1,5)
- if percentFull < warning then
- redstone.setOutput("left", true)
- mon.write("Less than " ..warning .."% full")
- sleep(1)
- redstone.setOutput("left", false)
- sleeptime = 1
- else
- -- Above warning level, sleep longer
- mon.write("More than " ..warning .."% full")
- sleeptime = 5
- end
- -- Sleep either 1 or 10 seconds
- sleep(sleeptime)
- end
Advertisement
Add Comment
Please, Sign In to add comment