5: BASIC Stamp Command Reference – SERIN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 279
communication) to interpret the values as necessary. In this case, perhaps
we actually wanted SerData to end up with the value 1, rather than the
ASCII code 49.
The SERIN command provides a formatter, called the decimal formatter,
which will interpret this for us. Look at the following code:
Symbol SerData = B0
SERIN 1, N2400, #SerData
--or--
SerData VAR BYTE
SERIN 1, 16780, [DEC SerData]
Notice the decimal formatter in the SERIN command. It is the “#” (for the
BS1) or “DEC” (for the other BASIC Stamps) that appears just to the left of
the SerData variable. This tells SERIN to convert incoming text
representing decimal numbers into true-decimal form and store the result
in SerData. If the user running the terminal software pressed the "1", "2"
and then "3" keys followed by a space or other non-numeric text, the value
123 will be stored in SerData. Afterwards, the program can perform any
numeric operation on the number just like with any other number.
Without the decimal formatter, however, you would have been forced to
receive each character (“1”, “2” and “3”) separately, and then would still
have to do some manual conversion to arrive at the number 123 (one
hundred twenty three) before you can do the desired calculations on it.
The decimal formatter is designed to seek out text that represents decimal
numbers. The characters that represent decimal numbers are the
characters “0” through “9”. Once the SERIN command is asked to use the
decimal formatter for a particular variable, it monitors the incoming serial
data, looking for the first decimal character. Once it finds the first decimal
character, it will continue looking for more (accumulating the entire multi-
digit number) until is finds a non-decimal numeric character. Keep in
mind that it will not finish until it finds at least one decimal character
followed by at least one non-decimal character.
D
ECIMAL FORMATTER SPECIFICS
.
1
2
e
2
sx
2
p
2
T
HIS IS WRITTEN WITH THE
BS2'
S
B
AUD
M
ODE VALUE
. B
E SURE TO
ADJUST THE VALUE FOR YOUR
BASIC
S
TAMP
.
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...