
blink
blinks a lamp on top
> examples blink > edit blink
Switches a redstone output on and off every half second, forever. It is the "hello world" of automation: the same loop drives a warning light at a train crossing, a flashing beacon on a tower, or the pulse that keeps a contraption moving.
What to build
Put a Redstone Lamp on top of the computer. Anything that reacts to redstone works in its place: a piston, a door, a note block, a Create Redstone Link set to transmit.
Run it with blink, stop it with Ctrl+T or the Stop button. When it stops, the output keeps its last value: the lamp may stay lit until another program changes it or the computer reboots or is switched off.
How it works
local side = "top"
local on = falseThe side is kept in a variable, so changing it means changing one word: "bottom", "left", "right", "front" or "back" (left and right as seen facing the screen). on remembers the current state of the lamp.
while true do
on = not on
rs.set(side, on)
sleep(0.5)
endwhile true do repeats forever. not on flips the state: false becomes true and back. rs.set() accepts true (full power, 15) or false (0), or a number from 0 to 15. With half a second on and half a second off, the lamp blinks once a second.
Redstone outputs reach the world at the end of each game tick (20 per second), and only the last value of the tick counts. Blinking faster than sleep(0.05), one tick, has no visible effect.
Ideas
- Blink faster or slower: change
0.5. Use two different delays for a short flash and a long pause:rs.set(side, true) sleep(0.1) rs.set(side, false) sleep(1.9). - Blink two lamps in turn, like a level crossing: set
"left"toonand"right"tonot on. - Blink only while a lever on the back is on: wrap the body in
if rs.get("back") > 0 then ... end, as in step 10 of the tutorial. Blink a set number of times, then stop:
Brass for i = 1, 5 do rs.set("top", true) sleep(0.5) rs.set("top", false) sleep(0.5) end print("Blinked 5 times")Blinked 5 times
- Send a strength instead of on and off:
rs.set(side, 7)gives a signal of 7, which goes 7 blocks along redstone dust and which a Create Nixie Tube shows as a number. Seersand the redstone guide.
The program
-- Blinks a redstone output. Put a redstone lamp on top of the computer.
-- Stop it with Ctrl+T or the Stop button.
local side = "top" -- also: bottom, left, right, front
local on = false
while true do
on = not on
rs.set(side, on) -- true = 15, false = 0
sleep(0.5)
end