What allanlane5 is implying is that there are arrays in PBasic, but they cannot be automatically initialized. They're set to zero as are all variables when the Stamp is reset (like at power on). They're also very limited in that there is a grand total of 26 bytes (or 13 words) of variable space.
You can store data in the EEPROM used to store your program and you can even compile in initial data using the DATA statement. The READ/WRITE (and STORE) statements are used to access these data areas. The posted example shows a data area in EEPROM being copied into an array called MyArray. You don't have to move the whole array to variables. You can process it one value at a time. Read the sections in the PBasic manual on READ/WRITE and keep in mind that EEPROM is limited to about 100000 write operations on any one "page" of about 32 to 64 bytes. The affected locations will "wear out" eventually and become unable to be written correctly.
Well im trying to create a keyboard but i want a more efficiant way to define the keys instead of having to use serout to my lcd screen for each letter.
a:
SEROUT Lpin, Baud19200, [noparse][[/noparse]"a"]
goto main
b:
SEROUT Lpin, Baud19200, [noparse][[/noparse]"b"]
goto main
but i was hoping to use an array instead so i can just replace with the "a" or "b" with this:
SEROUT Lpin, Baud19200, [noparse][[/noparse]row1(hitkey)]
Yeah, I think you'd use the "LOOKUP" keyword to embed in your PBasic code the translation. "Use an array" is how you'd implement that in a language with WAY more RAM memory.
Please look in the PBASIC manual under LOOKUP first. Most of the statements have multiple examples and quite a bit of description, particularly the more complex statements like LOOKUP. If there's something you don't understand after reading the manual and trying it, show us what you've tried and we'll try to help.
Comments
You could do:
MyArray VAR BYTE(12) ' 0..11
I VAR NIB
DATA 1, 34, 5, 6, 4, 3, 2, 4, 6, 7, 4, 4
for i = 0 to 11
READ i, MyArray(I)
NEXT
Note that would take up half your RAM memory locations, though.
You can store data in the EEPROM used to store your program and you can even compile in initial data using the DATA statement. The READ/WRITE (and STORE) statements are used to access these data areas. The posted example shows a data area in EEPROM being copied into an array called MyArray. You don't have to move the whole array to variables. You can process it one value at a time. Read the sections in the PBasic manual on READ/WRITE and keep in mind that EEPROM is limited to about 100000 write operations on any one "page" of about 32 to 64 bytes. The affected locations will "wear out" eventually and become unable to be written correctly.
2. Then:
' {$STAMP BS2}
' {$PBASIC 2.5}
MyArray VAR Byte(12) ' 0..11
MyArray2 VAR Byte(12) ' 0..11
I VAR Nib
MyData1 DATA 1, 34, 5, 6, 4, 3, 2, 4, 6, 7, 4, 4
MyData2 DATA 1, 34, 5, 6, 4, 3, 2, 4, 6, 7, 4, 4
FOR i = 0 TO 11
READ MyData1+i, MyArray(I)
READ MyData2+i, MyArray(I)
NEXT
But -- you've now used all your 'VAR' space for arrays -- you have no RAM left over to process with.
Why do you want to do this?
Though, you mention "Keyboard", then "using serout to my LCD screen" to "define the keys". So I don't understand what's going on.
a:
SEROUT Lpin, Baud19200, [noparse][[/noparse]"a"]
goto main
b:
SEROUT Lpin, Baud19200, [noparse][[/noparse]"b"]
goto main
but i was hoping to use an array instead so i can just replace with the "a" or "b" with this:
SEROUT Lpin, Baud19200, [noparse][[/noparse]row1(hitkey)]