ComputerCraft

Control redstone with a computer

Read and write redstone signals from Lua. Build automatic doors, alarms, or any redstone contraption driven by code.

What you will end up with

A CC:Tweaked computer that detects a redstone signal on one side and toggles a signal on another side — essentially a programmable repeater, timer, or gate. The same technique is used to build automatic doors, alarms triggered by pressure plates, and timed pulse generators.

What you need

Each face of the computer corresponds to a direction string in Lua: "top", "bottom", "left", "right", "front", "back". Place your devices on the matching side.

Step by step — automatic door

  1. Place a Computer in the world.
  2. Place a pressure plate touching the left side of the computer (or connect it with redstone dust).
  3. Place an iron door touching the right side of the computer.
  4. Right-click the computer and create a new program:
    edit door.lua
  5. Type the following program:
    -- door.lua -- Opens the door when pressure plate is triggered while true do local signal = redstone.getInput("left") redstone.setOutput("right", signal) os.sleep(0.1) end
  6. Save and exit (Ctrl → Save → Ctrl → Exit), then run the program:
    door
  7. Step on the pressure plate — the door opens. Step off — it closes.

How the redstone API works

CC:Tweaked exposes the redstone API for reading and writing signals on each face:

Example — timed alarm

This script pulses a bell or alarm for 2 seconds whenever the input is triggered, then resets — regardless of how long the input stays on.

-- alarm.lua -- Pulses output for 2 seconds when input is triggered while true do -- Wait for a rising edge on the "back" side os.pullEvent("redstone") if redstone.getInput("back") then redstone.setOutput("front", true) os.sleep(2) redstone.setOutput("front", false) end end
os.pullEvent("redstone") pauses the script until any redstone input changes — this is more efficient than polling in a tight loop with os.sleep().

Troubleshooting