4: BASIC Stamp Architecture – Defining Arrays
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 51
The above example will create a bit-sized variable called Mouse, and
nibble-sized variable called Cat, a byte-size variable called Dog and a
word-sized variable called Rhino. Unlike in the BS1, these variable
declarations don't point to a specific location in RAM. Instead, we only
specified the desired size for each variable; the BASIC Stamp will arrange
them in RAM as it sees fit. Throughout the rest of the program, we can
use the names Mouse, Cat, Dog and Rhino to set or retrieve the contents of
these variables.
A variable should be given the smallest size that will hold the largest
value that will ever be stored in it. If you need a variable to hold the
on/off status (1 or 0) of switch, use a bit. If you need a counter for a
FOR…NEXT loop that will count from 1 to 100, use a byte. And so on.
If you assign a value to a variable that exceeds its size, the excess bits will
be lost. For example, suppose you use the nibble variable Dog, from the
example above, and write Dog = 260 (%100000100 binary). What will Dog
contain? It will hold only the lowest 8 bits of 260: %00000100 (4 decimal).
On the BS2, BS2e, BS2sx and BS2p, you can also define multipart variables
called arrays. An array is a group of variables of the same size, and
sharing a single name, but broken up into numbered cells, called elements.
You can define an array using the following syntax:
Name VAR Size(n)
where Name and Size are the same as described earlier. The new argument,
(n), tells PBASIC how many elements you want the array to have. For
example:
MyList VAR BYTE(10) ' Create a 10-byte array.
Once an array is defined, you can access its elements by number.
Numbering starts at 0 and ends at n–1. For example:
MyList(3) = 57
DEBUG ? MyList(3)
This code will display "MyList(3) = 57" on the PC screen. The real power of
arrays is that the index value can be a variable itself. For example:
1
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
D
EFINING
A
RRAYS
.
Содержание BASIC Stamp 2e
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...