RedstoneX
I've made a useful api for more redstone things. It is called redstoneX.
Functions:
Spoiler
redstoneX.version() - returns version
usage: none
redstoneX.listen(side, timeout, sensitivity) - allows one to listen for a redstone signal
usage:
redstoneX.flash(side, timeout) - flash a signal
Usage:
redstoneX.strobe(side, freq, timeout) - strobe a signal for a certain amount of time at a certain frequency
Usage:
redstoneX.sequence(side, freqs)
Usage:
redstoneX.version() - returns version
usage: none
redstoneX.listen(side, timeout, sensitivity) - allows one to listen for a redstone signal
usage:
Spoiler
side - what side to listen on (string)
timeout - how long to wait. 0 is indefinite. If it times out, it returns false
sensitivity - how often it checks for a signal. basically, set it at some value less than the amount of time the redstone will be activated. For a button, 1 should suffice. The higher the sensitivity, the quicker the response, but the higher the cpu load.
example:side - what side to listen on (string)
timeout - how long to wait. 0 is indefinite. If it times out, it returns false
sensitivity - how often it checks for a signal. basically, set it at some value less than the amount of time the redstone will be activated. For a button, 1 should suffice. The higher the sensitivity, the quicker the response, but the higher the cpu load.
Spoiler
redstoneX.listen("left", 60, 1) --listen for 60 seconds on the left side, with a sensitivity of 1
redstoneX.flash(side, timeout) - flash a signal
Usage:
Spoiler
side - which side is flashed (string)
timeout - how long to flash
example:side - which side is flashed (string)
timeout - how long to flash
Spoiler
redstoneX.flash("left", 5) --flash the left side for 5 seconds
redstoneX.strobe(side, freq, timeout) - strobe a signal for a certain amount of time at a certain frequency
Usage:
Spoiler
side - Which side to strobe (string).
freq - How often to turn the signal on and off
timeout - How long to strobe
Example:side - Which side to strobe (string).
freq - How often to turn the signal on and off
timeout - How long to strobe
Spoiler
redstoneX.strobe("left",0.4,6) --toggle every 0.4 seconds for 6 seconds
redstoneX.sequence(side, freqs)
Usage:
Spoiler
side - side to sequence (string)
freqs - sequencing array. See example.
Example:side - side to sequence (string)
freqs - sequencing array. See example.
Spoiler
redstoneX.sequence("left", {2,0.5,1}) --turn left side on for 2 seconds, off for 0.5 seconds, on for 1 second, then off.
Code:
Spoiler
function version() return 0.01 end function listen(side, timeout, sensitivity) if timeout == 0 then while true do if redstone.getInput(side) then break end sleep(0.2) end else time=timeout/sensitivity for i=1,time do sleep(0.2) if redstone.getInput(side) then return true end end return false end end function flash(side, timeout) redstone.setOutput(side, true) sleep(timeout) redstone.setOutput(side, false) end function strobe(side, freq, timeout) time = timeout/freq/2 for i=1,time do redstone.setOutput(side, true) sleep(freq) redstone.setOutput(side, false) sleep(freq) end end function sequence(side, freqs) freqsnum = # freqs for i = 1, freqsnum do freqsmod = i%2 if freqsmod == 1 then redstone.setOutput(side, true) sleep(freqs[i]) else redstone.setOutput(side, false) sleep(freqs[i]) end end redstone.setOutput(side,false) end
Install:
Spoiler
Go to: minecraft/computercraft/lua/roms/apis
Save the attached redstoneX.txt file in that folder
Go to: minecraft/computercraft/lua/roms/apis
Save the attached redstoneX.txt file in that folder
Attached Files
-
redstoneX.txt 950bytes
59 downloads











