Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Valve, Monitor & Wireless Modem
- local val = peripheral.wrap("back")
- local mon = peripheral.wrap("top")
- local wmod = peripheral.wrap("bottom")
- local warning = 20 -- 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 = 1 -- Modem Frequency
- local warnFreq = 2 -- Modem Frequency
- local content = "Water[1]" -- What is in tank?
- local WarningLast = false
- -- Make sure frequency match the main computer
- -- Set warning lamp to off
- -- Main prog loop, never stop
- while true do
- --mon.clear()
- --mon.setCursorPos(1,1)
- -- Fill table with data from tank valve
- tanksTable = val.getTankInfo("unknown")
- maintank = tanksTable[1]
- -- Get values for tank capacity and amount
- cap = maintank.capacity / 1000 -- in buckets
- amount = maintank.amount -- in millibuckets
- -- 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
- amount = math.floor(amount / 1000)
- percentfull = math.floor(100 * amount / cap)
- end
- --mon.write(content)
- --mon.setCursorPos(1,2)
- --mon.write("Amount: " ..amount .."/"..cap .." B.")
- --mon.setCursorPos(1,3)
- --mon.write("Amount: " ..percentfull .."% ")
- -- Check for change since last loop
- if percentfull == lastpercent and percentfull > warning then
- print("Still " ..percentfull .. "%, nothing sent.")
- else
- sendmsg = content ..": " ..percentfull .."%"
- if percentfull < warning then
- if WarningLast == false then
- WarningLast = true
- sendmsg = sendmsg .. " [WARNING]"
- else
- WarningLast = false
- end
- wmod.transmit(warnFreq,0,sendmsg)
- else
- wmod.transmit(sendFreq,0,sendmsg)
- end
- print("Sent: " ..sendmsg)
- end
- -- Save for next loop
- lastpercent = percentfull
- sleeptime = 1
- -- Sleep either 1 or 10 seconds
- sleep(sleeptime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement