Advertisement
KingKevin23

door_control

Aug 6th, 2023
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local my_name = "rocket"
  2. local modem_pos = "bottom"
  3. local protocol = "door_control"
  4. local motor = peripheral.wrap("right")
  5.  
  6. motor.stop()
  7. rednet.open(modem_pos)
  8. rednet.host(protocol, my_name)
  9. while true do
  10.     local id, message = rednet.receive(protocol)
  11.     if message == "open" then
  12.         if redstone.getInput("left") then
  13.             sleep(motor.rotate(-90, 10))
  14.             motor.stop()
  15.             print("Door opened by " .. id)
  16.         else
  17.             print("Door already open")
  18.         end
  19.     elseif message == "close" then
  20.         if redstone.getInput("left") == false then
  21.             sleep(motor.rotate(90, 10))
  22.             motor.stop()
  23.             print("Door closed by " .. id)
  24.         else
  25.             print("Door already closed")
  26.         end
  27.     else
  28.         print("Message was not recognized " .. message .. " " .. id)
  29.     end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement