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

Detecting Input From Bundled Cables

Started by Nikolai, 29 November 2012 - 02:15 PM
Nikolai #1
Posted 29 November 2012 - 03:15 PM
I am trying to write a program that detects whether there is any currant coming from the yellow cable in the bundle plugged into the back of the computer, and if there is, will send currant through the redstone/bundle on the left side of the machine. Could someone write a program that does this?


-Thanks
SuPeRMiNoR2 #2
Posted 29 November 2012 - 04:28 PM
This should do it.

while true do
yellowin = rs.testBundledInput("back", colors.yellow)
if yellowin == true then
rs.setOutput("left", true)
end
if yellowin == false then
rs.setOutput("left", false)
end
sleep(.1)
end

This will do the first part, but send the signal through the black line in the bundled cable conected to the back of your computer

while true do
yellowin = rs.testBundledInput("back", colors.yellow)
if yellowin == true then
rs.setBundledOutput("back", colors.black)
end
if yellowin == false then
rs.setBundledOutput("back", 0)
end
sleep(.1)
end

If you want this as part of a program you already have then you can put it in as a function like so

function readinput()
yellowin = rs.testBundledInput("back", colors.yellow)
if yellowin == true then
rs.setBundledOutput("back", colors.black)
end
if yellowin == false then
rs.setBundledOutput("back", 0)
end
sleep(.1)
end
Then everytime you want to check if the yellow line is on you can run

readinput()
And it will run the detecter program thing that I just made
whatsfast #3
Posted 29 November 2012 - 04:51 PM
Simplify his above:


function readinput()
if yellowin = rs.testBundledInput("back", colors.yellow) then
 rs.setBundledOutput("back", colors.black)
else
 rs.setBundledOutput("back", 0)
end
sleep(.1)
end
Nikolai #4
Posted 29 November 2012 - 05:30 PM
Thanks man, that really helped. Hopefully this will help prevent most nuclear meltdowns…