multidimensional boolean array ??

im having problems with the setup syntax
I pretty sure about the logic after that
the actual application has much larger arrays 20x20 copied into 150x50

I want to copy and paste small[0] and small[1]..... small[98]and small[99]
into large a 10x10 boolean array

// ????? boolean small[100][3][3];
// ???? boolean large[10][10];

small[0][][]={ // this gets pasted to Large[0][0] to [2][2] x,y coordinates
{1,0,1},
{0,0,1},
{1,1,0},
};
small[1][][]={ //this gets pasted to Large[3][0] to [5][2]
{0,0,1},
{0,1,1},
{1,0,0},
};
...

small[98][][]={ //this gets pasted to Large[0][5] to [2][7]
{1,0,0},
{0,1,1},
{1,0,0},
};
small[99][][]={ //this gets pasted to Large[7][7] to [9][9]
{1,1,1},
{0,1,1},
{1,0,0},
};

// i want large to look like
{1,0,1,0,0,1,0,0,0,0},
{0,0,1,0,1,1,0,0,0,0},
{1,1,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,1,1,1},
{0,0,0,0,0,0,0,0,1,1},
{0,0,0,0,0,0,0,1,0,0},

// when I'm done

Not sure you fully understand arrays or maybe you just made "small" have different data on purpose, but you can use a FOR loop(s).

If you know how many elements you have per group (in this case you have 3) you can use the module operator (%) to change the group when you get to the last element of the group. But still, you should either have two different arrays, maybe small and Small.

I don't think those definitions for small, will actually work at all.

If small is supposed to be a 3x3 array, then small[0][] is the first row of the array, should be three elements, not 9.

This is not possible, as @michinyon say :

 small[0][]={
  {1,0,1},
  {0,0,1},
  {1,1,0},            // ???? why another , ???
};

This is possible for explain values in array, but you can't write this when declaring arrays:

small[0][]= {1,0,1}; 
small[1][]= {0,0,1};
small[2][]= {1,1,0};

In code you need to write this:

boolean small[3][3]={
  {1,0,1},
  {0,0,1},
  {1,1,0}
};

So 3x3=9 elements.

please be aware that boolean are bytes so every boolean takes a byte.

It might be simpler to make wrapper functions
void SetBit(x, y, z, val);
boolean GetBit(x, y, z, val);
that maps onto a simpler byte array from which every bit is used. Saves 7x memory.!

from reference A boolean holds one of two values, true or false. (Each boolean variable occupies one byte of memory.)

/*please be aware that boolean are bytes so every boolean takes a byte.
It might be simpler to make wrapper functions
this looks interesting.. where can I read More?
{ void SetBit(x, y, z, val);
{ boolean GetBit(x, y, z, val);
that maps onto a simpler byte array from which every bit is used. Saves 7x memory.!

Rob Tillaart */

rodloy:
this looks interesting.. where can I read More?

bitRead: http://arduino.cc/en/Reference/BitRead
bitWrite: http://arduino.cc/en/Reference/BitWrite
are basic functions to access single bit of a numeric variable. byte=8 bits, int=16 bits

byte Val=0;
bitWrite(Val,3,1);   bit numer 3 to 1    Val=B00001000 => 4

If you're going to hard-code those values as shown in the example, and if the inner array length is less than 64, then you could simplify the problem enormously by storing the inner arrays as numbers expressed in binary notation rather than as an array. That would also make the copy and paste you mention more efficient. However, it would be worth reviewing the purpose of the copy and paste since it may well be possible to avoid that entirely.

Thank you all for your ideas.. I'm making progress..

this is my first programming project since IBM AT computers..
I did some pretty amazing things back then and am so grateful to be back at it

thank you again

Yes I need to hard code the variables and the visual I've used is helpful and not essential
right now I'm using much larger arrays 20x20 copied into 150x50 and in future plans they get bigger

