BHTAelitepwn

button

Apr 1st, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. monitor=peripheral.wrap("front")
  2. mouseWidth = 0
  3. mouseHeight = 0
  4.  
  5. function prepare()
  6.   monitor.clear()
  7.   monitor.setBackgroundColor((colors.black))
  8.   monitor.setCursorPos(1,1)
  9.   monitor.setTextColor((colors.white))
  10.   monitor.write("water")
  11.   monitor.setCursorPos(1,2)
  12.   monitor.write("cooling")
  13. end
  14.  
  15. function on()
  16.   prepare()
  17.   monitor.setCursorPos(2,4)
  18.   monitor.setBackgroundColor((colors.green))
  19.   monitor.write("  on   ")
  20. end
  21.  
  22. function off()
  23.   prepare()
  24.   monitor.setCursorPos(2,4)
  25.   monitor.setBackgroundColor((colors.red))
  26.   monitor.write("  off  ")  
  27. end
  28.  
  29. function ClickOn()
  30.   if mouseWidth > 1 and mouseWidth < 9 and mouseHeight == 4 then
  31.     rs.setOutput("back", false)
  32.   end
  33. end
  34.  
  35. function ClickOff()
  36.   if mouseWidth > 1 and mouseWidth < 9 and mouseHeight == 4 then
  37.     rs.setOutput("back", true)
  38.   end
  39. end
  40.  
  41. function checkOff()
  42.   event,p1,p2,p3 = os.pullEvent()
  43.     if event == "monitor_touch" then
  44.       mouseWidth = p2
  45.       mouseHeight = p3
  46.       ClickOff()
  47.       return "aan"
  48.     end
  49. end
  50.  
  51. function checkOn()
  52.   event,p1,p2,p3 = os.pullEvent()
  53.     if event == "monitor_touch" then
  54.       mouseWidth = p2
  55.       mouseHeight = p3
  56.       ClickOn()
  57.       return "aan"
  58.     end
  59. end
  60.  
  61. while true do
  62.    prepare()
  63.    off()
  64.   repeat
  65.     checkOff()
  66.   until
  67.     checkOff() == "aan"
  68.  
  69.   prepare()
  70.   on()
  71.   repeat
  72.         checkOn()
  73.   until
  74.         checkOn() == "aan"        
  75. end
Advertisement
Add Comment
Please, Sign In to add comment