Jump to content

Computercraft - command to switch certain bundled lines


Stevolution

Recommended Posts

Hi

I have a computer controlling a lift over 3 floors.

I am trying to get the Bundled cable output to switch on and off only certain colors.

I'm Wiki'd out here.

rs.setBundledOutput("back", color.white, true).

This works fine, as it does with any other color, or when you add colors e.g color.white+color.cyan

However, I need to switch off certain colors and keep others on.

I was under the impression that I could do the following (but obviously not... it doesn't work)..

So to switch on only white and cyan...

rs.setBundledOutput("Back",513, 1)

Where 512 is the color of Cyan and 1 is the color of white - hence 513.

All other colors would turn off.

The 1 and 0 at the end of the command work fine as the true/false statement.

Anyone?

(and where are the programs listings stored? - just so I can copy/paste them if needed)

Link to comment
Share on other sites

The syntax is a bit wrong. It does not accept the 0/1 at the end.

rs.setBundledOutput("back", 513) should do the trick. What you can do, then, is replace the number in the command with an integer variable, like "state", and then set the state to whatever you want by adding or removing color indexes as integers. I.e:

state = 0

[Command to turn white on]:

state = state + 1

[Command to turn cyan on]:

state = state + 512

 

rs.setBundledOutput("back", state)

Of course, this method is very clunky and gets problematic if you run this in a loop (since if you write it wrong, you will keep adding integers to your value indiscriminately), but as far as I know, this is the fastest way to handle states using CC.

[EDIT]: For loops, setting the state to 0 before rechecking all colors could do the trick.

Link to comment
Share on other sites

You dont need to use the magic number there is an object color which has all the number as static attributes.

rs.setBundledOutput("back", rs.getBundledOutput() +color.Cyan) would switch on the cyan channel

rs.setBundledOutput("back", rs.getBundledOutput() -color.Cyan) would switch the cyan channel off.

Link to comment
Share on other sites

Unlike the above poster, I suggest you DO use the magic number. Write a little subscript that reads in the wire you want to change as input, and then reads the current state of every other wire, adds up all their numbers (or not, if they're off), and then adds in (or not) the wire you care about, then sets the output to the final result.

At the end of the day youll have a function that changes a specified wire and keeps everything else doing what it was already doing (on or off).

This would be much easier to write with the raw numbers since you can just do loops and stuff like 2^(loop index) etc.

Link to comment
Share on other sites

I am still getting my head around this Lua coding. This is my first proper go.

No laughing.....

term.clear()

print "      Lift Control"

print " "

redstone.setBundledOutput("back", 0)

local mon = peripheral.wrap("right")

mon.clear()

mon.setTextScale(1)

 

sleep(2)

 

print "                System ready"

mon.setCursorPos(2,1)

mon.write "NI Lift Control"

 

while true do

 

while true do

sleep(0)

  local event = os.pullEvent()

  if event == "redstone" then

  break

  end

end

 

down = rs.testBundledInput ("back", colors.lightBlue)

up = rs.testBundledInput ("back", colors.magenta)

gf = rs.testBundledInput ("back", colors.orange)

 

if up == true then

  sleep(3)

  for i=1,6 do

  mon.setCursorPos(3,3)

  mon.write"Lift going up  "

  rs.setBundledOutput("back" ,513)

  sleep(.5)

  rs.setBundledOutput("back" ,512)

  sleep(.5)

end

 

elseif

 

  down == true and gf == false then

  sleep(3)

  for i=1,6 do

  mon.setCursorPos(2,3)

  mon.write"Lift going down  "

  rs.setBundledOutput("back" ,768)

  sleep(.5)

  rs.setBundledOutput("back" ,512)

  sleep(.5)

  end

end

 

rs.setBundledOutput("back" ,0)

term.setCursorPos(14,6)

print"                                        "

mon.setCursorPos(2,3)

mon.write"                "

end

It works fine. Just needs tiding up.

I know I have different methods of checking the inputs etc. It is all part of the learning curve.

The first little routine basically waits for a change in the Bundled Input... and this method certainly seems to stop the horrific lag I suffered through other methods.

The routine is controlling my lift. 2x push buttons on each floor for up and down, and then 2 outputs for the up and down frame motors.

The cyan cable goes to an alarm which sounds during movement.

The 'gf' (on the orange cable) is a ground floor sensor (there will be one at the top as well). This is to stop you calling the lift down, when its already at the bottom.

However.... I can't find a good way of getting a redstone signal when the lift has reached ground floor.

First effort - a bare redstone cable in the wall at the bottom. I mounted a redstone torch on the side of the frame lift (on a panel), but it just pops off when the lift moves.

If you put it on a cover, then it stops the lift moving (bloody frames).

So then I put a daylight sensor in the wall through a NOR gate to give a signal when the lift was blocking the light. Works fine if you block the hole with a block... but frames with covers don't act like blocks and do not cut out the light for some reason to the light sensor.

Any suggestions on detecting position?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...