This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Uch1ha_Sasuke's profile picture

(Qeustion using a timing)

Started by Uch1ha_Sasuke, 08 June 2012 - 12:31 PM
Uch1ha_Sasuke #1
Posted 08 June 2012 - 02:31 PM
I am using a redsotne cable that is connected to my computer or a bundled cable.
So my script goes as follows

if rs.testBundledInput("left",colours.black) then
print("Induction furnace is running")
end

So it works fine and all but,
as i am using the Eu detector cable at the bottom of my Induction furnace so that when Eu is
flowing through it emits a signal to my computer.
however to keep the furnace running at 100% heat it every now and then requires a burst of Eu.
And i dont want my Computer to display "Induction furnace is on" everytime it just gets redsonte for 1
second.
I think i have a selution to my problem but dont know how to script it so what better place to ask for help than here.

I was thinking of maing it if the computer receives a signal for 3 second or more it should
print("Inductionfurnace is running")
oherwise it should desplay nothing.

Any script that might be used for this?
please help
Sasuke
xuma202 #2
Posted 08 June 2012 - 06:07 PM
Ok what you have to check is simple you have to only execute the code if the input is not triggering. So what you can do is that:


if rs.testBundledInput("left", colors.black) then
  //Ok signal is on
  sleep(3)
  if rs.testBundledInput("left", colors.black) then
	//Signal is still on
	print("Induction furnace is running")
  end
end

You may have to change the delay time. Another way of doing it is to start a loop that constantly checks whether the signal is still on and if so for at least n milliseconds print the line.
In code it will look like so:


if rs.getBundledInput("left", colors.black) then
  i = os.clock()
  on = true
  while on do
   on = rs.getBundledInput("left", colors.black)
	if (os.clock() - i) >= 3000 then
	  on = false
	  print("Induction furnace running")
	end
    sleep(0.1)
  end
end

Keep in mind this code is untested! But it should work.
Lyqyd #3
Posted 08 June 2012 - 06:51 PM
Here's another way of doing it:


local inputSide = "right"

while true do
    e, p1 = os.pullEvent()
    if e == "redstone" then
        if rs.getInput(inputSide) then
            runTimer = os.startTimer(3)
        else
            runTimer = nil
        end
    elseif e == "timer" then
        if p1 == runTimer then
            print("Furnace is running!")
        end
    end
end

Any interruptions in the redstone signal between the start of the timer and the end will cause the timer check to fail, so we know that it was continuously on for three seconds rather than just on at the start of the three seconds and on also at the end of three seconds. This code assumes only one redstone input.
MysticT #4
Posted 08 June 2012 - 06:55 PM
Well, I don't know why you made two posts with the same question, but here's a link to the other one, where I already answered this: link
Lyqyd #5
Posted 08 June 2012 - 07:01 PM
Well, I don't know why you made two posts with the same question, but here's a link to the other one, where I already answered this: link

Heh. I saw this post first as I was going through the new topics. Interesting that we came up with identical solutions independently. Yours does, however, account for multiple inputs, while mine does not.