Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.find("monitor")
- monitor.setCursorPos(1, 1)
- monitor.clear()
- -- | Directional
- -- | Variables
- -- | i.e., these variables deal with the movement of the array
- mainGearshift = redstone.testBundledInput("back", colors.white) -- White
- xGantryProp = redstone.testBundledInput("back", colors.black) -- Black
- yGantryProp = redstone.testBundledInput("back", colors.brown) -- Brown
- -- | Hardware
- -- | Variables
- maxYReached = redstone.testBundledInput("back", colors.yellow) -- Yellow
- maxXReached = redstone.testBundledInput("back", colors.purple) -- Purple
- maxDepthReached = redstone.testBundledInput("back", colors.red) -- Red
- drillArrayReturn = redstone.testBundledInput("back", colors.green) -- Green
- drillLeftReturn = redstone.testBundledInput("back", colors.orange) -- Orange
- drillBackReturn = redstone.testBundledInput("back", colors.blue) -- Blue
- portableInter = redstone.testBundledInput("back", colors.gray) -- Gray
- clutch = redstone.testBundledInput("back", colors.magenta) -- Magenta
- -- | Color
- -- | Variables
- whiteNum = 0x1
- orangeNum = 0x2
- magentaNum = 0x4
- lightBlueNum = 0x8
- yellowNum = 0x10
- limeNum = 0x20
- pinkNum = 0x40
- grayNum = 0x80
- lightGrayNum = 0x100
- cyanNum = 0x200
- purpleNum = 0x400
- blueNum = 0x800
- brownNum = 0x1000
- greenNum = 0x2000
- redNum = 0x4000
- blackNum = 0x8000
- time = 5 -- Time it takes the array to move by 3m in any direction
- --placeholder = 0
- -- | Bundled Cable
- -- | Functions
- function toggleBundledColor(side, color) -- Works
- -- Toggles the inputted color at selected side
- -- *Warning* This function requires colors with the -Num suffix
- -- credits: https://www.computercraft.info/forums2/index.php?/topic/28112-toggle-bundled-cable-outputs/ User: Lyqyd
- rs.setBundledOutput(side, (colors.test(rs.getBundledOutput(side), color) and colors.subtract(rs.getBundledOutput(side), color) or colors.combine(rs.getBundledOutput(side), color)))
- end
- function setBundledColor(side, color, state) -- Works
- -- Sets the inputted color and the inputted side to the inputted value
- -- *Warning* This function requires colors with the -Num suffix
- -- credits: https://www.computercraft.info/forums2/index.php?/topic/28112-toggle-bundled-cable-outputs/ User: Lyqyd
- if state then
- if not colors.test(rs.getBundledOutput(side), color) then
- rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side), color))
- end
- else
- if colors.test(rs.getBundledOutput(side), color) then
- rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side), color))
- end
- end
- end
- -- | Drill Array Operation
- -- | Variables
- function moveArrayRight() -- Works
- -- Moves the drill array right.
- -- Main Gearshift: 1, Main Propagation: 1
- setBundledColor("back", whiteNum, true) -- Main
- setBundledColor("back", blackNum, true) -- Main Propagation
- setBundledColor("back", brownNum, false) -- Secondary Propagation
- end
- function moveArrayLeft() -- Works
- -- Moves the drill array left.
- -- Main Propagation: 1
- setBundledColor("back", whiteNum, false) -- Main
- setBundledColor("back", blackNum, true) -- Main Propagation
- setBundledColor("back", brownNum, false) -- Secondary Propagation
- end
- function moveArrayForward() -- Works
- -- Moves the drill array forward.
- -- Main Gearshift: 1
- setBundledColor("back", whiteNum, true) -- Main
- setBundledColor("back", blackNum, false) -- Main Propagation
- setBundledColor("back", brownNum, false) -- Secondary Propagation
- end
- function moveArrayBack() -- Works
- -- Moves the drill array backward.
- -- All values 0
- setBundledColor("back", whiteNum, false) -- Main
- setBundledColor("back", blackNum, false) -- Main Propagation
- setBundledColor("back", brownNum, false) -- Secondary Propagation
- end
- function lowerDrill() -- Works
- -- Lowers the drill array until the max depth is reached.
- -- Main Propagation: 1, Secondary Propagation: 1
- while not MaxDepthReached() do -- Stops once max depth is reached
- setBundledColor("back", whiteNum, false) -- Main
- setBundledColor("back", blackNum, true) -- Main Propagation
- setBundledColor("back", brownNum, true) -- Secondary Propagation
- sleep() -- Prevents a "Too long without yield" error
- end
- print("Max depth reached.")
- while not DrillArrayReturn() do -- Stops once drill array has returned
- raiseDrill()
- sleep()
- end
- print("Drill array returned.")
- end
- function raiseDrill() -- Works
- -- Raises the drill array until the drill array has been returned (using the drill return contact).
- -- Main Gearshift: 1, Main Propagation: 1, Secondary Propagation: 1
- print("Inside the raise drill function.")
- setBundledColor("back", whiteNum, true) -- Main
- setBundledColor("back", blackNum, true) -- Main Propagation
- setBundledColor("back", brownNum, true) -- Secondary Propagation
- end
- -- | Helper
- -- | Functions
- -- | Based on the recommendation of u/CommendableCalamari on Reddit
- function MaxDepthReached() return redstone.testBundledInput("back", colors.red) end
- function DrillArrayReturn() return redstone.testBundledInput("back", colors.green) end
- function DrillLeftReturn() return redstone.testBundledInput("back", colors.orange) end
- function DrillBackReturn() return redstone.testBundledInput("back", colors.blue) end
- function MaxYReached() return redstone.testBundledInput("back", colors.yellow) end
- function MaxXReached() return redstone.testBundledInput("back", colors.purple) end
- -- | Main
- -- | Functions
- function ReturnToOrigin() -- Works
- -- Returns the drill array to the origin.
- while not DrillLeftReturn() do -- While the array isn't at its' max left
- moveArrayLeft()
- sleep()
- end
- while not DrillBackReturn() do -- While the array isn' at its' max back
- moveArrayBack()
- sleep()
- end
- end
- function MoveRightLogic() -- Fix
- -- Moves the drill array right if possible
- while true do
- lowerDrill() -- Issue: Somehow, gets stuck here without raising the drill after moving forward.
- print("Finished lowering the drill.")
- if MaxXReached() then -- Breaks if it has reached the maximum 'X' value
- -- Only does this after it has drilled, so it can drill the section near the max 'X' value
- print("Max 'X' value reached.")
- break
- end
- moveArrayRight()
- sleep(time)
- end
- while not DrillLeftReturn() do -- Moves the array left until it reaches the maximum left
- moveArrayLeft()
- sleep()
- end
- end
- function Main() -- Untested
- -- The main function
- setBundledColor("back", grayNum, true) -- Disables the portable storage interface
- -- setBundledColor("back", magentaNum, true) -- Locks the clutch
- sleep(2.0)
- repeat
- -- setBundledColor("back", magentaNum, false) -- Unlocks the clutch
- print("Beginning of loop.")
- MoveRightLogic() -- Issue when the array is at a 'Y' greater than 3 and is unable to raise drill
- print("Finished move right logic.")
- moveArrayForward()
- print("Moved Array Forward.")
- sleep(time) -- Timing is based on 16 RPM
- print("Gone past system sleep.")
- until(MaxXReached() and MaxYReached()) -- Until the array has reached max 'X' and 'Y'
- -- The only reason I'm doing a repeat-until loop is that once it has actually reached boy 'X' and 'Y' max
- -- It first must drill, then return to origin.
- print("Broken from repeat-while loop.")
- ReturnToOrigin()
- toggleBundledColor("back", magentaNum) -- Locks the clutch
- toggleBundledColor("back", grayNum) -- Enables the portable storage interface
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment