Advertisement
Guest User

doorControl

a guest
Jun 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. function close(bool)
  2.   rs.setOutput("left",bool)
  3.   rs.setOutput("back",bool)
  4. end
  5.  
  6. function open()
  7.   close(false)
  8.   sleep(2)
  9.   close(true)
  10. end
  11.  
  12. close(true)
  13. local modem = peripheral.wrap("bottom")
  14. modem.closeAll()
  15. modem.open(1)
  16. local auto = true
  17.  
  18. while true do
  19.   event,side,freq,refreq,msg,dist = os.pullEvent("modem_message")
  20.   if freq == 1 then
  21.     if msg == "open" then
  22.       auto = false
  23.       close(false)
  24.       write("force open")
  25.     elseif msg == "close" then
  26.       auto = false
  27.       close(true)
  28.       write("force close")
  29.     elseif msg == "auto" then
  30.       auto = true
  31.       write("auto on")
  32.     elseif msg == "opc" and dist < 5 and auto then
  33.       open()
  34.       write("open- "..dist.."\n")
  35.     else
  36.       if auto then
  37.         write("reject- freq:"..freq..",.refreq:"..refreq.."msg"..msg.."dist"..dist.."\n")
  38.       end
  39.     end
  40.   end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement