Posted 10 January 2015 - 05:56 PM
Hello all been working the last couple weeks on this project and just got it done. here is the program for use with Steves factory manager that actually does all the work i will be including a link to a video of how it works and is set up in the future.
monitor size currently used on this project is 39,26
[attachment=2039:2015-01-10_12.54.23.png][attachment=2040:2015-01-10_12.54.34.png][attachment=2041:2015-01-10_12.54.44.png][attachment=2042:2015-01-10_12.54.55.png][attachment=2043:2015-01-10_12.55.04.png]
basic flow chart for factory manager as follows
bucket from upper activator to lower activator on time trigger 1 sec
bucket from lower activator to back chest same trigger
bucket from chest to upper activator only on computer signal
items from back chest to item valve above kettle on 2 second delay with blacklist of buckets water and empty
bottle from front right chest. only on computer signal whitelist one at a time. pulls out only non water and empty bottles to front left chest. on 2 sec delay. pushes bottles in only on computer signal pulls out extra bottles if any exist or system gets stuck every 5 seconds
now for the potions run down
is divided as such
takes input on top and bottom analog signal through blocks next to the computer. weird bug with rednet not talking nice with factory manager was only compact way i could do it. top 1-15 bottom 1-15 and top and bottom 1-15 so total of 45 different brews made this way.
checks for signal at ether. triggers check through flow splits into top bottom or top and bottom groups. then into 1-5,6-10,11-15 from there it is on individual checking that the opposite node is not getting any signal if it is in ether of the single side groups. it then checks the individual signals and pulls items depending on the brew you want set where. in my cast 1 top is the signal for brew of vines in witchery so it takes 1 of each of the required items and puts it in the back chest to be put into the item valve after the time delay. all of these above functions than run to an emitter that tell when each step is complete so the computer can control all the delay and timing
local mon = peripheral.wrap("monitor_2")
mon.setBackgroundColor(colors.black)
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
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 ClearTable()
button = {}
end
function funcName()
print("You clicked buttonText")
end
function fillTable()
setTable("ButtonText", funcName, 5, 25, 4, 8)
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 toggleButton(name)
button[name]["active"] = not button[name]["active"]
screen()
end
----------------------------------------------
function checkActive(name)
return button[name]["active"]
end
----------------------------------------------
function flash(name)
toggleButton(name)
screen()
sleep(0.15)
toggleButton(name)
screen()
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"]()
return true
--data["active"] = not data["active"]
--print(name)
end
end
end
return false
end
function heading(text)
w, h = mon.getSize()
mon.setCursorPos((w-string.len(text))/2+1, 1)
mon.write(text)
end
function label(w, h, text)
mon.setCursorPos(w, h)
mon.write(text)
end
modified button api from direwolf20
os.loadAPI("button")
----modified version of progress bar api from hawkee.com/snippet/10100 just made it work over network-----------------------------------------
batch=1
local status= "loading"
local hasMonitor = false
local ProgressBar = {}
local FillColor = colors.orange
local EmptyColor = colors.blue
local TextColor = colors.white
function SetPeripheral(Pname)
monitor = peripheral.wrap(Pname)
hasMonitor = true
end
function SetTable(name, maxVal, curVal, xmin, xmax, y)
ProgressBar[name] = {}
ProgressBar[name]["Max"] = maxVal
ProgressBar[name]["Current"] = curVal
ProgressBar[name]["XMin"] = xmin
ProgressBar[name]["XMax"] = xmax
ProgressBar[name]["YVal"] = y
end
function ClearTable()
if (hasMonitor) then
ProgressBar = {}
end
end
function SetFillColor(color)
if (colors.combine(color,color)) then
FillColor = color
end
end
function SetEmptyColor(color)
if (colors.combine(color,color)) then
EmptyColor = color
end
end
function SetTextColor(color)
if (colors.combine(color,color)) then
TextColor = color
end
end
function SetMaxValue(name, intVal)
if (ProgressBar[name]) then
ProgressBar[name]["Max"] = intVal
end
end
function SetCurValue(name, intVal)
if (ProgressBar[name]) then
ProgressBar[name]["Current"] = intVal
end
end
function DrawToPeripheral(status)
if (hasMonitor) then
for name, data in pairs(ProgressBar) do
DrawBar(name, data)
end
end
monitor.setCursorPos(1,24)
monitor.write("status:" ..status )
end
function DrawBar(name, arr)
local y = arr["YVal"]
local fill = math.floor((arr["XMax"] - arr["XMin"]) * (arr["Current"] / arr["Max"]))
monitor.setBackgroundColor(FillColor)
monitor.setTextColor(TextColor)
for x = arr["XMin"], arr["XMax"] do
local num = math.floor(x - arr["XMin"])
monitor.setCursorPos(x,y)
if (num > fill) then
monitor.setBackgroundColor(EmptyColor)
end
if (num == 0) then
monitor.write("[")
end
if (x == arr["XMax"]) then
monitor.write("]")
else
monitor.write(" ")
end
end
monitor.setBackgroundColor(colors.black)
end
------------------------------------------
-------------------------
function bucket()
print(r)
redstone.setAnalogOutput("right",15)
sleep(1)
redstone.setAnalogOutput("right",0)
end
-------------------------
function pickPotion(side,potion)
SetCurValue("Test",2)
DrawToPeripheral("choosing potions")
redstone.setAnalogOutput(side,potion)
sleep(1)
redstone.setAnalogOutput(side,0)
end
-------------------------
function items()
redstone.setAnalogOutput("right",5)
sleep(1)
redstone.setAnalogOutput("right",0)
SetCurValue("Test",3)
DrawToPeripheral("dispensing items")
end
-------------------------
function bottle()
redstone.setAnalogOutput("right",1)
sleep(1)
redstone.setAnalogOutput("right",0)
end
-------------------------------------
function extras()
redstone.setAnalogOutput("right",2)
sleep(1)
redstone.setAnalogOutput("right",0)
SetCurValue("Test",7)
DrawToPeripheral("removing excess bottles")
end
-------------------------------------
-------------------------------------
function Brew(side,potion)
r=redstone.getInput("left")
redstone.setOutput("right",false)
redstone.setOutput("left",false)
redstone.setOutput("top",false)
redstone.setOutput("bottom",false)
t=5
bucket()
SetCurValue("Test",1)
DrawToPeripheral("dispensing water")
if not r then
while not r do
r=redstone.getInput("left")
print("system not ready waiting")
t=t-1
if t==1 then
monitor.setCursorPos(1,24)
monitor.clearLine()
DrawToPeripheral("error")
getClick()
end
sleep(1)
end
pickPotion(side,potion)
else
pickPotion(side,potion)
end
sleep(3)
t=5
if not r then
while not r do
r=redstone.getInput("left")
print("system not ready waiting")
t=t-1
if t==1 then
monitor.setCursorPos(1,24)
monitor.clearLine()
DrawToPeripheral("error")
getClick()
end
sleep(1)
end
items()
else
items()
end
sleep(1)
t=5
if not r then
while not r do
r=redstone.getInput("left")
print("system not ready waiting")
t=t-1
if t==1 then
monitor.setCursorPos(1,24)
monitor.clearLine()
DrawToPeripheral("error")
getClick()
end
sleep(1)
end
x=3
while x >= 1 do
if x==3 then
SetCurValue("Test",4)
elseif x==2 then
SetCurValue("Test",5)
elseif x==1 then
SetCurValue("Test",6)
else
end
bottle()
sleep(2)
x=x-1
end
else
x=3
while x >= 1 do
if x==3 then
SetCurValue("Test",4)
elseif x==2 then
SetCurValue("Test",5)
elseif x==1 then
SetCurValue("Test",6)
else
end
bottle()
sleep(2)
DrawToPeripheral("dispensing bottle "..x)
x=x-1
end
end
sleep(1)
print("removing extra bottles")
t=5
if not r then
while not r do
r=redstone.getInput("left")
print("system not ready waiting")
t=t-1
if t==1 then
monitor.setCursorPos(1,24)
monitor.clearLine()
DrawToPeripheral("error")
getClick()
end
sleep(1)
end
extras()
else
sleep(1)
extras()
end
print("extras removed")
monitor.setCursorPos(1,24)
monitor.clearLine()
monitor.setCursorPos(1,26)
monitor.clearLine()
DrawToPeripheral("processing complete")
sleep(3)
monitor.setCursorPos(1,24)
monitor.clearLine()
monitor.setCursorPos(1,26)
monitor.clearLine()
SetCurValue("Test",0)
DrawToPeripheral("waiting")
if screen==1 then
fillTable()
elseif screen==2 then
fillTable2()
end
end
-----------------------------------------
--------------------------------------
function fillTable()
screen=1
DrawToPeripheral("waiting")
button.setTable("page1", page1, 1,7,1,3)
button.setTable("page2", page2, 33,39,1,3)
batchB()
button.setTable("vines", vines, 1,7,5,7)
button.setTable("thorns", thorns, 9,15,5,7)
button.setTable("reboot", reboot, 33,39,24,26)
button.screen()
end
------------------------------------------------
function fillTable2()
screen=2
DrawToPeripheral("waiting")
button.setTable("page1", page1, 1,7,1,3)
button.setTable("page2", page2, 33,39,1,3)
batchB()
button.setTable("reboot", reboot, 33,39,24,26)
button.screen()
end
------------------------------------
function batchB()
button.setTable("1",batch1,9,11,1,3)
button.setTable("2",batch2,14,16,1,3)
button.setTable("3",batch3,19,21,1,3)
button.setTable("4",batch4,24,26,1,3)
button.setTable("5",batch5,29,31,1,3)
end
-----------------------------------------------
function page1()
button.ClearTable()
monitor.clear()
fillTable()
button.flash("page1")
end
----------------------------
function page2()
button.ClearTable()
monitor.clear()
fillTable2()
button.flash("page2")
end
----------------------------------------------
function batch1()
print(button.checkActive("1"))
if not button.checkActive("1") then
button.toggleButton("1")
batch=1
if button.checkActive("2") then
button.toggleButton("2")
end
if button.checkActive("3") then
button.toggleButton("3")
end
if button.checkActive("4") then
button.toggleButton("4")
end
if button.checkActive("5") then
button.toggleButton("5")
end
else
batch=1
button.flash("1")
end
end
---------------------------------------------------------
function batch2()
if not button.checkActive("2") then
button.toggleButton("2")
batch=2
if button.checkActive("1") then
button.toggleButton("1")
end
if button.checkActive("3") then
button.toggleButton("3")
end
if button.checkActive("4") then
button.toggleButton("4")
end
if button.checkActive("5") then
button.toggleButton("5")
end
else
button.flash("2")
batch=1
end
end
-------------------------------------------------------------
function batch3()
if not button.checkActive("3") then
button.toggleButton("3")
batch=2
if button.checkActive("1") then
button.toggleButton("1")
end
if button.checkActive("2") then
button.toggleButton("2")
end
if button.checkActive("4") then
button.toggleButton("4")
end
if button.checkActive("5") then
button.toggleButton("5")
end
else
button.flash("3")
batch=1
end
end
----------------------------------------------------
function batch4()
if not button.checkActive("4") then
button.toggleButton("4")
batch=2
if button.checkActive("1") then
button.toggleButton("1")
end
if button.checkActive("3") then
button.toggleButton("3")
end
if button.checkActive("2") then
button.toggleButton("2")
end
if button.checkActive("5") then
button.toggleButton("5")
end
else
button.flash("4")
batch=1
end
end
-----------------------------------------------
function batch5()
if not button.checkActive("5") then
button.toggleButton("5")
batch=2
if button.checkActive("1") then
button.toggleButton("1")
end
if button.checkActive("3") then
button.toggleButton("3")
end
if button.checkActive("4") then
button.toggleButton("4")
end
if button.checkActive("2") then
button.toggleButton("2")
end
else
button.flash("5")
batch=1
end
end
---------------------------------------------------
function batchs(side,potion,batch)
print("batch processing enabled")
batch=batch+1
while batch >=2 do
batch=batch-1
Brew(side,potion)
if batch > 1 then print("batch processing enabled")
else print("batch processing disabled")
end
sleep(2)
end
end
--------------------------------
function getClick()
event,side,x,y = os.pullEvent("monitor_touch")
button.checkxy(x,y)
end
------------------------------------------------------
function vines()
button.flash("vines")
batchs("top",1,batch)
end
function thorns()
button.flash("thorns")
batchs("top",2,batch)
end
function reboot()
button.flash("reboot")
os.reboot()
end
-------------------------------------------------------
SetPeripheral("monitor_2")
monitor.clear()
ClearTable()
fillTable()
SetTable("Test", 7, 1, 1,26,25)
DrawToPeripheral("waiting")
while true do
getClick()
end
and my code to use with the factory manager. setup is as fallows.monitor size currently used on this project is 39,26
[attachment=2039:2015-01-10_12.54.23.png][attachment=2040:2015-01-10_12.54.34.png][attachment=2041:2015-01-10_12.54.44.png][attachment=2042:2015-01-10_12.54.55.png][attachment=2043:2015-01-10_12.55.04.png]
basic flow chart for factory manager as follows
bucket from upper activator to lower activator on time trigger 1 sec
bucket from lower activator to back chest same trigger
bucket from chest to upper activator only on computer signal
items from back chest to item valve above kettle on 2 second delay with blacklist of buckets water and empty
bottle from front right chest. only on computer signal whitelist one at a time. pulls out only non water and empty bottles to front left chest. on 2 sec delay. pushes bottles in only on computer signal pulls out extra bottles if any exist or system gets stuck every 5 seconds
now for the potions run down
is divided as such
takes input on top and bottom analog signal through blocks next to the computer. weird bug with rednet not talking nice with factory manager was only compact way i could do it. top 1-15 bottom 1-15 and top and bottom 1-15 so total of 45 different brews made this way.
checks for signal at ether. triggers check through flow splits into top bottom or top and bottom groups. then into 1-5,6-10,11-15 from there it is on individual checking that the opposite node is not getting any signal if it is in ether of the single side groups. it then checks the individual signals and pulls items depending on the brew you want set where. in my cast 1 top is the signal for brew of vines in witchery so it takes 1 of each of the required items and puts it in the back chest to be put into the item valve after the time delay. all of these above functions than run to an emitter that tell when each step is complete so the computer can control all the delay and timing
Edited on 10 January 2015 - 05:09 PM