Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Liquid Level Monitor v1.1
- by Fooman
- http://www.youtube.com/user/Foooman
- ]]--
- --Side of Computer with Nuclear Information Reader
- local nuclearReaderSide = "right"
- --Side of Computer with Howler Alarm
- local howlerAlarmSide = "back"
- --Side of Computer with Monitor
- local monitorSide = "left"
- --Time interval (seconds) between updates
- local updateInterval = 5
- --Amount of Liquid (amount/capacity) to trigger alarm
- local alarmTrigger = 0.25
- --Number of Tanks to monitor
- local tankQuantity = 1
- local nonKitable = 18000
- local lCapacity
- local lAmount
- nr = peripheral.wrap(nuclearReaderSide)
- m = peripheral.wrap(monitorSide)
- m.setTextScale(0.5)
- local wm,hm = m.getSize()
- local function monitorCentered(str,ypos)
- m.setCursorPos(wm/2 - #str/2 + 1, ypos)
- m.write(str)
- end
- local function monitorLeft(str,ypos)
- m.setCursorPos(1 , ypos)
- m.write(str)
- end
- function getLiquid()
- --Reset Counter to nonKitable base value
- lAmount = 0
- lCapacity = nonKitable
- for i = 1,tankQuantity do
- --get Counter for all BC Tanks
- local a,b,c, info = nr.get(i)
- --Error on bad sensor kit
- if b ~= "OK" then error("bad sensor kit: "..b) end
- for system, status in pairs(info) do
- status = tostring(status)
- if system == "capacity" then
- lCapacity = lCapacity + status
- elseif system == "amount" then
- lAmount = lAmount + status
- end
- end
- end
- --Add nonKitable to Amount if nonzero
- if lAmount > 0 then
- lAmount = lAmount + nonKitable
- end
- end
- function alarmTrig()
- if (lAmount/lCapacity) <= alarmTrigger then
- rs.setOutput(howlerAlarmSide, true)
- else
- rs.setOutput(howlerAlarmSide, false)
- end
- end
- function updateMonitor()
- m.clear()
- monitorCentered("Fuel Amount",2)
- monitorCentered(tostring(lAmount).." mB", 7)
- end
- --Operation
- term.clear()
- local updateTimer = os.startTimer(0.05)
- while true do
- event, param1, param2, param3 = os.pullEvent()
- if event == "timer" then
- getLiquid()
- alarmTrig()
- updateMonitor()
- updateTimer = os.startTimer(updateInterval)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement