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
- A Computer (from CC:Tweaked)
- Any redstone input device — a lever, button, or pressure plate
- Any redstone output device — a door, lamp, or piston
- Redstone dust to connect them to the sides of the computer (optional if placed directly adjacent)
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
- Place a Computer in the world.
- Place a pressure plate touching the left side of the computer (or connect it with redstone dust).
- Place an iron door touching the right side of the computer.
- Right-click the computer and create a new program:
edit door.lua
-
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
- Save and exit (Ctrl → Save → Ctrl → Exit), then run the program:
door
- 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:
redstone.getInput("side")— returnstrueif the side is receiving a signalredstone.setOutput("side", true/false)— turns the output signal on or offredstone.getAnalogInput("side")— returns signal strength 0–15redstone.setAnalogOutput("side", strength)— sets analog output strength
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
- Output not working — make sure the device is on the correct side. Use
redstone.getSides()to list all side names. - Signal fires multiple times — use
os.pullEvent("redstone")instead of a polling loop to detect edge transitions cleanly. - Door opens but does not close — check that you are setting the output to
falsewhen the input drops.