Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local side = "left"
- local funcState = {}
- funcState.step = 0
- funcState.func = runLeft
- local rsDelay = 0.1
- local colMap = {
- headSliderBreaker = { color = colors.orange, delay = 0.3 },
- headSliderDeployer = { color = colors.yellow, delay = 0.3 },
- headSliderLeft = { color = colors.lightBlue, delay = 1.1 },
- headSliderRight = { color = colors.magenta, delay = 1.1 },
- checkColLeft = { color = colors.white },
- checkColRight = { color = colors.gray },
- checkForward = { color = colors.brown },
- fwdBreaker = { color = colors.purple, delay = 0.3 },
- fwdDeployer = { color = colors.cyan, delay = 0.3 },
- battery = { color = colors.lime, delay = 1 },
- engineMotorPush = { color=colors.pink, delay = 1 },
- engineMotorPull = { color=colors.lightGray, delay= 1.3 },
- headMiningBreaker = { color = colors.blue, delay = 0.35 },
- kill = { color = colors.green }
- }
- function redclear()
- rs.setBundledOutput(side,0)
- end
- function redset(color)
- rs.setBundledOutput(side,color)
- end
- function forward()
- redpulse( colMap.fwdDeployer )
- local check = false
- while not check do
- redpulse(colMap.engineMotorPush)
- redpulse(colMap.engineMotorPull)
- redpulse(colMap.battery)
- for i = 1, 5, 1 do
- if redtest(colMap.checkForward.color) then
- check = true
- delay(1)
- end
- if check then break end
- delay(0.5)
- end
- end
- redpulse( colMap.fwdBreaker )
- return "#END"
- end
- function redadd(color)
- --print("add " .. color )
- local nCol = colors.combine( rs.getBundledOutput( side ), color )
- rs.setBundledOutput(side,nCol)
- end
- function reddel(color)
- --print("sub " .. color )
- local nCol = colors.subtract( rs.getBundledOutput( side ), color )
- rs.setBundledOutput(side,nCol)
- end
- function redtest(color)
- return colors.test( rs.getBundledInput( side ), color )
- end
- function delay(delayt)
- funcState.timer = os.startTimer( delayt * 5 )
- coroutine.yield("a")
- end
- function redpulse(opts)
- redadd(opts.color)
- delay( opts.delay )
- reddel(opts.color)
- delay(rsDelay)
- end
- function mineHeadLeft()
- redpulse(colMap.headSliderBreaker)
- redpulse(colMap.headSliderLeft)
- end
- function mineHeadRight()
- redpulse(colMap.headSliderDeployer)
- redpulse(colMap.headSliderRight)
- end
- redclear()
- function runLeft()
- while not redtest(colors.white) do
- mineHeadLeft()
- end
- return "#END"
- end
- funcState.func = runLeft
- function mine()
- local tCol = colMap.checkColRight.color
- local cFunc = mineHeadRight
- if not funcState.dir then tCol = colMap.checkColLeft.color cFunc = mineHeadLeft end
- local counter = 0
- while not redtest(tCol) do
- redpulse(colMap.headMiningBreaker)
- cFunc()
- counter = counter + 1
- if counter > 20 then error("ERROR: Mine head too far/broken") end
- end
- redpulse(colMap.headMiningBreaker)
- return "#END"
- end
- function funcDo()
- while true do
- if redtest(colMap.kill.color) then return end
- local res = funcState.func()
- if res == "#END" then
- redclear()
- if funcState.func == runLeft then
- funcState.dir = true
- funcState.func = mine
- elseif funcState.func == mine then
- print("mine end")
- funcState.func = forward
- elseif funcState.func == forward then
- funcState.func = mine
- funcState.dir = not funcState.dir
- end
- end
- delay(rsDelay)
- end
- end
- local funcCo = coroutine.create(funcDo)
- function timerCallback(ev,p1)
- if redtest( colMap.kill.color) then return end
- if p1 == funcState.timer then
- funcState.timer = nil
- coroutine.resume(funcCo)
- end
- end
- events.registerEvent("timer",timerCallback)
- coroutine.resume(funcCo)
- while true do
- if redtest(colMap.kill.color) then return end
- coroutine.yield()
- end
Advertisement
Add Comment
Please, Sign In to add comment