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

redstone help needed

Started by DTM450, 03 April 2014 - 08:54 AM
DTM450 #1
Posted 03 April 2014 - 10:54 AM
Hi
Im trying to get an advanced computer to accept a redstone pulse from the bottom of the computer and then send 3 short redstone pulses out the right side of the comp I know how to use the rs.setOutput() command and the rs.getInput() however i cant get the Os.pullEvent to work can anyone help? there was a redstone basic tutorial that i used to try and get it working but it doesn't quite work the way i want it to here but that one works when there is a constant redstone signal not just a single pulse

i also want to use a loop function so i dont have to have repeated lines of code.
CometWolf #2
Posted 03 April 2014 - 06:33 PM
Throw up your code and we can point out what's wrong. You have to keep in mind that os.pullEvent reacts to any redstone changes, but it dosen't specify where it happened. You'll have to manually check the current state of the redstone when you get the event.
DTM450 #3
Posted 04 April 2014 - 01:12 AM
ok so my code is

os.pullEvent("redstone") do
   if rs.getInput("bottom") then
	  rs.setOutput("right",true)
	  sleep(0.3)
	  rs.setOutput("right",false)
   end
end
Im not sure if Im using the Os.pullEvent function right
I also want to loop the output true/false bit of the code so that it runs 3 times

ok so i was using Os.pullEvent instead of os.pullEvent I changed that in the code, that removed the error i was getting now i just need to loop the setOuput bit which im having trouble with
Edited on 04 April 2014 - 01:01 AM
DTM450 #4
Posted 04 April 2014 - 05:29 AM
ok so i figured out how to get the loop working correctly here is my revised program

count = 1 -- loop condition
while (true) do
os.pullEvent("redstone")
  if rs.getInput("bottom") then
    for count = 1, 3, 1 do
	  -- print(count)
	  rs.setOutput("right",true)
	  sleep(0.2)
	  rs.setOutput("right",false)
	  sleep(0.1)
    end
  end
end
CometWolf #5
Posted 04 April 2014 - 06:08 AM
You don't need to declare the count variable on the first line, it's declared locally when the loop starts.
DTM450 #6
Posted 04 April 2014 - 06:41 AM
ok cool thanks