Pages: [1]   Go Down
Author Topic: Byte array - 2D  (Read 376 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 408
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 90
Posts: 3512
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To fill a 2 dimensional array you need 2 nested loops
Code:
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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Sr. Member
****
Karma: 2
Posts: 408
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:


#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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24427
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
n = 416;
... 
  for (i =0; i >= n ; i = i +13)
That's going to be a short loop.
Logged

"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.

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 90
Posts: 3512
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Pages: [1]   Go Up
Jump to: