BASIC stamp manual v2.2
4: BASIC Stamp Architecture – PIN Symbols
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 99
expression 100+90 into a compile-time expression like OneNinety CON
100+90.
To sum up: compile-time expressions are those that involve only
constants; once a variable is involved, the expression must be solved at
run-time. That’s why the line “NotWorking CON 3 * result” would
generate an error message. The CON directive works only at compile-time
and result is a variable; variables are not allowed in compile-time
expressions.
Now we know now to create variables and constants (with VAR and
CON) but there is a third option if you’re using PBASIC 2.5; pin-type
symbols (with PIN). PIN is like VAR and CON put together and
represents an I/O pin.
There are some situations where it is handy to refer to a pin using a
variable (like IN2 or OUT2) and also as a constant (2, in this case). The
PIN directive lets you define a context-sensitive symbol representing an
I/O pin. Depending on where and how this pin-type symbol is used
determines whether it is treated as an I/O pin input variable, and I/O pin
output variable or as a constant representing the pin number.
Let’s explore a simple example to see where this is useful. It is common
practice to define constants for any number used in many places so that
changing that number doesn’t create a maintenance hassle later on. If we
were to use a constant symbol to represent an I/O pin, we might do
something like this:
' {$PBASIC 2.5}
signal CON 1 ' constant-type symbol representing I/O 1
INPUT signal ' set signal pin to input
Wait:
IF signal = 0 THEN Wait ' wait until signal pin = 1
Here we define signal to represent our desired I/O pin, then we use the
INPUT command to set it to the input direction and later we check the
state of the signal pin and loop (wait) while it is equal to logic 0. This code
has a common bug, however; the INPUT command works as expected,
because its Pin argument requires a number representing the I/O pin, but
DEFINING AND USING PINS WITH THE PIN
DIRECTIVE
.
All
2