Hi,
I am trying to create an array out of these names, is that possible?
DeviceAddress is part of the DallasTemperature library
DeviceAddress black = {0x28, 0xFF, 0x1A, 0xAA, 0x62, 0x15, 0x03, 0x20};
DeviceAddress red = {0x28, 0xFF, 0xA9, 0xB4, 0x62, 0x15, 0x03, 0x0C};
DeviceAddress green = {0x28, 0xFF, 0xF5, 0xB3, 0x62, 0x15, 0x03, 0x3E};
How would I make this work?
DeviceAddress devices[] = {black, red, green};
So that I can use;
for(DeviceAddress device : devices) {
sensors.setResolution(device, 10);
}
You need to get straight the difference between a variable (which has an address in memory), its name (compile time only), and its value.
At compile time there is a mapping from name to address that the compiler knows about and sorts out for you so you don't have to see bare addresses. At runtime you mostly are interested in the value stored in a variable, not the variable itself (unless using pointers or pass by reference).
devices is a pointer to one of the DeviceAddress objects which can be used to pass the address to the setResoution function, assuming it is written to accept such an argument... Regards, Ray L.