local keypad={"top"}
local output="bottom"

local manymeta={
["__index"]=function (tab, key)

	return function(...)
		local ret
		local tArgs={...}
		for i,k in ipairs(tab) do
			if k[key] then ret={k[key](unpack(tArgs))} end
			if #ret>0 then break end
		end
		return unpack(ret)
	end

end,
["__call"]=function (tab, ...)
	local ret={}
	local tArgs={...}
	if #tArgs==0 then return end
	local key=table.remove(tArgs,1)
	for i,k in ipairs(tab) do
		if k[key] then ret[i]={k[key](unpack(tArgs))} end
	end
	return ret
end

}

local function wrapAll()
for i,k in ipairs(keypad) do
	keypad[i]= peripheral.wrap(k)
	if not keypad[i] then error("Wrong stand side "..tostring(k)) end
end
setmetatable(keypad,manymeta)
end
local function paint(A,B,C)
B.setBackgroundColor(A)
B.clear()
end

wrapAll()
print("Armory Doorlock Activated")

local locked=true
local event,timer
while true do
redstone.setOutput(output,not locked)
paint(locked and colors.red or colors.lime,keypad)
event={os.pullEvent()}
if event[1]=="timer" and event[2]==timer then locked=true
elseif event[1]=="monitor_touch" then locked=not locked if not locked then timer=os.startTimer(5) else timer=nil end
end
end
