Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Door control with bundled cable (More Red + Create + CC:Tweaked)
- local modemSide = "top" -- Wireless modem side
- local bundledSide = "back" -- Bundled cable side
- local channel = 42 -- Wireless channel to listen on
- -- Define color bits
- local RED = colors.red
- local GREEN = colors.lime
- local ORANGE = colors.orange
- local BLUE = colors.blue
- local LIGHTBLUE = colors.lightBlue
- local MAGENTA = colors.magenta
- local YELLOW = colors.yellow
- -- Pulse helper
- function pulse(color)
- local output = redstone.getBundledOutput(bundledSide)
- redstone.setBundledOutput(bundledSide, bit.bor(output, color))
- sleep(0.2)
- output = redstone.getBundledOutput(bundledSide)
- redstone.setBundledOutput(bundledSide, bit.band(output, bit.bnot(color)))
- end
- -- Status check
- function isDoorClosed()
- local input = redstone.getBundledInput(bundledSide)
- return bit.band(input, MAGENTA) ~= 0
- end
- function isDoorOpen()
- local input = redstone.getBundledInput(bundledSide)
- return bit.band(input, YELLOW) ~= 0
- end
- -- Open door sequence
- function openDoor()
- if isDoorOpen() then
- print("Door is already open.")
- return "already_open"
- end
- print("Opening door...")
- -- Set direction to OPEN (Red OFF)
- local output = redstone.getBundledOutput(bundledSide)
- redstone.setBundledOutput(bundledSide, bit.band(output, bit.bnot(RED)))
- sleep(0.1)
- -- start water clearing
- pulse(LIGHTBLUE);
- sleep(5)
- -- retract pistons
- pulse(ORANGE)
- sleep(7)
- -- Activate BLUE (start sliding door out)
- pulse(BLUE)
- sleep(1.5) -- wait for door to slide out
- -- rotate wall in
- pulse(GREEN)
- sleep(0.5) -- allow for piston extension
- print("Door opened.")
- return "opened"
- end
- -- Close door sequence
- function closeDoor()
- if isDoorClosed() then
- print("Door is already closed.")
- return "already_closed"
- end
- print("Closing door...")
- -- Set direction to CLOSE (Red ON)
- local output = redstone.getBundledOutput(bundledSide)
- redstone.setBundledOutput(bundledSide, bit.bor(output, RED))
- -- rotate wall out
- pulse(GREEN)
- sleep(1.5)
- -- rotate pistons
- pulse(BLUE)
- sleep(1.5) -- wait for pistons rotate
- -- extend pistons
- pulse(ORANGE)
- sleep(5) -- allow for door to slide closed
- print("Door closed.")
- return "closed"
- end
- -- Setup modem
- rednet.open(modemSide)
- rednet.host("door_control", "door_server")
- print("Door controller listening on wireless channel " .. channel)
- -- Main loop
- while true do
- local senderId, message = rednet.receive("door_control")
- local response = "unknown_command"
- if message == "open" then
- response = openDoor()
- elseif message == "close" then
- response = closeDoor()
- elseif message == "status" then
- if isDoorOpen() then
- response = "door_open"
- elseif isDoorClosed() then
- response = "door_closed"
- else
- response = "door_inbetween"
- end
- end
- rednet.send(senderId, response, "door_control")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement