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

Activating a command by adding a redstone current?

Started by Deo3560, 08 October 2012 - 10:47 PM
Deo3560 #1
Posted 09 October 2012 - 12:47 AM
I have worked for a tiny bit on Computercraft when trying to make a Elevator (with a call back). For example, all I needed to do was type 3-2 which the elevator is called up to floor 3 and brings me to floor 2 and then goes back down to the bottom floor. I want to see if I can make this simpler by only the use of a button.

Is there a way to activate and run a program by sending a redstone current to the computer?
I'd like to place buttons on the walls on my elevator, when I press the button (a sign will say 2) the elevator would go up to floor 2 (framemotors).
I'm a novice at this and wrote a code for each floor 1-2, 1-3, 1-4, 2-1, 2-2, etc.

So by pressing the button it reaches the computer(say the left side) it activates a program that makes the elevator work so there is NO typing a command to get it to work, as the button does it for you.

Is this possible? If so, please share how you do it.
Thanks
faubiguy #2
Posted 09 October 2012 - 12:56 AM
you can use os.pullEvent() to wait until it recieves redstone, then check if its on, and if it is then activate the elevator.

-- put this in startup
while true do
 local event, parameter = os.pullEvent("redstone")
 if redstone.getInput("left") then
  shell.run("1-2")
 end
end

Also, this belongs in the Ask a Pro section.
PixelToast #3
Posted 09 October 2012 - 01:12 AM
os.pullEvent("redstone")
then an if statement checking if the redstone is on
EDIT:
:D/>/>
Deo3560 #4
Posted 09 October 2012 - 01:13 AM
awesome , this is a big help!
Mads #5
Posted 09 October 2012 - 04:22 PM
General use of eventlistener:


local pullEvent = os.pullEventRaw
local e, p1, p2, p3, p4, p5 = pullEvent(--[[ filter. None means no filter ]])
-- Handle event. Example of a simple key press handler:
if e == "key" then
  print(p1 .. " = " .. string.char(p1))
end