Array for 1wire address array

I have twenty 1wire temp sensors. Each has a unique 8 byte address. In the sample 1wire sketch, the address is stored in a typedef called DeviceAddress which is defined as in the libarary as : typedef uint8_t DeviceAddress[8];

I'd like to do something like this:

DeviceAddress tempSensorAddresses[20];  
tempSensorAddresses[0] = { 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE4 };
tempSensorAddresses[1] = { 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE5 };
tempSensorAddresses[2] = { 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE6 };
and so on for all 20 sensors

But this doesn't work. I know I have an array of arrays, so maybe this doesn't make sense to do it this way. I'd appreciate any suggestions in how I can do this. When I read the sensors I want to do it in a loop; so looping through an array would be ideal instead if 20 lines of code to read each one.

While I'm on the subject of arrays, why doesn't this work:

byte myArray[8];
myArray = { 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE4 };

But this does

byte myArray[8] = { 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE4 };

This is a declaration

byte myArray[8] = { 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE4 };

it creates the array and assigns a set of initial values to the elements.

byte myArray[8] = { 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE4 };

This is an assignment it is used to set one element of the array not 8.

That the language you must learn it as you can't change it

Mark

Hello, recently someone asked the same question: http://arduino.cc/forum/index.php/topic,132911.0.html :slight_smile:

I figured it out. I created a 2 dimensional array like this:

uint8_t tempSensors[4][8] = 
{ 
{ 0x10, 0x33, 0x71, 0x6A, 0x02, 0x08, 0x00, 0x5D },
{ 0x10, 0xD0, 0x8E, 0x6A, 0x02, 0x08, 0x00, 0xE4 },
{ 0x10, 0x07, 0x91, 0x6A, 0x02, 0x08, 0x00, 0xB6 },
{ 0x10, 0x3B, 0x75, 0x6A, 0x02, 0x08, 0x00, 0xE3 } 
};

Then when I want to reference an device like this:

for(i=0; i < 4; i++)
{
  if ( sensors.isConnected(&tempSensors[i][0]) == true )  // See if device is connected
  { // Found temp sensor 
    sensors.setResolution(&tempSensors[i][0], 9);      // Set resolution to 9 bits
}