122-32000 Parallax Inc, 122-32000 Datasheet - Page 197

MANUAL PROPELLER

122-32000

Manufacturer Part Number
122-32000
Description
MANUAL PROPELLER
Manufacturer
Parallax Inc
Datasheets

Specifications of 122-32000

Accessory Type
Manual
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
Propeller Education (PE) Kit
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
Enumerations (Syntax 2 and 3)
Constant Blocks can also declare enumerated constant symbols. Enumerations are logically
grouped symbols which have incrementing integer constant values assigned to them that are
each unique for the group. For example, an object may have the need for certain modes of
operation. Each of these modes can be identified by a number, 0, 1, 2 and 3, for example.
The numbers themselves don’t really matter for our purposes; they just need to be unique
within the context of the operation mode. Since the numbers themselves are not descriptive,
it may be difficult to remember what mode 3 does, but it is a lot easier to remember what the
mode means if it had a descriptive name instead. Look at the following example.
CON
The above example would suffice for our purposes; now users of our object can indicate
logical group of items this way may cause bugs and maintenance problems because if any
value was changed (on purpose or by accident) without changing the rest accordingly, it may
cause the program to fail. Also, imagine a case where there were 20 modes of operation.
That would be a much longer set of constants and even more opportunities for maintenance
issues.
Enumerations solve these problems by automatically incrementing values for symbols. We
can rewrite the above example with enumeration syntax as follows:
CON
Here,
equal to that value. Then, any additional symbols that do not specify their own value (via an
‘= expression’) are automatically assigned the previous value plus 1. The result is that
RunTest
cases, the values themselves don’t usually matter; all that matters is that they are each
assigned a unique number. Defining enumerated values like this has the advantages of
insuring that the assigned values are unique and contiguous within the group.
RunFull
'Declare modes of operation
RunTest
RunVerbose = 1
RunBrief
RunFull
#0, RunTest, RunVerbose, RunBrief, RunFull
#0
, tells the compiler to start counting from the number 0 and it sets the next symbol
equals 0,
” instead of “
'Declare modes of operation
= 0
= 2
= 3
RunVerbose
3
” to specify the desired mode of operation. The problem is, defining a
equals 1,
RunBrief
4: Spin Language Reference –
equals 2 and
Propeller Manual v1.0 · Page 197
RunFull
equals 3. For most

Related parts for 122-32000