Shop OBEX P1 Docs P2 Docs Learn Events
SXB pin state read / write... — Parallax Forums

SXB pin state read / write...

FORDFORD Posts: 221
edited 2007-04-29 19:28 in General Discussion
Hi all,

I would like to read the state of an input·pin, and immediately put it inverted onto an output pin.

something like...

output <> input

what is the correct way to do this in sxb ?
i have tried a few methods, and get syntax type errors.
i dont want to have to resort to if/then statements etc.

any help appreciated.

cheers,
Chris Anderson
Western Australia
·

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-04-29 13:39
    Give this a try, Chris:

      INPUT ioPin
      newState = ~ioPin
      ioPin = newState
      OUTPUT ioPin
    
    



    I tried moving the inverted input directly to the output register but it doesn't compile as expected -- use a bit variable for temporary storage of the new state.

    Post Edited (JonnyMac) : 4/29/2007 1:44:03 PM GMT
  • FORDFORD Posts: 221
    edited 2007-04-29 13:47
    thanks Jon,

    will try that tomorrow...

    about top post another question if you wouldnt mind looking at it, i'm not at work, so cant check it myself (no tools here at home).

    cheers, chris.
  • BeanBean Posts: 8,129
    edited 2007-04-29 15:48
    Chris,
    Is the input pin and the output pin the same pin ? Jon code makes that assumption.
    If they are different pins then just use "OutPin = ~InPin"

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"

    Benjamin Franklin
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 9,214
    edited 2007-04-29 19:28
    Oi... I could have sworn that he wanted the same pin (that's what I get for working so early on a Sunday...), but looking at it now I think you're right, Terry. Chris, this will work:

    outPin = ~inPin
    



    And it turns out it will work fine in either case -- whether you're using the same pin or not. If using the same pin you'll need to deal with the output state after; if those pins (when using two) have previously been declared then you just need the one line.

    Post Edited (JonnyMac) : 4/29/2007 7:33:02 PM GMT
Sign In or Register to comment.