Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- currentLevel = 1
- maxLevel = 0
- findLevel = 15
- currentLevelInput = "back"
- goUpInput = "left"
- goDownInput = "right"
- callInput = "front"
- clutchOutput = "top"
- updownOutput = "bottom"
- currentLevelData = 0
- goUpDataRaw = 0
- goUpData = false
- goDownDataRaw = 0
- goDownData = false
- callData = 0
- clutchOutputData = 15
- updownOutputData = 0
- function updateData()
- currentLevelUpdate()
- currentCalldataUpdate()
- end
- function currentLevelUpdate()
- currentLevelData = redstone.getAnalogInput(currentLevelInput)
- if currentLevelData ~= 0 then
- currentLevel = currentLevelData
- end
- end
- function currentCalldataUpdate()
- callData = redstone.getAnalogInput(callInput)
- goUpData = (goUpDataRaw > 1)
- goDownData = (goDownDataRaw > 1)
- goUpDataRaw = redstone.getAnalogInput(goUpInput)
- goDownDataRaw = redstone.getAnalogInput(goDownInput)
- if callData ~= 0 then
- findLevel = callData
- callData = 0
- elseif goUpData and goUpDataRaw == 0 then
- findLevel = findLevel + 1
- goUpData = false
- if findLevel > 15 then
- findLevel = 15
- end
- elseif goDownData and goDownDataRaw == 0 then
- findLevel = findLevel - 1
- goDownData = false
- if findLevel < 1 then
- findLevel = 1
- end
- end
- end
- function moveStop()
- -- redstone.setAnalogOutput(clutchOutput, 15)
- clutchOutputData = 15
- end
- function moveDown()
- if findLevel ~= currentLevel then
- -- redstone.setAnalogOutput(updownOutput, 0)
- -- redstone.setAnalogOutput(clutchOutput, 0)
- updownOutputData = 0
- clutchOutputData = 0
- end
- end
- function moveUp()
- if findLevel ~= currentLevel then
- -- redstone.setAnalogOutput(updownOutput, 15)
- -- redstone.setAnalogOutput(clutchOutput, 0)
- updownOutputData = 15
- clutchOutputData = 0
- end
- end
- function calibrate()
- -- currentLevel = 0
- -- maxLevel = 0
- -- startTime = os.time()
- -- while startTime + 600 < os.time() do
- -- redstone.setAnalogOutput(updownOutput, 0)
- -- redstone.setAnalogOutput(clutchOutput, 0)
- -- end
- -- redstone.setAnalogOutput(updownOutput, 15)
- -- redstone.setAnalogOutput(clutchOutput, 0)
- -- while true do
- -- -- Aantal verdiepingen tellen tot max input
- -- currentLevelData = redstone.getAnalogInput(currentLevelInput)
- -- if currentLevelData ~= 0 then
- -- currentLevel = currentLevelData
- -- maxLevel++
- -- end
- -- end
- repeat
- os.queueEvent("randomEvent")
- os.pullEvent()
- updateData()
- moveUp()
- redstone.setAnalogOutput(updownOutput, updownOutputData)
- redstone.setAnalogOutput(clutchOutput, clutchOutputData)
- until currentLevelData == 15
- moveStop()
- -- redstone.setAnalogOutput(updownOutput, 15)
- -- redstone.setAnalogOutput(clutchOutput, 0)
- -- currentLevelUpdate()
- end
- -- Start routine
- moveStop()
- calibrate()
- while true do
- -- term.clear()
- os.queueEvent("randomEvent")
- os.pullEvent()
- updateData()
- -- Check knop voor hoger of lager
- if findLevel ~= currentLevelData then
- if findLevel > currentLevel then
- moveUp()
- elseif findLevel < currentLevel then
- moveDown()
- else
- moveStop()
- end
- else
- moveStop()
- end
- redstone.setAnalogOutput(updownOutput, updownOutputData)
- redstone.setAnalogOutput(clutchOutput, clutchOutputData)
- term.setCursorPos(1, 1)
- print("Current level is ".. currentLevel ..", and I am going to level ".. findLevel .." ")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement