Advertisement
Fooman

Liquid Level Monitor

May 15th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. --[[
  2. Liquid Level Monitor v1.0
  3. by Fooman
  4.  
  5. http://www.youtube.com/user/Foooman
  6.  
  7. Intended for use with Railcraft Steam Boilers not being fed by Aqueous Accumulators.
  8. ]]--
  9.  
  10. --Side of Computer with Nuclear Information Reader
  11. local nuclearReaderSide = "top"
  12. --Side of Computer with Howler Alarm
  13. local howlerAlarmSide = "back"
  14. --Time interval (seconds) between updates
  15. local updateInterval = 5
  16. --Amount of Liquid (amount/capacity) to trigger alarm
  17. local alarmTrigger = 0.5
  18.  
  19. local lCapacity
  20. local lAmount
  21.  
  22. nr = peripheral.wrap(nuclearReaderSide)
  23.  
  24. function getLiquid()
  25.     local a,b,c, info = nr.get(1)
  26.     --Error on bad sensor kit
  27.     if b ~= "OK" then error("bad sensor kit: "..b) end
  28.     for system, status in pairs(info) do
  29.         status = tostring(status)
  30.         if system == "capacity" then
  31.             lCapacity = status
  32.         elseif system == "amount" then
  33.             lAmount = status
  34.             print(status)
  35.         end
  36.     end
  37. end
  38.  
  39. function alarmTrig()
  40.     if (lAmount/lCapacity) <= alarmTrigger then
  41.         rs.setOutput(howlerAlarmSide, true)
  42.     else
  43.         rs.setOutput(howlerAlarmSide, false)
  44.     end
  45. end
  46.  
  47.  
  48.  
  49.  
  50. --Operation
  51. term.clear()
  52. local updateTimer = os.startTimer(0.05)
  53.  
  54. while true do
  55.     event, param1, param2, param3 = os.pullEvent()
  56.     if event == "timer" then
  57.         getLiquid()
  58.         alarmTrig()
  59.         updateTimer = os.startTimer(updateInterval)
  60.     end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement