function resetCode()
one = false
two = false
three = false
four = false
five = false
six = false
seven = false
eight = false
nine = false
end
resetCode()
--------------------------------------------
local mon = peripheral.wrap("right")
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
mon.setBackgroundColor(colors.black)
function setTable(name, func, xmin, xmax, ymin, ymax)
button[name] = {}
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 funcName()
print("You clicked buttonText")
end
function fillTable()
setTable("1", password1, 1, 1, 1, 1)
setTable("2", password2, 3, 3, 1, 1)
setTable("3", password3, 5, 5, 1, 1)
setTable("4", password4, 1, 1, 3, 3)
setTable("5", password5, 3, 3, 3, 3)
setTable("6", password6, 5, 5, 3, 3)
setTable("7", password7, 1, 1, 5, 5)
setTable("8", password8, 3, 3, 5, 5)
setTable("9", password9, 5, 5, 5, 5)
setTable("*", passwordValid, 7, 7, 5, 5)
setTable("C", resetCode, 7, 7, 1, 1)
-- setTable("OtherButton is COOL!", funcName, 5, 35, 10, 12)
end
function password1()
one = true
print("ping")
end
function password2()
two = true
print("ping")
end
function password3()
three = true
print("ping")
end
function password4()
four = true
print("ping4")
end
function password5()
five = true
print("ping5")
end
function password6()
six = true
end
function password7()
seven = true
end
function password8()
eight = true
end
function password9()
nine = true
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
currColor = colors.red
else currColor = colors.red
end
fill(name, currColor, 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"]()
data["active"] = not data["active"]
print(name)
end
end
end
end
function heading(text)
w, h = mon.getSize()
mon.setCursorPos((w-string.len(text))/2+1, 1)
mon.write(text)
end
fillTable()
function passwordValid()
if one == true then
print("test")
end
if one == true and two == true and three == true and four == true then
print("password accepted")
end
one = false
two = false
three = false
four = false
five = false
six = false
seven = false
eight = false
nine = false
print("code reset")
end
passwordValid()
print("PINGALING")
while true do
mon.clear()
heading(" ")
screen()
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
sleep(.1)
end