Specifications
BASIC Stamp II
Page 276 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Input
INPUT
pin
Make the specified pin an input (write a 0 to the corresponding bit of
DIRS).
• Pin is a variable/constant (0–15) that specifies the I/O pin to use.
Explanation
There are several ways to make a pin an input. When a program be-
gins, all of the BS2’s pins are inputs. Input instructions (Pulsin, Serin)
automatically change the specified pin to input and leave it in that
state. Writing 0s to particular bits of the variable DIRS makes the corre-
sponding pins inputs. And then there’s the Input instruction.
When a pin is an input, your program can check its state by reading
the corresponding INS variable. For example:
INPUT 4
Hold: if IN4 = 0 then Hold ' Stay here until P4 is 1.
The program is reading the state of P4 as set by external circuitry. If
nothing is connected to P4, it could be in either state (1 or 0) and could
change states apparently at random.
What happens if your program writes to the OUTS bit of a pin that is
set up as an input? The state is stored in OUTS, but has no effect on the
outside world. If the pin is changed to output, the last value written to
the corresponding OUTS bit will appear on the pin. The demo pro-
gram shows how this works.
Demo Program
This program demonstrates how the input/output direction of a pin is
determined by the corresponding bit of DIRS. It also shows that the
state of the pin itself (as reflected by the corresponding bit of INS) is
determined by the outside world when the pin is an input, and by the
corresponding bit of OUTS when it’s an output. To set up the demo,
connect a 10k resistor from +5V to P7 on the BS2. The resistor to +5V
puts a high (1) on the pin when it’s an input. The BS2 can override this










