Create: Computing AgesBrass Docs
Built-in programs

speed

drives a speed controller

Runs on All All computers · 15 lines
Type this at the prompt of a computer to copy it onto the medium:
Terminal
> examples speed
> edit speed

Drives a Create Rotation Speed Controller: the machines turn fast (128 RPM) while the left input is powered, and slowly (16 RPM) otherwise. A computer that sets speeds can save stress when a line is idle, speed up a mill when ore piles up, or slow a contraption down near the end of its travel.

What to build

  • On the right of the computer (seen facing the screen), a Rotation Speed Controller, fed by a turning shaft as usual, with the large cogwheel on top that drives your machines.
  • On the left, a lever, a button, or any redstone signal.

If the block on the right is not a peripheral, the program stops with no speed controller on the right. If it is another Create block, the first kinetic.set_speed() stops it with set_speed needs a Rotation Speed Controller.

How it works

Brass
local motor = peripheral.wrap("right")

peripheral.wrap() gives an object for the block on the right. A Create block that turns has the kinetic methods; on a Rotation Speed Controller, they include set_speed.

Brass
if rs.get("left") > 0 then
  motor.set_speed(128)
else
  motor.set_speed(16)
end

set_speed sets the target speed of the controller, in RPM, like the value on its side: up to 256 either way, a negative number turning the other way. The change reaches the world at the end of the game tick, once, with the last value asked: setting a speed in a tight loop does not flood the server.

Brass
print(motor.speed() .. " RPM")
os.pull_event("redstone")

kinetic.speed() reads the speed of the block itself. On a Rotation Speed Controller, that is the speed of the shaft that feeds it, not the target you just set. Then os.pull_event() waits, at no cost, until a redstone input changes, and the loop starts over.

Ideas

  • Use the strength of the signal: 0 to 15 mapped to 0 to 256 RPM, for a speed set with a dial such as a Create Analog Lever:

    Brass
    for _, power in ipairs({0, 1, 8, 15}) do
      local rpm = math.floor(power / 15 * 256)
      print(power, rpm)
    end
    Screen
    0   0
    1   17
    8   136
    15  256

    In the program: motor.set_speed(math.floor(rs.get("left") / 15 * 256)).

  • Slow down before it breaks: kinetic.overstressed() tells when the network is overstressed. The overstress guard recipe lowers the speed until it recovers.
  • Run the crushers faster while a vault holds a lot of ore, with inventory.count() (see stock).
  • Reverse a conveyor for a few seconds with a negative speed, then set it back.

The program

speed
-- Drives a Create machine: a Rotation Speed Controller on the right
-- turns fast while the left input is powered, slowly otherwise.
local motor = peripheral.wrap("right")
if motor == nil then
  error("no speed controller on the right")
end
while true do
  if rs.get("left") > 0 then
    motor.set_speed(128)
  else
    motor.set_speed(16)
  end
  print(motor.speed() .. " RPM")
  os.pull_event("redstone")
end