Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- buttons = {}
- function print()
- mon.clear()
- mon.setTextScale(1)
- mon.setCursorPos(22, 2)
- mon.write("Grinders")
- mon.setCursorPos(9, 5)
- mon.write("Left Grinder")
- mon.setCursorPos(30, 5)
- mon.write("Right Grinder")
- printbutton("leftLight")
- printbutton("rightLight")
- end
- function newbutton(name, text, func, xmin, xmax, ymin, ymax)
- buttons[name] = {}
- buttons[name]["text"] = text
- buttons[name]["func"] = func
- buttons[name]["xmin"] = xmin
- buttons[name]["xmax"] = xmax
- buttons[name]["ymin"] = ymin
- buttons[name]["ymax"] = ymax
- buttons[name]["active"] = true
- end
- function printbutton(name)
- if (buttons[name]["active"]) then
- mon.setBackgroundColor(colors.lime)
- else
- mon.setBackgroundColor(colors.red)
- end
- for i = buttons[name]["ymin"], buttons[name]["ymax"], 1 do
- mon.setCursorPos(buttons[name]["xmin"], i)
- for i = buttons[name]["xmin"], buttons[name]["xmax"], 1 do
- mon.write(" ")
- end
- end
- xstart = buttons[name]["xmin"] + 1 + math.floor((buttons[name]["xmax"] - buttons[name]["xmin"] - string.len(buttons[name]["text"])) / 2)
- ystart = buttons[name]["ymin"] + math.floor((buttons[name]["ymax"] - buttons[name]["ymin"]) / 2)
- mon.setCursorPos(xstart, ystart)
- mon.write(buttons[name]["text"])
- mon.setBackgroundColor(colors.black)
- end
- function getClick()
- event, side, x, y = os.pullEvent("monitor_touch")
- for name, data in pairs(buttons) do
- if y <= data["ymax"] and y >= data["ymin"] then
- if x <= data["xmax"] and y >= data["xmin"] then
- data["func"]()
- end
- end
- end
- print()
- end
- function lLight()
- buttons["leftLight"]["active"] = not buttons["leftLight"]["active"]
- end
- function rLight()
- buttons["rightLight"]["active"] = not buttons["rightLight"]["active"]
- end
- function update()
- if buttons["leftLight"]["active"] == true and buttons["rightLight"]["active"] == true then
- rs.setOutput("left", true)
- rs.setOutput("back", true)
- elseif buttons["leftLight"]["active"] == true and buttons["rightLight"]["active"] == false then
- rs.setOutput("back", true)
- rs.setOutput("left", false)
- elseif buttons["rightLight"]["active"] == true and buttons["leftLight"]["active"] == false then
- rs.setOutput("back", false)
- rs.setOutput("left", true)
- else
- rs.setOutput("left", false)
- rs.setOutput("back", false)
- end
- end
- buttons = {}
- newbutton("leftLight", "Light", lLight, 9, 21, 7, 9)
- newbutton("rightLight", "Light", rLight, 30, 42, 7, 9)
- while true do
- print()
- update()
- getClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement