with it? We’re going to use a conditional compilation
construct to set a constant value that will be used to scale
the raw input from PULSIN to microseconds, always
returning the correct value, regardless of which BASIC
Stamp module is being used.
#CASE BS2, BS2E
Scale CON $200
Scale CON $0CC
Scale CON $0C0
Scale CON $1E1
When we compile a program, the first thing that the
compiler does is look for conditional compilation symbols
(created with #DEFINE), then look for conditional
compilation constructs like ours above. The construct
works as we’d expect, but only at compile time. The
section that evaluates as true will get compiled into the
program; all others will be ignored.
If, for example, we had selected a BASIC Stamp 2
module, our program would compile and assign the
constant called Scale a value of $200 (same as 2.0
decimal when used with */).
Once you get used to conditional compilation, it can
be a very powerful tool. How many times have you
sprinkled DEBUG statements through a program, only
having to go rip them all out when everything is working?
With conditional compilation, you can do this:
#DEFINE DebugMode = 1
Then, in the body of the program, we add a bit of logic
around our DEBUG outputs:
#IF DebugMode #THEN
DEBUG “Program Status”
Once the program is working properly, we can turn-off
all the DEBUG statements with one small change:
#DEFINE DebugMode = 0
How much easier is this? Also, as we’ve all seen,
programs are ultimately updated. When that happens, we
don’t have to go back through and drop in DEBUG
NUTS & VOLTS
Circle #35 on the Reader Service Card.