Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin code: GzeD85fR
- rednet.open("left")
- local mon = peripheral.wrap("top")
- local mX, mY = mon.getSize()
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- local button={}
- mon.setBackgroundColor(colors.black)
- function CreateButton(name, func, minX, minY, maxX, maxY)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = minX
- button[name]["ymin"] = minY
- button[name]["xmax"] = maxX
- button[name]["ymax"] = maxY
- end
- function SetUpButtons()
- CreateButton("Lockdown", LockDown, 2, 3, 20, 5)
- CreateButton("Main Door", CloseMain, 2, 7, 20, 9)
- CreateButton("Alarm", Alarm, mX - 21, 3, mX - 1, 5)
- end
- function Alarm()
- for funcName, funcData in pairs(button) do
- if funcName == "Alarm" then
- if funcData["active"] ~= true then
- rs.setOutput("back", false)
- print("Alarm off")
- else
- rs.setOutput("back", true)
- print("Alarm on")
- end
- end
- end
- end
- function Title(text)
- mon.setCursorPos((mX - string.len(text)) / 2 + 1, 1)
- mon.write(text)
- end
- function Screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then
- currColor = colors.lime
- else currColor = colors.red
- end
- fill(name, currColor, data)
- end
- end
- function checkxy(x, y)
- local activeFunc = "none"
- print(x.." "..y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["active"] = not data["active"]
- activeFunc = name
- print(name)
- end
- end
- end
- if (activeFunc ~= "none") then
- button[activeFunc]["func"]()
- end
- end
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function CloseMain()
- for funcName, funcData in pairs(button) do
- local on = funcData["active"]
- if funcName == "Main Door" then
- if on ~= true then
- rednet.send(35, "open")
- else
- rednet.send(35, "close")
- end
- end
- end
- return true
- end
- function LockDown()
- for name2,data2 in pairs(button) do
- local on = data2["active"]
- if name2 == "Lockdown" then
- if on ~= true then
- print("OPEN")
- rs.setOutput("back", false)
- rednet.send(35, "open")
- rednet.send(36, "open")
- rednet.send(30, "open")
- rednet.send(37, "open")
- rednet.send(38, "open")
- rednet.send(39, "open")
- rednet.send(40, "open")
- rednet.send(41, "open")
- rednet.send(42, "open")
- button["Alarm"]["active"] = false
- else
- print("CLOSE")
- rs.setOutput("back", true)
- rednet.send(35, "close")
- rednet.send(36, "close")
- rednet.send(30, "close")
- rednet.send(37, "close")
- rednet.send(38, "close")
- rednet.send(39, "close")
- rednet.send(40, "close")
- rednet.send(41, "close")
- rednet.send(42, "close")
- button["Alarm"]["active"] = true
- end
- end
- end
- return true
- end
- SetUpButtons()
- while true do
- mon.clear()
- Title("Security Control")
- Screen()
- local event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- checkxy(x, y)
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement