Advertisement
Crunchy_Nut

Miner Turtle Motor

Jun 1st, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.45 KB | None | 0 0
  1. local args = {...}
  2. local sides = rs.getSides()
  3.  
  4. local motorDir = args[1]
  5. local motorStage = tonumber(args[2])
  6.  
  7. for i = 1, #sides do
  8.     side = sides[i]
  9.     if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  10.         rednet.open(side)
  11.         break
  12.     end
  13. end
  14.  
  15. function pulse()
  16.     print("Pulsing redstone")
  17.     redstone.setOutput("right", true)
  18.     sleep(0.5)
  19.     redstone.setOutput("right", false)
  20.     sleep(0.5)
  21. end
  22.  
  23. while(true) do
  24.     --term.clear()
  25.     --term.setCursorPos(1, 1)
  26.  
  27.     print("Motor waiting for message..")
  28.     id, msg = rednet.receive("coms_turtles_motor")
  29.    
  30.     if msg == "UPDATE" then
  31.         shell.run("updater false motor")
  32.     end
  33.  
  34.     if string.find(msg, "forward") then
  35.         print("Message was for forward!")
  36.  
  37.         if motorDir == "forward" then
  38.             if (msg == "forward_1" and motorStage == 1) or (msg == "forward_2" and motorStage == 2) then
  39.                 pulse()
  40.             end
  41.         end
  42.  
  43.         if string.find(msg, "_1") then
  44.             if motorDir == "forward" then
  45.                 turtle.forward()
  46.             else
  47.                 turtle.back()
  48.             end
  49.         end
  50.     elseif string.find(msg, "reverse") then
  51.         print("Message was for reverse!")
  52.  
  53.         if motorDir == "reverse" then
  54.             if (msg == "reverse_1" and motorStage == 1) or (msg == "reverse_2" and motorStage == 2) then
  55.                 pulse()
  56.             end
  57.         end
  58.  
  59.         if string.find(msg, "_1") then
  60.             if motorDir == "reverse" then
  61.                 turtle.forward()
  62.             else
  63.                 turtle.back()
  64.             end
  65.         end
  66.     end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement