Posted 23 March 2013 - 11:27 PM
Hi all so I have got my touch screen to the point where it can turn the background text from red to green when i click on it however what I need to do next is toggle an bundled cable off and on with 6 seprate outputs. The bundled cable need to start sending a redstone single to all of 6 output and then be able to turn off each indivually so when for example the creeper button is red i will send rs.setBundledCable ("left'',color.blue) but then when I click the creeper button and it turns green it will turn it off.
pastebin code c41bsCPd
local mon = peripheral.wrap("left")
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("Wither" , funcName, 2, 9, 4, 6)
setTable("Creeper", funcName, 11, 19, 4, 6)
setTable("Zombie", funcName, 21, 28, 4, 6)
setTable("Spider", funcName, 2, 9, 8, 10)
setTable("1", funcName, 11, 19, 8, 10)
setTable("2", funcName, 21, 28, 8, 10)
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)
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()
while true do
mon.clear()
heading("MOB SPAWNER")
screen()
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
sleep(.1)
end
pastebin code c41bsCPd