50 posts
Location
South Africa
Posted 15 June 2012 - 11:44 AM
Is it possible to recognise the length of a redstone pulse? So in other words if a pulse is received for 3 seconds it will recognise and translate that as say for example a word and if its shorter it wont print/recognise it?
If thats possible how would you code the computer to translate the pulse?
510 posts
Posted 15 June 2012 - 12:40 PM
Well, you could periodically check for redstone activity. Like:
-- wait for pulse
while not redstone.getInput(side) do
sleep(0.5)
end
-- count on time
local duration = 0
while redstone.getInput(side) do
duration = duration + 0.5
sleep(0.5)
end
-- duration now holds the pulse length in seconds.
However, if you simply want to communicate between computers, you should use wireless modems and the rednet api.
134 posts
Location
Salt Lake, UT
Posted 15 June 2012 - 04:26 PM
Im confused why everyone uses redstone and not rednet… Rednet is so much easier… Check out the api at the wiki. It will save your life
1604 posts
Posted 15 June 2012 - 05:23 PM
The best way to do it would be with "redstone" events:
local sSide = "left"
local bPulseOn = false
local nStart
while true do
os.pullEvent("redstone")
if rs.getInput(sSide) ~= bPulse then
if bPulseOn then
local duration = os.clock() - nStart
bPulseOn = false
print("Pulse duration: ", duration)
else
nStart = os.clock()
bPulseOn = true
end
end
end
It's efficient and will give you the pulse duration in milliseconds.
Im confused why everyone uses redstone and not rednet… Rednet is so much easier… Check out the api at the wiki. It will save your life
Rednet is for communication between computers, redstone is for redstone input and output, and it's usefull to "communicate" with other mods or things that work with redstone. They are two different things.