BASIC stamp manual v2.2
BASIC Stamp Architecture – PIN Symbols
Page 100 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
the Condition argument in the IF…THEN statement will always evaluate to
false because signal is a constant equal to 1, and “1 = 0” is false. What the
user really meant to happen is something like: IF IN1 = 0 THEN Wait
because IN1 is the input variable representing the current state of I/O pin
1. This situation is perfect for the PIN directive:
' {$PBASIC 2.5}
signal PIN 1 ' pin-type symbol representing I/O 1
INPUT signal ' set signal pin to input
Wait:
IF signal = 0 THEN Wait ' wait until signal = 1
We only changed one thing in this code: the CON directive was changed
to PIN. Now signal is a context-sensitive symbol that will be treated as a
constant or as a variable depending on where it is used. In the INPUT
command signal is used as the Pin argument, and since that argument
requires a number representing the pin number, signal is treated as a
constant equal to 1. In the IF…THEN statement, signal is compared to
another value (which implies that what signal represents is expected to
change at run-time; i.e.: signal’s value is “variable”) so signal is treated as a
variable equal to the input variable for the defined pin (IN1 in this case).
As another example, consider the following code:
' {$PBASIC 2.5}
signal CON 2 ' constant-type symbol representing I/O 2
OUTPUT signal ' set signal pin to output
signal = 1 ' set signal high
Here, again, this is a common bug; the OUTPUT command will work as
expected, but the signal = 1 statement generates a syntax error at compile-
time. Why the error? This is an assignment statement, meant to assign the
value 1 to the item on the left, but the item on the left is a constant, not a
variable, so it can not be changed at run-time. What the user was thinking
when writing this was: OUT2 = 1 which sets the value of the output
variable representing I/O pin 2 to logical 1 (high). Here’s the solution:
All
2