Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Change these variables to how you want your door configured
- local wirelessSide = "top" --The side of the rednet router
- local monitorSide = "left" --The side the advanced monitor is on (YES MUST BE ADVANCED MONITOR)
- local doorNumber = 2 --Either one or two, the number of doors connected
- local door1ID = 2 --Change these variables to the number IDs of the computers controlling your doors
- local door2ID = 4 --If using only 1 door set this value to - nil
- local wireless = peripheral.wrap(wirelessSide)
- local monitor = peripheral.wrap(monitorSide) --Wraps monitor to the side specified
- function
- clearScreen() --Clears anything that might have been on the screen
- monitor.clear()
- end
- function titleDisplay()
- --Creates the static title display
- monitor.setCursorPos(2,1)
- monitor.setBackgroundColor(colors.black)
- monitor.write("Doors")
- end
- function closedDoor1()
- --Dislayed if door1 is closed
- monitor.setCursorPos(2,door1ButtonY)
- monitor.clearLine()
- monitor.setBackgroundColor(colors.green)
- monitor.write("Door1")
- monitor.setBackgroundColor(colors.black)
- end
- function openedDoor1() --Displayed if door1 is opened
- monitor.setCursorPos(2,door1ButtonY)
- monitor.clearLine()
- monitor.setBackgroundColor(colors.red)
- monitor.write("Door1")
- monitor.setBackgroundColor(colors.black)
- end
- function closedDoor2()
- --Displayed if door2 is closed
- monitor.setCursorPos(2,4)
- monitor.clearLine()
- monitor.setBackgroundColor(colors.green)
- monitor.write("Door2")
- monitor.setBackgroundColor(colors.black)
- end
- function openedDoor2() --Displayed if door2 is open
- monitor.setCursorPos(2,4)
- monitor.clearLine()
- monitor.setBackgroundColor(colors.red)
- monitor.write("Door2")
- monitor.setBackgroundColor(colors.black)
- end
- function statusDoor1() --Checks the status of door1 and updates the display on the monitor
- if arg2=="open" then
- openedDoor1()
- elseif arg2=="closed" then
- closedDoor1()
- end
- end
- function statusDoor2() --Checks the status of door2 and updates the display on the monitor
- if arg2=="open" then
- openedDoor2()
- elseif arg2=="closed" then
- closedDoor2()
- end
- end
- function eventDoor1() --Controls the events for door1
- if event=="rednet_message" and arg1==door1ID then
- statusDoor1()
- elseif event=="monitor_touch" and arg3==door1ButtonY then
- rednet.send(door1ID, "force1")
- end
- end
- function eventDoor2() --Controls the events for door2
- if event=="rednet_message" and arg1==door2ID then
- statusDoor2()
- elseif event=="monitor_touch" and arg3==4 then
- rednet.send(door2ID, "force2")
- end
- end
- rednet.open(wirelessSide) --Opens rednet
- clearScreen() --Clears screen
- titleDisplay() --Displays title
- if doorNumber==1 then
- door1ButtonY = 3
- elseif doorNumber==2 then
- door1ButtonY = 2
- end
- while true do --For loop that initiates the code and waits for updates to the doors and for if anyone touches the buttons on the monitor
- event, arg1, arg2, arg3 = os.pullEvent()
- if doorNumber==1 then
- eventDoor1()
- end
- if doorNumber==2 then
- eventDoor1()
- eventDoor2()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement