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

Door Switch

Started by RaZPuTiN42, 31 August 2012 - 02:28 PM
RaZPuTiN42 #1
Posted 31 August 2012 - 04:28 PM
I'm having a problem working something out. I'm quite sure it's not very complicated, I'm just kinda new to computercraft.
I've made a piston controled 3x3 door, and a program for closing and opening it. This went without a hitch.
However, I want to burrow the computer underground, and connect it to a button on the outside, so that when you hit the button, the door opens. I've tried using a "while true do" command and pulling on the redstone event. This works for the first time the button is pushed. If I tried restarting the program at the end of itself, it no longer stoped to wait for a redstone input, and just kept opening. Thus, I would have to manually restart the program to make the design work, and I want this to funciton automatically.
Please help :)/>/>

Edit:
I simulated the sitaution with a redstone lamp for experimentation, and the program looks like this (and is ofcourse saved as startup)

event, back = os.pullEvent()

if event == "redstone" then

shell.run("on")
sleep(2.0)
shell.run("off")
os.reboot()

else
os.reboot()
end
Kolpa #2
Posted 31 August 2012 - 06:08 PM
I'm having a problem working something out. I'm quite sure it's not very complicated, I'm just kinda new to computercraft.
I've made a piston controled 3x3 door, and a program for closing and opening it. This went without a hitch.
However, I want to burrow the computer underground, and connect it to a button on the outside, so that when you hit the button, the door opens. I've tried using a "while true do" command and pulling on the redstone event. This works for the first time the button is pushed. If I tried restarting the program at the end of itself, it no longer stoped to wait for a redstone input, and just kept opening. Thus, I would have to manually restart the program to make the design work, and I want this to funciton automatically.
Please help :)/>/>

Edit:
I simulated the sitaution with a redstone lamp for experimentation, and the program looks like this (and is ofcourse saved as startup)

event, back = os.pullEvent()

if event == "redstone" then

shell.run("on")
sleep(2.0)
shell.run("off")
os.reboot()

else
os.reboot()
end

do this:

while true do
event, back = os.pullEvent()
if event == "redstone" then
shell.run("on")
sleep(2.0)
shell.run("off")
os.reboot()
else
os.reboot()
end
end
RaZPuTiN42 #3
Posted 31 August 2012 - 06:33 PM
Thank you! Although your solution didn't solve my problem, it led me to realise what the problem was, so I managed to solve it myself :)/>/>
The problem was that the "off" event that put of the redstone output was too quickly followed by the restart, so that the program managed to pull another redstone event. Putting a sleep(1.0) after shell.run("off") solved that problem.
Kolpa #4
Posted 31 August 2012 - 07:48 PM
well you didn't show me the programms right … anyways try doing it like this its way more clean:

function pulse(s,si)
  rs.setOutput(si,"true")
  sleep(s)
  rs.setOutput(si,"false")
end
while true do
  event, back = os.pullEvent()
	if event == "redstone" then
	  pulse(seconds,"side") -- put the amount of time and the side for the redstone pulse
  end
end