Advertisement
lucifersamfr

MSlateral

Apr 1st, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. --Operate 2 frame motors moving the mining station LEFT & RIGHT
  2. local movChannel = 12
  3. local movRespChannel = 13
  4. local followChannel = 14
  5. local followRespChannel = 15
  6. local modem = peripheral.wrap("right")
  7. modem.open(movChannel)
  8.  
  9. function unsetAll(sigSide)
  10.   rs.setBundledOutput(sigSide,0)
  11. end
  12.  
  13. function move(side,dist)
  14.   local signalSide
  15.   local followerCmd
  16.   if (side == "left") then
  17.     signalSide = "front"
  18.     followerCmd = "follow_Left"
  19.   else
  20.     if (side == "right") then
  21.       signalSide = "back"
  22.       followerCmd = "follow_Right"
  23.     else
  24.       return false
  25.     end
  26.   end
  27.  
  28.   for i=1,dist do
  29.     modem.transmit(followChannel ,followRespChannel ,followerCmd)
  30.    
  31.     rs.setBundledOutput(signalSide,colors.red)
  32.     sleep(0.5)
  33.     unsetAll(signalSide)
  34.     sleep(1)
  35.    
  36.     rs.setBundledOutput(signalSide,colors.black)
  37.     sleep(0.5)
  38.     unsetAll(signalSide)
  39.     sleep(1)
  40.   end
  41. end
  42.  
  43. while true do
  44.   local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  45.   local op=textutils.unserialize(message)
  46.   --print(op.name)
  47.   --print("__"..op.direction)
  48.   --print("__"..op.iter)
  49.   if (op.name == "lateral") then
  50.     move(op.direction, tonumber(op.iter))
  51.     modem.transmit(movRespChannel,movChannel,"lateral OK")
  52.   end
  53.   sleep(3)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement