MegiRicky

Z-18Aux.lua

Sep 26th, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. local motor = peripheral.find("Create_RotationSpeedController")
  3. redstone.setOutput("front",false)
  4. motor.setTargetSpeed(0)
  5. print("Input the controlChannel, default = 1100")
  6. local controlChannel = io.read()
  7. if controlChannel == "" then
  8. controlChannel = 1100
  9. end
  10. controlChannel = tonumber(controlChannel)
  11. modem.open(controlChannel) -- Open a channel to communicate
  12. local AuxControlChannel = controlChannel + 1
  13. modem.open(AuxControlChannel)
  14.  
  15. local function manualCannonControl()
  16. while true do
  17. if AuxControls then
  18. motor.setTargetSpeed(AuxControls.tailSpeed)
  19. end
  20. sleep()
  21. end
  22. end
  23.  
  24. local function pitchControl()
  25. while true do
  26. if AuxControls and AuxControls.pitch then
  27. if AuxControls.pitch > 0 then
  28. redstone.setAnalogOutput("bottom",math.min(math.abs(AuxControls.pitch),15))
  29. redstone.setOutput("back",false)
  30. elseif AuxControls.pitch < 0 then
  31. redstone.setAnalogOutput("back",math.min(math.abs(AuxControls.pitch),15))
  32. redstone.setOutput("bottom",false)
  33. else
  34. redstone.setOutput("bottom",false)
  35. redstone.setOutput("back",false)
  36. end
  37. end
  38. sleep()
  39. end
  40. end
  41.  
  42. local function throttleControl()
  43. while true do
  44. if AuxControls and AuxControls.throttle then
  45. if AuxControls.throttle > 0 then
  46. redstone.setAnalogOutput("front",math.abs(AuxControls.throttle))
  47. else
  48. redstone.setOutput("front",false)
  49. end
  50. end
  51. sleep()
  52. end
  53. end
  54.  
  55. local function modemMessage()
  56. while true do
  57. if modem then
  58. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  59. if channel == AuxControlChannel then
  60. AuxControls = message
  61. end
  62. else
  63. sleep()
  64. end
  65. end
  66. end
  67.  
  68. parallel.waitForAny(
  69. modemMessage,
  70. manualCannonControl,
  71. pitchControl,
  72. throttleControl
  73. )
  74.  
Advertisement
Add Comment
Please, Sign In to add comment