Advertisement
MajorVictory

Volcano Pump Display

May 24th, 2013
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1.  
  2. -- Monitor must be to the right
  3. -- Requires 1x2 Monitor for correct display
  4. local out = peripheral.wrap("right")
  5.  
  6. local running = true
  7. local firstrun = true
  8. local isPumping = false
  9.  
  10. while running do
  11.  
  12.     if not firstrun then
  13.         os.pullEvent("redstone")
  14.     else
  15.         firstrun = false
  16.     end
  17.  
  18.     if rs.getInput("right") then
  19.         out.clear()
  20.         out.setCursorPos(1,1)
  21.         out.write("RESTARTING")
  22.         sleep(2)
  23.         os.reboot()
  24.     end
  25.  
  26.     out.clear()
  27.     out.setCursorPos(1,1)
  28.     out.write("~~ Pump Status ~~")
  29.  
  30.     -- redstone "sensors" input to specific sides
  31.  
  32.     -- redstone signal indicating pump is turned of by user
  33.     local pumpEnabled = rs.getInput("back")
  34.  
  35.     -- redstone signal indicating reserve tank is full (at ~95% capacity)
  36.     local tankFull = rs.getInput("bottom")
  37.  
  38.     -- redstone signal indicating reserve tank is empty
  39.     local tankEmpty = rs.getInput("front")
  40.  
  41.     -- ~~ Pump Shutoff System ~~
  42.     -- pump shuts off when tank is full (~95%)
  43.     -- pump starts when tank is empty
  44.  
  45.     if tankFull and isPumping then
  46.         isPumping = false
  47.     end
  48.  
  49.     if tankEmpty and not isPumping then
  50.         if pumpEnabled then
  51.             isPumping = true
  52.         end
  53.     end
  54.  
  55.     rs.setOutput("top", isPumping)
  56.  
  57.     out.setCursorPos(1,2)
  58.  
  59.     if pumpEnabled then
  60.         out.setBackgroundColor(colors.lime)
  61.         out.setTextColor(colors.black)
  62.         out.write("Pump Online       ")
  63.     else
  64.         out.setBackgroundColor(colors.red)
  65.         out.setTextColor(colors.white)
  66.         out.write("Pump Offline      ")
  67.     end
  68.  
  69.     out.setBackgroundColor(colors.black)
  70.     out.setTextColor(colors.white)
  71.  
  72.     out.setCursorPos(1,3)
  73.  
  74.     if tankFull and not tankEmpty then
  75.         out.setBackgroundColor(colors.lime)
  76.         out.setTextColor(colors.black)
  77.         out.write("Tank Full         ")
  78.     elseif not tankFull and not tankEmpty then
  79.         out.setBackgroundColor(colors.yellow)
  80.         out.setTextColor(colors.black)
  81.         if isPumping then
  82.             out.write("Tank Filling      ")
  83.         else
  84.             out.write("Tank Draining     ")
  85.         end
  86.     elseif not tankFull and tankEmpty then
  87.         out.setBackgroundColor(colors.red)
  88.         out.setTextColor(colors.white)
  89.         out.write("Tank Empty        ")
  90.     end
  91.  
  92.     out.setCursorPos(1,4)
  93.  
  94.     if isPumping then
  95.         out.setBackgroundColor(colors.lime)
  96.         out.setTextColor(colors.black)
  97.         out.write("   - PUMPING -    ")
  98.     else
  99.         out.setBackgroundColor(colors.yellow)
  100.         out.setTextColor(colors.black)
  101.         out.write("  - PUMP  IDLE -  ")
  102.     end
  103.  
  104.     out.setBackgroundColor(colors.black)
  105.     out.setTextColor(colors.white)
  106.  
  107.     sleep(1)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement