SHOW:
|
|
- or go back to the newest paste.
| 1 | -- @param pulse length in seconds | |
| 2 | local pulseLength = 0.5 | |
| 3 | ||
| 4 | -- @param clock speed in seconds | |
| 5 | local clockSpeed = 2 | |
| 6 | ||
| 7 | -- @param pulse direction | |
| 8 | local pulseSide = "right" | |
| 9 | local inputSide = "front" | |
| 10 | ||
| 11 | -- @param redstone signal to disable clock | |
| 12 | -- true = redstone turns on | |
| 13 | -- false = redstone turns off | |
| 14 | -- nil = ignore redstone | |
| 15 | local redstone = nil | |
| 16 | ||
| 17 | while true do | |
| 18 | term.clear() | |
| 19 | print("Clock running, output " .. pulseSide .. "...")
| |
| 20 | print("T " .. pulseLength .. " / C " .. clockSpeed)
| |
| 21 | ||
| 22 | -- use redstone signal to determine if the clock is on or off | |
| 23 | while redstone ~= rs.getInput(inputSide) do | |
| 24 | rs.setOutput(pulseSide, true) | |
| 25 | sleep(pulseLength) | |
| 26 | ||
| 27 | rs.setOutput(pulseSide, false) | |
| 28 | sleep(clockSpeed - pulseLength) | |
| 29 | end | |
| 30 | ||
| 31 | -- if we dropped out of the clock loop, wait for redstone | |
| 32 | print("")
| |
| 33 | print("OFF (Waiting for redstone)")
| |
| 34 | event = os.pullEvent("redstone")
| |
| 35 | end |