Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("top")
- mon.setTextScale(1)
- mon.setTextColor(colors.white)
- local button={}
- local tmp_password = {""}
- local password = {""}
- mon.setBackgroundColor(colors.black)
- local x
- local y
- function setTable(name, value, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["value"] = value
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function clickButton(name)
- print("Click on: "..name)
- tmp_password[#tmp_password+1] = name
- fill(name, colors.lime, button[name])
- sleep(.1)
- fill(name, colors.red, button[name])
- print(#tmp_password)
- if (#tmp_password == 5) then
- print("COMPROBAMOS PASSWORD")
- checkPassword('checkPassword')
- end
- --saveAll()
- end
- function checkPassword(name)
- local tmp = ""
- for i = 1, y do
- if tmp_password[i] ~= nil then
- tmp = tmp .. tmp_password[i]
- end
- end
- if tmp == "5926" then
- writeTask("open_door")
- os.reboot()
- else
- os.reboot()
- end
- end
- function writeTask(task)
- fs.delete("tasks")
- local file = fs.open("tasks", "w")
- file.write(task)
- file.close()
- end
- function checkTasks()
- local file = fs.open("tasks", "r")
- local data = file.readAll()
- if (data == "open_door") then
- redstone.setOutput("bottom", true)
- sleep(5)
- redstone.setOutput("bottom", false)
- writeTask("_clear_")
- os.reboot()
- end
- end
- function fillTable()
- setTable("1", "1",clickButton, 1, 2, 1, 1)
- setTable("2", "2",clickButton, 3, 4, 1, 1)
- setTable("3", "3",clickButton, 5, 6, 1, 1)
- setTable("4", "4",clickButton, 1, 2, 3, 3)
- setTable("5", "5",clickButton, 3, 4, 3, 3)
- setTable("6", "6",clickButton, 5, 6, 3, 3)
- setTable("7", "7",clickButton, 1, 2, 5, 5)
- setTable("8", "8",clickButton, 3, 4, 5, 5)
- setTable("9", "9",clickButton, 5, 6, 5, 5)
- setTable("enviar", "enviar", checkPassword, 20, 30, 17, 19)
- 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 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)
- fill(name, colors.red, data)
- end
- end
- function checkxy(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["func"](name) -- llamamos a la funcion del boton pasandole el nombre
- data["active"] = not data["active"]
- end
- end
- end
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- -- MAIN PROGRAM
- x, y = mon.getSize()
- fillTable()
- checkTasks()
- while true do
- mon.clear()
- screen()
- local e,side,x,y = os.pullEvent("monitor_touch")
- print(x..":"..y)
- checkxy(x,y)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment