Repository navigation
Turntable Examples
Lycoris edited this page Nov 10, 2026
·
1 revision
local turntable = peripheral.find("loconautics:turntable_bearing")
local legs = { north = 0, east = 90, south = 180, west = 270 }
local function goTo(name)
local target = legs[name]
if not target then error("no leg called " .. name) end
turntable.turnTo(target)
repeat os.sleep(0.05) until not turntable.isTurning()
print("facing " .. name)
end
goTo("south")A turn does not finish if rotation stops, so add a timeout.
local function turn(degrees, timeoutSeconds)
turntable.turnBy(degrees)
local deadline = os.clock() + (timeoutSeconds or 30)
while turntable.isTurning() do
if os.clock() > deadline then
turntable.stop()
return false, "timed out with " ..
string.format("%.1f", turntable.getRemainingDegrees()) .. " degrees left"
end
os.sleep(0.05)
end
return true
end
local ok, err = turn(180, 20)
if not ok then print(err) endlocal function safeToCross()
local s = turntable.getState()
return s.assembled and s.settled and not s.turning
end
while not safeToCross() do os.sleep(0.1) end
redstone.setOutput("back", true) -- release the signalturntable.setInstructions({
{ type = "turn_angle", value = 90 },
{ type = "await" },
{ type = "turn_angle", value = 90 },
{ type = "end" },
})
turntable.setTrigger("pulse")
turntable.runSequence()
repeat os.sleep(0.05) until turntable.getCurrentInstruction() == 2
print("first quarter done, waiting for the go ahead")
os.pullEvent("redstone")
turntable.resume()Start here
Reading the train
- Identity
- Motion
- State
- Station
- Signals
- Track ahead
- Orientation
- World position
- Carriages
- Consist wide cargo
Driving the train
Schedules
Doors and body
Links
The whole railway
Reacting to changes
Programs and reference
Start here
Controlling the plate
Automatic modes
Reading the turntable
Reference