//the compiler is accepting this
boolean mycharacter[4][4][4]={
{0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1},
{0,1,0,0,0,1,0,1,0,1,1,0,0,1,1,1},
{1,0,0,0,1,0,0,1,1,0,1,0,1,0,1,1},
{1,1,0,0,1,1,0,1,1,1,1,0,1,1,1,1}
};
//and
void loop() {

for (int myx = 0; myx < 4; myx++) {
for (int myy = 0; myy < 4; myy++) {
for (int myz = 0; myz < 4; myz++) {
// when I test
if (mycharacter[myx][myy][myz]=1){ // it is always true ???

ight now I'm using much larger arrays 20x20 copied into 150x50 and in future plans they get bigger

How many bytes does a 150 x 50 array of boolean elements take up? How many bytes do you have available?

Why is your boolean array named mycharacter? I suppose you have some ints called myFloatThis and myFloatThat. Do you have floats called myInt1 and myInt2, too?

1 150 x50 array takes almost 8k 7500bytes .. that's too much
I have an Arduino Mega ADK it only has 8k so I'm going to flash 256k there or an SD shield later
or writing direct ... similar logic I think.

actually I'm just getting started in Arduino and /or C, C++

so the "my" label helps me recognize my variables for now

so yes almost everything starts with "my"

so the "my" label helps me recognize my variables for now

Who else has variables in your sketch?

so yes almost everything starts with "my"

My objection wasn't with the my prefix.

so what is the objection? I'm not going for aesthetics (even though I try to practice that) just clarity
the munchkins and elves have their own variables i.e. stan_elf_inita, tiffiny_munchkin_MyFloatThat... :smiley:

1 150 x50 array takes almost 8k 7500bytes .. that's too much

If you insist on storing one bit of information in eight bits, yes, it is too much.

so what is the objection?

I expect to understand the code without having to refer to the definitions all the time. When I see myChar[2][3][1], I have to look up the definition, and guess at why a singular name is storing multiple values.

If I see a statement like:

   if(myInt == 14.7)

I assume that you've made a mistake, either in naming a float variable myInt or in comparing an int to a float value. Why should I have to determine which mistake you've made, and decide that one was just dumb but OK?

Thank you .. I'm understanding the language better so I'll improve the variable naming..

This code actually gets me the expected output ..
i hope it isn't the actual final solution
because it looks like .. 8)

I'm storing 1's and 0's -- on's and off's into the 256 K of Flash memory.
and I am retrieving them see attached file.. I didn't see how to copy from Serial Monitor
Serial.println( buffer,DEC ); // showed me I was getting -64 for my 0' and 0 for my 1's
//so I had to add some logic to get the output I wanted

not the clean code I wanted but it looks consistent for now??

it looks like I can use this for now.. here is the test code

#include <avr/pgmspace.h>  //allow arduino to store letter arrays in flash memory
int zeroonetf;
int myx;
int myy;
int myz;
char mystring[400];
char buffer[1];
char zeroone;
char izeroone;
int i=0;

PROGMEM prog_char mycharacter[3][3][3]  =

{  // 0
{{0,1,1,},  
{0,0,0,},
{1,1,0,}},
   // 1
{{0,1,1,},
{0,0,1,},
{0,1,0,}},
   // 2
{{0,0,1,},
{0,1,0,},
{1,1,1,}}
};
  void setup ()
  {
    Serial.begin(9600);  // set up Serial library at 9600 bps      
   } 
   
   // i=0;  see above
void loop() 
  {
   
    for (myx = 0; myx < 3; myx++) { 
      for (myy = 0; myy < 3; myy++) {
        for (myz = 0; myz < 3; myz++) {
          
                                // Necessary casts and dereferencing, just copy.           
     strcpy_P(buffer, (char*)pgm_read_byte_near(&(mycharacter[myx][myy][myz])));
     zeroone = char(buffer[1]);
     if (i=0)
             {i=1;
             izeroone=zeroone;}
             
   if (izeroone == zeroone) {zeroonetf=0;}
   else {zeroonetf=1;}
              Serial.print(zeroone,DEC); 
              Serial.print("  "); 
              Serial.print(zeroone);
              Serial.print("  "); 
              Serial.print(izeroone);
              Serial.print("  "); 
              Serial.print(zeroonetf);
               Serial.print("  "); 
               Serial.print(myx); 
               Serial.print(myy); 
               Serial.println(myz); 
                      delay(400);
                                       }
                                      }
                                    }
    }

     zeroone = char(buffer[1]);

The upper index for an array is one less than the size of the array. For an array of length one (I can't see why you bother), the valid range of indices is 0 to 0.

     if (i=0)

Assigning 0 to i seems unlikely to be what you mean to do.

it looks like I can use this for now.

Not to me... 8)

 if (mycharacter[myx][myy][myz]=1){       // it is always true   ???
« Last Edit: 2014-01-09, 10:21:07 by rodloy »

yes. The value of the inner assignment is always 1, which is "true."
You probably wanted a comparison using "==" rather than an assignment using "=" :slight_smile: