Shop OBEX P1 Docs P2 Docs Learn Events
Reading an output state on a BS2 — Parallax Forums

Reading an output state on a BS2

jeff2.0jeff2.0 Posts: 24
edited 2010-11-01 08:48 in BASIC Stamp
I am trying to read the value of an output on a BS2.

Reading an input is easy. Here is an example.

IF IN0 = 1 THEN (something)

......but how can I read the value of an output? Can I do it with an IF/THEN statement?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-31 22:09
    The input register (INS / INn) reflects the current state of all I/O pins including the ones set as outputs. If you set I/O pin 3 as an output and make it high, the value of IN3 will be 1. If you make pin 3 low, IN3 will be 0.

    You can also refer to OUTn to see what the I/O pin is supposed to be (if it's indeed an output).

    All of the I/O registers (INS / OUTS / DIRS) and their individual pieces are considered to be variables so you can set and test their values like any other variable. In the case of INS, you can't actually set its value since it's set from the state of the I/O pins.
  • jeff2.0jeff2.0 Posts: 24
    edited 2010-10-31 22:21
    Ahh, I get it.
    Thanks Mike.
    j
  • ercoerco Posts: 20,256
    edited 2010-11-01 08:48
    Mike states it all so accurately and eloquently. I'm from the deep south; I'm far less PC and far more direct. I would have said:

    You ASK an input what it is. It can change at any time.
    You TELL an output what it is. It stays that way until your program changes it.
Sign In or Register to comment.