Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local event = require("event")
- local component = require("component")
- local sides = require("sides")
- local gpu = component.gpu
- local rs = component.redstone
- local status = 0
- local colors = { blue = 0x4286F4, purple = 0xB673d6, red = 0xC14141, green = 0xDA841, black = 0x000000, white = 0xFFFFFF, grey = 0x47494C, lightGrey = 0xBBBBBB}
- -- * -----------------------------------------------------
- function turnOffLamps()
- rs.setOutput(sides.top, 0 )
- rs.setOutput(sides.north, 0 )
- rs.setOutput(sides.south, 0 )
- rs.setOutput(sides.west, 0 )
- rs.setOutput(sides.east, 0 )
- end
- function button(x, y, x2, y2, bColor, fColor, bText)
- gpu.setBackground(bColor)
- gpu.setForeground(fColor)
- gpu.fill(x, y, x2, y2, " ")
- gpu.set(x, y, bText)
- end
- function text(x, y, bColor, fColor, text)
- gpu.setBackground(bColor)
- gpu.setForeground(fColor)
- gpu.set(x, y, text)
- end
- function clearScr()
- gpu.setBackground(colors.black)
- gpu.setForeground(colors.white)
- gpu.fill(1, 1, 160, 50, " ")
- end
- function printCoords(x, y)
- gpu.set(1, 50, ("Debug -- Coords = x: " .. x .. " y: " .. y .. " "))
- end
- function flashStatus()
- if status == 0 then
- button(160, 50, 1, 1, colors.red, colors.black, " ")
- status = 1
- elseif status == 1 then
- button(160, 50, 1, 1, colors.green, colors.black, " ")
- status = 0
- end
- end
- -- ****************************************** --
- clearScr()
- gpu.setResolution(160, 50)
- tBc = colors.blue
- tFc = colors.white
- text(1,1, tBc, tFc, "Top lamp switch: ")
- text(1,3, tBc, tFc, "North lamp switch:")
- text(1,5, tBc, tFc, "South lamp switch:")
- text(1,7, tBc, tFc, "East lamp switch: ")
- text(1,9, tBc, tFc, "West lamp switch: ")
- text(1, 11, tBc, tFc, "Reset all lamps:")
- button(20, 1, 1, 1, colors.red, colors.black, " ")
- button(20, 3, 1, 1, colors.red, colors.black, " ")
- button(20, 5, 1, 1, colors.red, colors.black, " ")
- button(20, 7, 1, 1, colors.red, colors.black, " ")
- button(20, 9, 1, 1, colors.red, colors.black, " ")
- button(20, 11, 1, 1, colors.blue, colors.black, " ")
- while true do
- flashStatus()
- local id, _, x, y = event.pullMultiple("touch", "interrupted", "key_up")
- if id == "interrupted" then
- print("soft interrupt, closing")
- clearScr()
- turnOffLamps()
- break
- elseif id == "touch" then
- printCoords(x, y)
- if x == 20 and y == 1 then
- button(x, y, 1, 1, colors.green, colors.black, " ")
- rs.setOutput(sides.top, 1)
- elseif x == 20 and y == 3 then
- button(x, y, 1, 1, colors.green, colors.black, " ")
- rs.setOutput(sides.north, 1)
- elseif x == 20 and y == 5 then
- button(x, y, 1, 1, colors.green, colors.black, " ")
- rs.setOutput(sides.south, 1)
- elseif x == 20 and y == 7 then
- button(x, y, 1, 1, colors.green, colors.black, " ")
- rs.setOutput(sides.east, 1)
- elseif x == 20 and y == 9 then
- button(x, y, 1, 1, colors.green, colors.black, " ")
- rs.setOutput(sides.west, 1)
- elseif x == 20 and y == 11 then
- turnOffLamps()
- end
- elseif id == nil then
- --
- end
- button(160, 50, 1, 1, colors.red, colors.black, " ")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement