Advertisement
Guest User

doorControl

a guest
Feb 8th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1. --Change these variables to how you want your door configured
  2. local wirelessSide = "top"  --The side of the rednet router
  3. local monitorSide = "left"  --The side the advanced monitor is on (YES MUST BE ADVANCED MONITOR)
  4. local doorNumber = 2        --Either one or two, the number of doors connected
  5. local door1ID = 2           --Change these variables to the number IDs of the computers controlling your doors
  6. local door2ID = 4           --If using only 1 door set this value to - nil
  7.  
  8. local wireless = peripheral.wrap(wirelessSide)
  9.  
  10. local monitor = peripheral.wrap(monitorSide)  --Wraps monitor to the side specified
  11.  
  12.  
  13. function
  14. clearScreen()  --Clears anything that might have been on the screen
  15.   monitor.clear()
  16. end
  17.  
  18. function titleDisplay()
  19.  
  20.   --Creates the static title display
  21.  
  22. monitor.setCursorPos(2,1)
  23.  
  24.   monitor.setBackgroundColor(colors.black)
  25.   monitor.write("Doors")
  26.  
  27. end
  28.  
  29.  
  30.  
  31. function closedDoor1()  
  32.   --Dislayed if door1 is closed
  33.   monitor.setCursorPos(2,door1ButtonY)
  34.  
  35.   monitor.clearLine()
  36.  
  37.   monitor.setBackgroundColor(colors.green)
  38.  
  39. monitor.write("Door1")
  40.  
  41.   monitor.setBackgroundColor(colors.black)
  42. end
  43.  
  44.  
  45.  
  46. function openedDoor1()  --Displayed if door1 is opened
  47.   monitor.setCursorPos(2,door1ButtonY)
  48.   monitor.clearLine()
  49.   monitor.setBackgroundColor(colors.red)
  50.   monitor.write("Door1")
  51.   monitor.setBackgroundColor(colors.black)
  52. end
  53.  
  54. function closedDoor2()  
  55.    --Displayed if door2 is closed
  56.   monitor.setCursorPos(2,4)
  57.  
  58.   monitor.clearLine()
  59.  
  60.   monitor.setBackgroundColor(colors.green)
  61.  
  62. monitor.write("Door2")
  63.   monitor.setBackgroundColor(colors.black)
  64.  
  65. end
  66.  
  67.  
  68. function openedDoor2()   --Displayed if door2 is open
  69.   monitor.setCursorPos(2,4)
  70.  
  71.   monitor.clearLine()
  72.  
  73.   monitor.setBackgroundColor(colors.red)
  74.  
  75. monitor.write("Door2")
  76.   monitor.setBackgroundColor(colors.black)
  77. end
  78.  
  79. function statusDoor1()  --Checks the status of door1 and updates the display on the monitor
  80.   if arg2=="open" then
  81.     openedDoor1()
  82.   elseif arg2=="closed" then
  83.     closedDoor1()
  84.   end
  85. end
  86.  
  87. function statusDoor2()  --Checks the status of door2 and updates the display on the monitor
  88.   if arg2=="open" then
  89.     openedDoor2()
  90.   elseif arg2=="closed" then
  91.     closedDoor2()
  92.   end
  93. end
  94.  
  95. function eventDoor1()    --Controls the events for door1
  96.   if event=="rednet_message" and arg1==door1ID then
  97.     statusDoor1()
  98.   elseif event=="monitor_touch" and arg3==door1ButtonY then
  99.     rednet.send(door1ID, "force1")
  100.   end
  101. end
  102.  
  103. function eventDoor2()   --Controls the events for door2
  104.   if event=="rednet_message" and arg1==door2ID then
  105.     statusDoor2()
  106.   elseif event=="monitor_touch" and arg3==4 then
  107.     rednet.send(door2ID, "force2")
  108.   end
  109. end
  110.  
  111. rednet.open(wirelessSide)  --Opens rednet
  112. clearScreen()              --Clears screen
  113. titleDisplay()             --Displays title
  114.  
  115. if doorNumber==1 then
  116.   door1ButtonY = 3
  117. elseif doorNumber==2 then
  118.   door1ButtonY = 2
  119. end
  120.  
  121. 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
  122. event, arg1, arg2, arg3 = os.pullEvent()
  123.   if doorNumber==1 then
  124.     eventDoor1()
  125.   end
  126.   if doorNumber==2 then
  127.     eventDoor1()
  128.     eventDoor2()
  129.   end
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement