Advertisement
thatparadox

4 button RS touchscreen

Jan 17th, 2015
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. mon = peripheral.find("monitor")
  2.  
  3. a = false
  4. b = false
  5. c = false
  6. d = false
  7.  
  8. function drawButtons()
  9. x,y = mon.getSize()
  10. mon.clear()
  11. mon.setTextColor(colors.black)
  12. if a == true then
  13.    mon.setBackgroundColor(colors.white)
  14. else
  15.    mon.setBackgroundColor(colors.gray)
  16. end
  17. for yc = 1, y/2+1 do
  18.     for xc = 1, x/2+1 do
  19.         mon.setCursorPos(xc,yc)
  20.         mon.write(" ")
  21.     end
  22. end
  23. mon.setCursorPos(x/4+1, y/4)
  24. mon.write("1")
  25. if b == true then
  26.    mon.setBackgroundColor(colors.white)
  27. else
  28.    mon.setBackgroundColor(colors.gray)
  29. end
  30. for yc = 1, y/2+1 do
  31.     for xc = x/2+1, x do
  32.         mon.setCursorPos(xc,yc)
  33.         mon.write(" ")
  34.     end
  35. end
  36. mon.setCursorPos(x/4*3+1, y/4)
  37. mon.write("2")
  38. if c == true then
  39.    mon.setBackgroundColor(colors.white)
  40. else
  41.    mon.setBackgroundColor(colors.gray)
  42. end
  43. for yc = y/2+1, y do
  44.     for xc = 1, x/2+1 do
  45.         mon.setCursorPos(xc,yc)
  46.         mon.write(" ")
  47.     end
  48. end
  49. mon.setCursorPos(x/4+1, y/4*3)
  50. mon.write("3")
  51. if d == true then
  52.    mon.setBackgroundColor(colors.white)
  53. else
  54.    mon.setBackgroundColor(colors.gray)
  55. end
  56. for yc = y/2+1, y do
  57.     for xc = x/2+1, x do
  58.         mon.setCursorPos(xc,yc)
  59.         mon.write(" ")
  60.     end
  61. end
  62. mon.setCursorPos(x/4*3+1, y/4*3)
  63. mon.write("4")
  64. end
  65.  
  66.  
  67. while true do
  68.     drawButtons()
  69.     event, param1, param2, param3 = os.pullEvent("monitor_touch")
  70.     if param2 < x/2 and param3 < y/2 then
  71.         if a == false then
  72.             rs.setOutput("front", true)
  73.             a = true
  74.         else
  75.             rs.setOutput("front", false)
  76.             a = false
  77.         end
  78.     elseif param2 > x/2 and param3 < y/2 then
  79.         if b == false then
  80.             rs.setOutput("right", true)
  81.             b = true
  82.         else
  83.             rs.setOutput("right", false)
  84.             b = false
  85.         end
  86.     elseif param2 < x/2 and param3 > y/2 then
  87.         if c == false then
  88.             rs.setOutput("back", true)
  89.             c = true
  90.         else
  91.             rs.setOutput("back", false)
  92.             c = false
  93.         end
  94.     elseif param2 > x/2 and param3 > y/2 then
  95.         if d == false then
  96.             rs.setOutput("left", true)
  97.             d = true
  98.         else
  99.             rs.setOutput("left", false)
  100.             d = false
  101.         end
  102.     end
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement