Advertisement
Guest User

pressurecontrol

a guest
Dec 22nd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. os.loadAPI("button")
  2. mon = peripheral.wrap("left")
  3. mon.clear()
  4. redstone.setOutput("right",false)
  5.  
  6. --Variables
  7.  
  8. local comp = peripheral.wrap("right")
  9. local danger = comp.getDangerPressure()
  10. local pressure = comp.getPressure()
  11.  
  12. --Functions
  13.  
  14. function fillTable()
  15.   button.setTable("ON",on,2,8,2,4)
  16.   button.setTable("OFF",off,11,17,2,4)
  17.   button.screen()
  18. end
  19.  
  20. function on()
  21.   if rdstnlvl == false then
  22.     button.toggleButton("ON")
  23.     redstone.setOutput("right",true)
  24.     button.toggleButton("OFF")
  25.     print("ON")
  26.   end
  27. end
  28.  
  29. function off()
  30.   if rdstnlvl == true then
  31.     button.toggleButton("OFF")
  32.     redstone.setOutput("right",false)
  33.     button.toggleButton("ON")
  34.     print("OFF")
  35.   end
  36. end
  37.  
  38. function getClick()
  39.   event,side,x,y = os.pullEvent("monitor_touch")
  40.   button.checkxy(x,y)
  41. end
  42.  
  43. function newLine()
  44.   local x,y = mon.getCursorPos()
  45.   mon.setCursorPos(1,y+1)
  46.   mon.clearLine()
  47. end
  48.  
  49. function getRedstoneLevel()
  50.   rdstnlvl = redstone.getOutput("right")
  51. end
  52.  
  53. function pressureReport()
  54.   mon.setCursorPos(1,7)
  55.   getPressureLevel()
  56.   mon.write(pressure)
  57.   newLine()
  58.   getRedstoneLevel()
  59.   mon.write(rdstnlvl)
  60. end
  61.  
  62. function getPressureLevel()
  63.   pressure = comp.getPressure()
  64. end
  65.  
  66. --Main
  67.  
  68. button.heading("Pressure Control")
  69. fillTable()
  70. button.toggleButton("OFF")
  71.  
  72. while true do
  73.   if pressure >= danger-0.5 then
  74.     off()
  75.     pressureReport()
  76.   else
  77.     on()
  78.     pressureReport()
  79.   end
  80.   sleep(5)
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement