Datasheet

Chapter 5: Debugging and Datalogging ยท Page 213
itself that you have declared two symbols, LED_MODE, which has been set equal to one,
and
DEBUG_MODE, which has been set equal to two.
' -----[ Compiler Definitions ]----------------------------------------
#DEFINE LED_MODE = 1
#DEFINE DEBUG_MODE = 2
Most compiler directives begin with #. Examples include #DEFINE, #IF, #THEN, #ELSE,
#SELECT, and #CASE. The others begin with the dollar sign, such as $STAMP and
$PBASIC.
The
#IF...#ENDIF code block below is called a conditional compiler directive. The
condition is
LED_MODE = 1. If that's how LED_MODE was declared, then the LedSpeaker
PIN
directive will be compiled. In other words, the BASIC Stamp Editor will consider
LedSpeaker PIN 5 to be part of the program. If LED_MODE is any value other than 1,
the
LedSpeaker PIN directive would be ignored, just as comments are ignored.
' -----[ I/O Definitions ]---------------------------------------------
#IF LED_MODE = 1 #THEN
LedSpeaker PIN 5
#ENDIF
Here is a variable declaration and
DEBUG command that are not nested inside any
conditional compiler directives, so they will be part of the program regardless of the
value of
DEBUG_MODE or LED_MODE.
' -----[ Variables ]---------------------------------------------------
counter VAR Word
' -----[ Initialization ]----------------------------------------------
DEBUG CLS, "Program running...", CR, CR
Since DEBUG_MODE was declared as 2, only the command DEBUG "DEBUG_MODE = 2."
will be part of the program. Again the commands in the other
#CASE directives might as
well be comments. However, if you change
#DEFINE DEBUG_MODE = 2 to #DEFINE
DEBUG_MODE = 0 and re-run the program, only the DEBUG command in the #CASE 0
block will be compiled. The program would instead display the message
"DEBUG_MODE
is zero."