Multi-dimensional array?
m.e.
Posts: 2
I'm trying to help my spouse with a project using BS2. He needs to create a multi-dimensional array (6 x 6 x 31, each cell containing an integer). Documentation doesn't seem to go into anything beyond one dimension ... so am I right in assuming 3 dimensions are not supported, or is there a trick/workaround we might try? Also, since my day job is Web development I'm not used to the memory constraints with BS2, and I suspect this will come into play here ... so any hints in that area would also be greatly appreciated. Thanks!
Comments
There are other Stamp models with more memory, but not enough for what you want. There's a comparison page on Parallax's website that shows the different amounts (and kinds) of memory that come with each model.
The only microcontroller that Parallax has that includes enough memory would be the Propeller. While that's easy to use, it's not as easy as the Stamps and it is very different. There is a version that, with some care, can be plugged into most Stamp boards like the Board of Education (the SpinStamp).
Post Edited (Mike Green) : 2/14/2009 9:57:19 PM GMT
IF X > 200 AND X < 300 THEN Y = 2 GO TO FORMULA
IF X > 300 AND X < 400 THEN Y = 3 GO TO FORMULA
IF X > 400 AND X < 500 THEN Y = 4 GO TO FORMULA
.
.
.
[noparse][[/noparse]there can be 15 of these IF THEN combos]
.
.
FORMULA:
A = Y * B
OR
IF X > 200 AND X < 300 THEN A = 2 * B GO TO OUTPUTA
IF X > 300 AND X < 400 THEN A = 3 * B GO TO OUTPUTA
IF X > 400 AND X < 500 THEN A = 4 * B GO TO OUTPUTA
.
.
.
[noparse][[/noparse]there can be 15 of these formulae too]
Thanks again!
Rich H
Duffer
If you dont want to shout outloud pm, but I think knowing this will be a main decider on which action would be best to take.
Lets say I have an 32kB eeprom (which you can easily connect to the BS2). You can designate the first 5 bits of the address to be the first index, the next 5 bits of the address to be the second index, and the last 5 bits of the address to be the third index. This gives you a 32 x 32 x 32 array.
So if you want to look up (or store) a value at address (10, 5, 6), then you set the address at 10406 (that's bit value 010100010100110, where 01010=10, 00101=5, and 00110=6).
You don't have to use a 5bit x 5bit x 5bit matrix either. For a 32kB eeprom, you could go 10bit x 3bit x 2bit (1024 x 8 x 4 array), or 8 x 4 x 3 (256 x 16 x 8 array)... so long as sum of the bits needed to store the array dimensions in 3 dimensions doesn't exceed 15 (15 for a 32kB chip, or 16 for a 64kB chip, 14 for 16kB, etc).
Do you follow? Did I adequately explain the concept?
Dave
Post Edited (achilles03) : 2/17/2009 3:59:11 PM GMT
Address = Base + ((depthindex*col_size+colindex) * row_size + rowindex) * Element_Size
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering