[Question] Redstone input
#1
Posted 11 January 2013 - 04:55 PM
first timer at computer-craft
so it might be a stupid question
is it possible for to have a redstone signal as an input and start a program?
what i want to do is send a redstone signal to the computer and the computer picks up the signal from front side or the back side and it starts a program that opens or closes the door
#2
Posted 11 January 2013 - 05:02 PM
take a look at the os API, mainly at the os.pullEvent function, redstone API and the shell api, mainly shell.run
EDIT: apis page http://computercraft...e=Category:APIs
Edited by TheOriginalBIT, 11 January 2013 - 05:03 PM.
#3
Posted 11 January 2013 - 05:09 PM
but for the redstone api which function do i use?
#4
Posted 11 January 2013 - 05:13 PM
if redstone.getInput("front") then
do stuff
end
Just do the same for the back, but changing front for back
#5
Posted 11 January 2013 - 05:20 PM
if redstone.getInput("front") then
redstone.setOutput("left", true)
sleep(2)
redstone.setOutput("right", true)
end
if redstone.getInput("back") then
redstone.setOutput("left", false)
sleep(2)
redstone.setOutput("right", false)
end
like this?
#6
Posted 11 January 2013 - 05:24 PM
SMD, on 11 January 2013 - 05:20 PM, said:
if redstone.getInput("front") then
redstone.setOutput("left", true)
sleep(2)
redstone.setOutput("right", true)
end
if redstone.getInput("back") then
redstone.setOutput("left", false)
sleep(2)
redstone.setOutput("right", false)
end
like this?#7
Posted 11 January 2013 - 05:25 PM
#9
Posted 11 January 2013 - 05:35 PM
i have another question how do i set it so it wait for the signals and doesn't terminate the program?
the too long without yielding
#10
Posted 11 January 2013 - 05:35 PM
i suggest adding this just after the while true do
os.pullEvent("redstone")
alternatively you could do this
sleep(0)
however using this, means that it will constantly be running and checking and wasting resources on your non-cc computer... using os.pullEvent("redstone") means that it wont run UNTIL it gets a redstone signal
Edited by TheOriginalBIT, 11 January 2013 - 05:37 PM.
#11
Posted 11 January 2013 - 05:42 PM
TheOriginalBIT, on 11 January 2013 - 05:35 PM, said:
i suggest adding this just after the while true do
os.pullEvent("redstone")
alternatively you could do this
sleep(0)
however using this, means that it will constantly be running and checking and wasting resources on your non-cc computer... using os.pullEvent("redstone") means that it wont run UNTIL it gets a redstone signal
while true do
e = os.pullEvent()
if e = "redstone" then
do stuff
end
end
end
#12
Posted 11 January 2013 - 05:47 PM
Heracles421, on 11 January 2013 - 05:42 PM, said:
TheOriginalBIT, on 11 January 2013 - 05:35 PM, said:
i suggest adding this just after the while true do
os.pullEvent("redstone")
alternatively you could do this
sleep(0)
however using this, means that it will constantly be running and checking and wasting resources on your non-cc computer... using os.pullEvent("redstone") means that it wont run UNTIL it gets a redstone signal
while true do e = os.pullEvent() if e = "redstone" then do stuff end end
end
Edited by TheOriginalBIT, 11 January 2013 - 05:47 PM.
#13
Posted 11 January 2013 - 05:50 PM
while true do
os.pullEvent("redstone")
if redstone.getInput("front") then
redstone.setOutput("left", true)
sleep(2)
redstone.setOutput("right", true)
end
if redstone.getInput("back") then
redstone.setOutput("right", false)
sleep(2)
redstone.setOutput("left", false)
end
end
this is this code i made with your all helpplease point out mistakes or places that i can improve if you can
#14
Posted 11 January 2013 - 05:50 PM
TheOriginalBIT, on 11 January 2013 - 05:47 PM, said:
Heracles421, on 11 January 2013 - 05:42 PM, said:
TheOriginalBIT, on 11 January 2013 - 05:35 PM, said:
i suggest adding this just after the while true do
os.pullEvent("redstone")
alternatively you could do this
sleep(0)
however using this, means that it will constantly be running and checking and wasting resources on your non-cc computer... using os.pullEvent("redstone") means that it wont run UNTIL it gets a redstone signal
while true do e = os.pullEvent() if e = "redstone" then do stuff end end
end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











