Go Down

Topic: Byte array - 2D (Read 633 times) previous topic - next topic

gnusso

Good Morning,

I've:

byte array [30] [12] = {
  //as many vals as dim1
 {0,0,0},
 {0,0,0}//as many rows as dim0
};

and I would like feel up it reading my eeprom address ...

where the record0 is from 0-12 the record1 is from 13-26, the record2 is from 27-39 until the record 31 ...

so now for fill up a record for 1 dimensional array should be like this:

Code: [Select]

byte memoria[416];
void LeggiEeprom()
{
 int ind;
  for (ind =0; ind <= 416 ; ind++)
     {
       // memoria[ind] = EEPROM.read(ind);
       memoria[ind] = readEEPROM(disk1, ind);
     }

}


how could I fill the bi dimensional array ?

Could you help kindly ?

thanks,
gnux

UKHeliBob

To fill a 2 dimensional array you need 2 nested loops
Code: [Select]
for (int row = 0;row <= 29;row++)
{
  for (int column = 0;column <= 11;column++)
  {
    array[column][row] = whatever you want in this position
  }
}

Where is the data coming from for the array ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

gnusso

HI Bob,
thanks for the idea ... I've did something like that :

Code: [Select]



#define disk1 0x50    //Address of 24LC256 eeprom chip
#include <Wire.h>

byte array [30] [12] = {
   //as many vals as dim1
  {0,0,0},
  {0,0,0}//as many rows as dim0
};


byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;

  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();

  Wire.requestFrom(deviceaddress,1);

  if (Wire.available()) rdata = Wire.read();

  return rdata;
}

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();

  delay(5);
}

void setup()
{
  int n,m,z,k,l,i,c;
  n = 416;
  k = 0;
  z = 0;
  Serial.begin(9600);
 
  for (i =0; i >= n ; i = i +13)
      {
        m = k * 13;
        c = 0;
        for ( l = m ; l > (m + 13); l++)
             {
               array[k][c] = readEEPROM(disk1, l);
               c = c + 1;
             } 
       k = k + 1;
           
       }   
}



void  loop()

delay(4000);
 
}


I think could be fine, what do you think ?

thanks gnux

AWOL

Code: [Select]
n = 416;
... 
  for (i =0; i >= n ; i = i +13)

That's going to be a short loop.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UKHeliBob


I think could be fine, what do you think ?

I think it look very complicated just to fill up a 2 dim array.
How many rows of data are there ?
How many columns are there in each row ?

Your array dimensions allow for 30 rows of 12 values.  Is that right ?
Do you want to fill up each row then move on to the next row or fill up each column then move on to the next column ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up