This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xixili's profile picture

Control a door with 2 computers

Started by Xixili, 21 July 2014 - 07:50 PM
Xixili #1
Posted 21 July 2014 - 09:50 PM
Hello

Im trying to create an airlock controlled by 2 computers

when computer 1 opens the door then you cant close the door with computer 2
Same counts the other way around, if computer 2 opens the door then computer 1 cant do anything with it.

I use bundledcable with this.
White cable is to open/close door
Yellow cable is to flow water between the doors (airlock)
both computers are connected to the same bundled cable.


-- ######################
-- ## CABLE USAGE
-- ######################

-- Computer ID 11
-- Waterflow yellow
-- Door	white

-- ######################
-- ##
-- ######################

os.pullEvent = os.pullEventRaw
local standby = 5
local side = "back"
local password = "sushi"
local YES = "y"
local back = "back"
local a = "1"
local b = "2"
local c = "3"

-- ######################
-- ##
-- ######################

local width, height = term.getSize()

while true do
term.setCursorPos(1, 1)
term.setBackgroundColor(colors.black)
term.clear()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.red)
term.clearLine()

term.setCursorPos(1, height)
term.clearLine()
local text = "D1 Airlock Controlpanel"
term.setCursorPos(math.floor((width - #text) / 2), 1)
term.write(text)

-- ######################
-- #### MENU
-- ######################

term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
term.setCursorPos(1, 3)
term.write("|D1 Menu|")
term.setCursorPos(4, 5)
term.write("1 - Open D1 Airlock")
term.setCursorPos(4, 6)
term.write("2 - Close D1 Airlock")
term.setTextColor(colors.red)
term.setBackgroundColor(colors.black)
term.setCursorPos(4, 7)
term.setTextColor(colors.red)
term.setBackgroundColor(colors.black)
term.setCursorPos(4, 14)
term.setTextColor(colors.white)
term.write("Option: ")
local input = read()

-- ######################
-- #### DOORS OPEN
-- ######################

if input == a then
	term.setCursorPos(1, 1)
term.setBackgroundColor(colors.black)
term.clear()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.red)
term.clearLine()

term.setCursorPos(1, height)
term.clearLine()
local text = "D1 Airlock"
term.setCursorPos(math.floor((width - #text) / 2), 1)
term.write(text)
-- ####
term.setCursorPos(3, 3)
	term.setBackgroundColor(colors.black)
	term.setTextColor(colors.white)
	term.write("Opening D1 Airlock")
for i=1, 1 do
	rs.setBundledOutput("back", colours.yellow)
	sleep(6.5)
	rs.setBundledOutput("back", colors.yellow+colors.white)
	sleep(0.5)
end
term.setCursorPos(25, 3)
	term.setBackgroundColor(colors.black)
	term.setTextColor(colors.lime)
	term.write("READY")
sleep(2)
term.clear()
	end

-- ######################
-- #### DOORS CLOSE
-- ######################

if input == b then
	term.setCursorPos(1, 1)
term.setBackgroundColor(colors.black)
term.clear()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.red)
term.clearLine()

term.setCursorPos(1, height)
term.clearLine()
local text = "D1 Airlock"
term.setCursorPos(math.floor((width - #text) / 2), 1)
term.write(text)
term.setCursorPos(3, 3)
	term.setBackgroundColor(colors.black)
	term.setTextColor(colors.white)
	term.write("Closing D1 Airlock")
for i=1, 1 do
	rs.setBundledOutput("back", colors.yellow+colors.black)
	sleep(1.5)
	rs.setBundledOutput("back", colours.black)
end
term.setCursorPos(25, 3)
	term.setBackgroundColor(colors.black)
	term.setTextColor(colors.lime)
	term.write("READY")
sleep(2)
term.clear()
	end
end
Edited on 21 July 2014 - 07:51 PM
hilburn #2
Posted 21 July 2014 - 10:16 PM
Well it depends on what version of CC you are using, but bundled cable support has been dropped in 1.6.x (or rather integration has been left up to the cable mod makers and noone has done it)

What errors are you encountering?
Xixili #3
Posted 21 July 2014 - 11:19 PM
Well it depends on what version of CC you are using, but bundled cable support has been dropped in 1.6.x (or rather integration has been left up to the cable mod makers and noone has done it)

What errors are you encountering?
im running version 1.58 (MC 1.6.4) and using the rednet cables.
Im not running in any errors because the script works.
But only on 1 computer it works.

For example I want to open the door on computer 1 it sends a redstone signal to the doors.
And it stays open untill i say it has to close.
But If I want to close it on computer 2 it doesnt because the redstone signal is send by computer 1.

thats my error.
hilburn #4
Posted 22 July 2014 - 12:58 AM
Aha I gotcha
Sending another signal over a different colour would probably be the easiest way to do it, for example if you sent a pulse down red every time you try to close the doors with either computer and then have something that turns off output on yellow when it has an input on red or in a more pseudocode form:


function door_close()
if rs.input(yellow) then --#if the other computer is keeping the door open
   rs.output(red,true) --#send a pulse on red to tell him to quit it
   sleep(0.2)
   rs.output(red,false)
end
rs.output(yellow,false) --#turn it off from this computer
end
function told_to_close()
if rs.input(red) then
    rs.output(yellow,false)
end
end

Sorry it's so rough, on a phone atm
Xixili #5
Posted 22 July 2014 - 01:55 AM
Aha I gotcha
Sending another signal over a different colour would probably be the easiest way to do it, for example if you sent a pulse down red every time you try to close the doors with either computer and then have something that turns off output on yellow when it has an input on red or in a more pseudocode form:


function door_close()
if rs.input(yellow) then --#if the other computer is keeping the door open
   rs.output(red,true) --#send a pulse on red to tell him to quit it
   sleep(0.2)
   rs.output(red,false)
end
rs.output(yellow,false) --#turn it off from this computer
end
function told_to_close()
if rs.input(red) then
	rs.output(yellow,false)
end
end

Sorry it's so rough, on a phone atm

looks okay but sadly its too long ago for me to get this working for me :(/>
I forgot most of the programming

EDIT:
I tried but I cant get it working sadly

This is what I have on both computers now:


-- ######################
-- ## CABLE USAGE
-- ######################
-- Computer ID 11
-- Waterflow yellow
-- Door    white 
-- ######################
-- ##
-- ######################
os.pullEvent = os.pullEventRaw
local standby = 5
local side = "back"
local password = "sushi"
local YES = "y"
local back = "back"
local a = "1"
local b = "2"
local c = "3"

-- ######################
-- ##
-- ######################
local width, height = term.getSize()

while true do
term.setCursorPos(1, 1)
term.setBackgroundColor(colors.black)
term.clear()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.red)
term.clearLine()

term.setCursorPos(1, height)
term.clearLine()
local text = "D1 Airlock Controlpanel"
term.setCursorPos(math.floor((width - #text) / 2), 1)
term.write(text)
-- ######################
-- #### MENU
-- ######################
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
term.setCursorPos(1, 3)
term.write("|D1 Menu|")
term.setCursorPos(4, 5)
term.write("1 - Open D1 Airlock")
term.setCursorPos(4, 6)
term.write("2 - Close D1 Airlock")
term.setTextColor(colors.red)
term.setBackgroundColor(colors.black)
term.setCursorPos(4, 7)
term.setTextColor(colors.red)
term.setBackgroundColor(colors.black)
term.setCursorPos(4, 14)
term.setTextColor(colors.white)
term.write("Option: ")
local input = read()
-- ######################
-- #### DOORS OPEN
-- ######################
if input == a then
if rs.testBundledInput("back", colours.yellow) then
    rs.setBundledOutput("back", colours.red)
sleep(0.2)
end
if rs.testBundledInput("back", colours.red) then
sleep(0.2)
    rs.setBundledOutput("back", colours.black)
end
    term.setCursorPos(1, 1)
term.setBackgroundColor(colors.black)
term.clear()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.red)
term.clearLine()

term.setCursorPos(1, height)
term.clearLine()
local text = "D1 Airlock"
term.setCursorPos(math.floor((width - #text) / 2), 1)
term.write(text)
-- ####
term.setCursorPos(3, 3)
    term.setBackgroundColor(colors.black)
    term.setTextColor(colors.white)
    term.write("Opening D1 Airlock")
for i=1, 1 do
    rs.setBundledOutput("back", colours.yellow)
    sleep(6.5)
    rs.setBundledOutput("back", colors.yellow+colors.white)
    sleep(0.5)
end
term.setCursorPos(25, 3)
    term.setBackgroundColor(colors.black)
    term.setTextColor(colors.lime)
    term.write("READY")
sleep(2)
term.clear()
    end
-- ######################
-- #### DOORS CLOSE
-- ######################
if input == b then
if rs.testBundledInput("back", colours.yellow) then
    rs.setBundledOutput("back", colours.red)
sleep(0.2)
end
if rs.testBundledInput("back", colours.red) then
sleep(0.2)
    rs.setBundledOutput("back", colours.black)
end

    term.setCursorPos(1, 1)
term.setBackgroundColor(colors.black)
term.clear()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.red)
term.clearLine()

term.setCursorPos(1, height)
term.clearLine()
local text = "D1 Airlock"
term.setCursorPos(math.floor((width - #text) / 2), 1)
term.write(text)
term.setCursorPos(3, 3)
    term.setBackgroundColor(colors.black)
    term.setTextColor(colors.white)
    term.write("Closing D1 Airlock")
for i=1, 1 do
    rs.setBundledOutput("back", colors.yellow+colors.black)
    sleep(1.5)
    rs.setBundledOutput("back", colours.black)
end
term.setCursorPos(25, 3)
    term.setBackgroundColor(colors.black)
    term.setTextColor(colors.lime)
    term.write("READY")
sleep(2)
term.clear()
    end
end
Edited on 22 July 2014 - 12:24 AM