Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local side = "left"
- local lastFloorDetection = 0
- local directionIsUp = true
- local requestFloor = {false, false, false}
- local requestFloorColor = {colors.orange, colors.red, colors.blue}
- local detectFloorColor = {colors.lightBlue, colors.green, colors.black}
- function EnableColor(color)
- redstone.setBundledOutput(side, colors.combine(redstone.getBundledOutput(side), color))
- end
- function DisableColor(color)
- redstone.setBundledOutput(side, colors.subtract(redstone.getBundledOutput(side), color))
- end
- function ElevatorUp()
- print("Going up...")
- DisableColor(colors.white)
- end
- function ElevatorDown()
- print("Going down...")
- EnableColor(colors.white)
- end
- function GotoFloor(index)
- end
- function CheckFloors()
- for i, v in ipairs(requestFloorColor) do
- if rs.testBundledInput(side, v) then
- print("Request for floor " .. i)
- return i
- end
- end
- end
- function DetectFloor()
- for i, v in ipairs(detectFloorColor) do
- if rs.testBundledInput(side, v) then
- print("Detected elevator at floor " .. i)
- return i
- end
- end
- end
- function Calibrate()
- print("Calibration in progress...")
- ElevatorUp()
- end
- function RedstoneDetected()
- currentFloor = DetectFloor()
- if currentFloor ~= 0 then
- lastFloorDetection = currentFloor
- else
- floorIndex = CheckFloors()
- GotoFloor(floorIndex)
- end
- end
- function SimpleElevator()
- if rs.testBundledInput(side, colors.white) then
- return
- end
- print("Redstone input detected...")
- if directionIsUp then
- ElevatorDown()
- directionIsUp = false
- else
- ElevatorUp()
- directionIsUp = true
- end
- end
- print( "Press E to quit." )
- --Main code
- while true do
- local e = os.pullEvent()
- if e == "key" then
- print( "You pressed [E]. Exiting program..." )
- break
- end
- if e == "redstone" then
- SimpleElevator()
- end
- end
Add Comment
Please, Sign In to add comment