Advertisement
Nokiyen

autoDoorSender

Jun 20th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. --[[
  2. ***********
  3.  * autoDoorSender
  4.  *
  5.  * argument1: side of wireless modem.
  6.  * argument2: channelID.
  7. **********
  8. ]]
  9.  
  10.  
  11. ----------
  12. -- Variables.
  13. ----------
  14. -- define vars.
  15. local args = {...}
  16. local side = args[1]
  17. local channelID = args[2]
  18.  
  19.  
  20. ----------
  21. -- Main Thread.
  22. ----------
  23. local p = peripheral.wrap(side)
  24. p.open(channelID)
  25.  
  26. while true do
  27.     p.transmit(channelID, channelID, channelID)
  28.     local timerID = os.startTimer(3)
  29.     local eventName, return1, return2, return3, return4, return5 = os.pullEvent()
  30.     if eventName == "modem_message" and tonumber(return2) == channelID then
  31.         if tonumber(return5) < 5 then
  32.             rs.setOutput("top", true)
  33.         else
  34.             rs.setOutput("top", false)
  35.         end
  36.     end
  37.     if eventName ~= "timer" or tonumber(return1) ~= timerID then
  38.         sleep(2.5)
  39.     end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement