Specifications

BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 287
2
Output
OUTPUT
pin
Make the specified pin an output (write a 1 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 output. When a program be-
gins, all of the BS2’s pins are inputs. Output instructions (Pulsout, High,
Low, Serout, etc.) automatically change the specified pin to output and
leave it in that state. Writing 1s to particular bits of the variable DIRS
makes the corresponding pins outputs. And then there’s the Output
instruction.
When a pin is an output, your program can change its state by writing
to the corresponding bit in the OUTS variable. For example:
OUTPUT 4
OUT4 = 1 ' Make pin 4 high (1).
When your program changes a pin from input to output, whatever
state happens to be in the corresponding bit of OUTS sets the state of
the pin. To simultaneously make a pin an output and set its state use
the High and Low instructions.
Demo Program
This program demonstrates how the input/output direction of a pin is
determined by the corresponding bit of DIRS. To set up the demo, con-
nect a 10k resistor from +5V to P7 on the BS2. The resistor to +5V puts
a high (1) on the pin when it’s initially an input. The BS2 then over-
rides this state by writing a low (0) to bit 7 of OUTS and executing
Output 7.
input 7 ' Make pin 7 an input.
debug "State of pin 7: ", bin IN7,cr
OUT7 = 0 ' Write 0 to output latch.
debug "After 0 written to OUT7: ",bin IN7,cr
OUTPUT 7 ' Make pin 7 an output.
debug "After pin 7 changed to output: ",bin IN7