Advertisement
Guest User

test2.lua

a guest
Feb 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. local event = require("event")
  2. local component = require("component")
  3. local sides = require("sides")
  4. local gpu = component.gpu
  5. local rs = component.redstone
  6. local status = 0
  7. local colors = { blue = 0x4286F4, purple = 0xB673d6, red = 0xC14141, green = 0xDA841, black = 0x000000, white = 0xFFFFFF, grey = 0x47494C, lightGrey = 0xBBBBBB}
  8.  
  9. -- * -----------------------------------------------------
  10. function turnOffLamps()
  11.   rs.setOutput(sides.top, 0 )
  12.   rs.setOutput(sides.north, 0 )
  13.   rs.setOutput(sides.south, 0 )
  14.   rs.setOutput(sides.west, 0 )
  15.   rs.setOutput(sides.east, 0 )
  16. end
  17.  
  18. function button(x, y, x2, y2, bColor, fColor, bText)
  19.   gpu.setBackground(bColor)
  20.   gpu.setForeground(fColor)
  21.   gpu.fill(x, y, x2, y2, " ")
  22.   gpu.set(x, y, bText)
  23. end
  24.  
  25. function text(x, y, bColor, fColor, text)
  26.   gpu.setBackground(bColor)
  27.   gpu.setForeground(fColor)
  28.   gpu.set(x, y, text)
  29. end
  30.  
  31. function clearScr()
  32.   gpu.setBackground(colors.black)
  33.   gpu.setForeground(colors.white)
  34.   gpu.fill(1, 1, 160, 50, " ")
  35. end
  36.  
  37. function printCoords(x, y)
  38.   gpu.set(1, 50, ("Debug -- Coords = x: " .. x .. " y: " .. y .. " "))
  39. end
  40.  
  41. function flashStatus()
  42.   if status == 0 then
  43.     button(160, 50, 1, 1, colors.red, colors.black, " ")
  44.     status = 1
  45.   elseif status == 1 then
  46.     button(160, 50, 1, 1, colors.green, colors.black, " ")
  47.     status = 0
  48.   end
  49. end
  50.  
  51. -- ****************************************** --
  52.  
  53. clearScr()
  54. gpu.setResolution(160, 50)
  55.  
  56. tBc = colors.blue
  57. tFc = colors.white
  58. text(1,1, tBc, tFc, "Top lamp switch:  ")
  59. text(1,3, tBc, tFc, "North lamp switch:")
  60. text(1,5, tBc, tFc, "South lamp switch:")
  61. text(1,7, tBc, tFc, "East lamp switch: ")
  62. text(1,9, tBc, tFc, "West lamp switch: ")
  63. text(1, 11, tBc, tFc, "Reset all lamps:")
  64.  
  65. button(20, 1, 1, 1, colors.red, colors.black, " ")
  66. button(20, 3, 1, 1, colors.red, colors.black, " ")
  67. button(20, 5, 1, 1, colors.red, colors.black, " ")
  68. button(20, 7, 1, 1, colors.red, colors.black, " ")
  69. button(20, 9, 1, 1, colors.red, colors.black, " ")
  70.  
  71. button(20, 11, 1, 1, colors.blue, colors.black, " ")
  72.  
  73. while true do
  74.   flashStatus()
  75.   local id, _, x, y = event.pullMultiple("touch", "interrupted", "key_up")
  76.   if id == "interrupted" then
  77.     print("soft interrupt, closing")
  78.     clearScr()
  79.     turnOffLamps()
  80.     break
  81.  
  82.   elseif id == "touch" then
  83.     printCoords(x, y)
  84.     if x == 20 and y == 1 then
  85.       button(x, y, 1, 1, colors.green, colors.black, " ")
  86.       rs.setOutput(sides.top, 1)    
  87.     elseif x == 20 and y == 3 then
  88.       button(x, y, 1, 1, colors.green, colors.black, " ")
  89.       rs.setOutput(sides.north, 1)
  90.     elseif x == 20 and y == 5 then
  91.       button(x, y, 1, 1, colors.green, colors.black, " ")
  92.       rs.setOutput(sides.south, 1)
  93.     elseif x == 20 and y == 7 then
  94.       button(x, y, 1, 1, colors.green, colors.black, " ")
  95.       rs.setOutput(sides.east, 1)
  96.     elseif x == 20 and y == 9 then
  97.       button(x, y, 1, 1, colors.green, colors.black, " ")
  98.       rs.setOutput(sides.west, 1)
  99.     elseif x == 20 and y == 11 then
  100.       turnOffLamps()
  101.     end    
  102.   elseif id == nil then
  103.   --
  104.   end
  105.   button(160, 50, 1, 1, colors.red, colors.black, " ")
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement